🎨 书签面板添加 删除 按钮用于删除书签组 https://github.com/siyuan-note/siyuan/issues/5155

This commit is contained in:
Liang Ding 2022-06-16 18:21:42 +08:00
parent 72225ff73c
commit 34be74d74f
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 65 additions and 0 deletions

View file

@ -27,6 +27,52 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func RemoveBookmark(bookmark string) (err error) {
util.PushEndlessProgress(Conf.Language(116))
bookmarks := sql.QueryBookmarkBlocksByKeyword(bookmark)
treeBlocks := map[string][]string{}
for _, tag := range bookmarks {
if blocks, ok := treeBlocks[tag.RootID]; !ok {
treeBlocks[tag.RootID] = []string{tag.ID}
} else {
treeBlocks[tag.RootID] = append(blocks, tag.ID)
}
}
for treeID, blocks := range treeBlocks {
util.PushEndlessProgress("[" + treeID + "]")
tree, e := loadTreeByBlockID(treeID)
if nil != e {
util.PushClearProgress()
return e
}
for _, blockID := range blocks {
node := treenode.GetNodeInTree(tree, blockID)
if nil == node {
continue
}
if bookmarkAttrVal := node.IALAttr("bookmark"); bookmarkAttrVal == bookmark {
node.RemoveIALAttr("bookmark")
}
}
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), tree.Root.IALAttr("title")))
if err = writeJSONQueue(tree); nil != err {
util.ClearPushProgress(100)
return
}
util.RandomSleep(50, 150)
}
util.PushEndlessProgress(Conf.Language(113))
sql.WaitForWritingDatabase()
util.ReloadUI()
return
}
func RenameBookmark(oldBookmark, newBookmark string) (err error) {
if treenode.ContainsMarker(newBookmark) {
return errors.New(Conf.Language(112))