mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🧑💻 Add filetreeSortChanged and notebookSortChanged to eventbus https://github.com/siyuan-note/siyuan/issues/16383
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
c0a3635809
commit
121e4a8b60
2 changed files with 70 additions and 0 deletions
|
|
@ -761,6 +761,14 @@ func ChangeBoxSort(boxIDs []string) {
|
||||||
boxConf.Sort = i + 1
|
boxConf.Sort = i + 1
|
||||||
box.SaveConf(boxConf)
|
box.SaveConf(boxConf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var notebookIDs []string
|
||||||
|
for _, box := range Conf.GetOpenedBoxes() {
|
||||||
|
notebookIDs = append(notebookIDs, box.ID)
|
||||||
|
}
|
||||||
|
util.BroadcastByType("main", "notebookSortChanged", 0, "", map[string]any{
|
||||||
|
"notebookIDs": notebookIDs,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetBoxIcon(boxID, icon string) {
|
func SetBoxIcon(boxID, icon string) {
|
||||||
|
|
|
||||||
|
|
@ -1849,6 +1849,24 @@ func moveSorts(rootID, fromBox, toBox string) {
|
||||||
logging.LogErrorf("write sort conf failed: %s", err)
|
logging.LogErrorf("write sort conf failed: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortIDs := map[string]int{}
|
||||||
|
bt := treenode.GetBlockTree(rootID)
|
||||||
|
if nil != bt {
|
||||||
|
parentPath := path.Dir(bt.Path)
|
||||||
|
docs, _, listErr := ListDocTree(toBox, parentPath, util.SortModeUnassigned, false, false, 102400)
|
||||||
|
if listErr != nil {
|
||||||
|
logging.LogErrorf("list doc tree failed: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, doc := range docs {
|
||||||
|
sortIDs[doc.ID] = doc.Sort
|
||||||
|
}
|
||||||
|
|
||||||
|
pushFiletreeSortChanged(sortIDs)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ChangeFileTreeSort(boxID string, paths []string) {
|
func ChangeFileTreeSort(boxID string, paths []string) {
|
||||||
|
|
@ -1926,6 +1944,8 @@ func ChangeFileTreeSort(boxID string, paths []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
IncSync()
|
IncSync()
|
||||||
|
|
||||||
|
pushFiletreeSortChanged(sortFolderIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (box *Box) fillSort(files *[]*File) {
|
func (box *Box) fillSort(files *[]*File) {
|
||||||
|
|
@ -2006,6 +2026,13 @@ func (box *Box) addMaxSort(parentPath, id string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
box.setSortVal(id, sortVal)
|
box.setSortVal(id, sortVal)
|
||||||
|
|
||||||
|
sortIDs := map[string]int{}
|
||||||
|
for _, doc := range docs {
|
||||||
|
sortIDs[doc.ID] = doc.Sort
|
||||||
|
}
|
||||||
|
sortIDs[id] = sortVal
|
||||||
|
pushFiletreeSortChanged(sortIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (box *Box) addMinSort(parentPath, id string) {
|
func (box *Box) addMinSort(parentPath, id string) {
|
||||||
|
|
@ -2021,6 +2048,13 @@ func (box *Box) addMinSort(parentPath, id string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
box.setSortVal(id, sortVal)
|
box.setSortVal(id, sortVal)
|
||||||
|
|
||||||
|
sortIDs := map[string]int{}
|
||||||
|
for _, doc := range docs {
|
||||||
|
sortIDs[doc.ID] = doc.Sort
|
||||||
|
}
|
||||||
|
sortIDs[id] = sortVal
|
||||||
|
pushFiletreeSortChanged(sortIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (box *Box) setSortVal(id string, sortVal int) {
|
func (box *Box) setSortVal(id string, sortVal int) {
|
||||||
|
|
@ -2086,6 +2120,7 @@ func (box *Box) addSort(previousPath, id string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortIDs := map[string]int{}
|
||||||
previousID := util.GetTreeID(previousPath)
|
previousID := util.GetTreeID(previousPath)
|
||||||
sortVal := 0
|
sortVal := 0
|
||||||
for _, doc := range docs {
|
for _, doc := range docs {
|
||||||
|
|
@ -2095,6 +2130,7 @@ func (box *Box) addSort(previousPath, id string) {
|
||||||
fullSortIDs[id] = sortVal
|
fullSortIDs[id] = sortVal
|
||||||
}
|
}
|
||||||
sortVal++
|
sortVal++
|
||||||
|
sortIDs[doc.ID] = sortVal
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err = gulu.JSON.MarshalJSON(fullSortIDs)
|
data, err = gulu.JSON.MarshalJSON(fullSortIDs)
|
||||||
|
|
@ -2106,6 +2142,8 @@ func (box *Box) addSort(previousPath, id string) {
|
||||||
logging.LogErrorf("write sort conf failed: %s", err)
|
logging.LogErrorf("write sort conf failed: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pushFiletreeSortChanged(sortIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (box *Box) setSort(sortIDVals map[string]int) {
|
func (box *Box) setSort(sortIDVals map[string]int) {
|
||||||
|
|
@ -2139,4 +2177,28 @@ func (box *Box) setSort(sortIDVals map[string]int) {
|
||||||
logging.LogErrorf("write sort conf failed: %s", err)
|
logging.LogErrorf("write sort conf failed: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pushFiletreeSortChanged(sortIDVals)
|
||||||
|
}
|
||||||
|
|
||||||
|
func pushFiletreeSortChanged(sortIDs map[string]int) {
|
||||||
|
var childIDs []string
|
||||||
|
for sortID := range sortIDs {
|
||||||
|
childIDs = append(childIDs, sortID)
|
||||||
|
}
|
||||||
|
sort.Slice(childIDs, func(i, j int) bool {
|
||||||
|
return sortIDs[childIDs[i]] < sortIDs[childIDs[j]]
|
||||||
|
})
|
||||||
|
|
||||||
|
firstID := childIDs[0]
|
||||||
|
bt := treenode.GetBlockTree(firstID)
|
||||||
|
if nil == bt {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
parentPath := path.Dir(bt.Path)
|
||||||
|
util.BroadcastByType("main", "filetreeSortChanged", 0, "", map[string]any{
|
||||||
|
"parentPath": parentPath,
|
||||||
|
"childIDs": childIDs,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue