diff options
author | inwit <inwit@sindominio.net> | 2023-10-29 23:45:55 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-11-02 11:59:39 +0100 |
commit | 9ce4af011c93e2816ce04012f6205b54e0ed1d51 (patch) | |
tree | d7bc32021b9e40bafd26f034d5b44ab7300e5e47 | |
parent | 2bf8fb42980ea981da34e104d8cfd0d1e3da788b (diff) | |
download | aerc-9ce4af011c93e2816ce04012f6205b54e0ed1d51.tar.gz |
fold: allow for multiple folding levels
Extend the :fold/:unfold behaviour to allow for multiple folding levels.
Signed-Off-By: inwit <inwit@sindominio.net>
Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r-- | app/dirtree.go | 30 | ||||
-rw-r--r-- | app/msglist.go | 2 | ||||
-rw-r--r-- | lib/msgstore.go | 13 | ||||
-rw-r--r-- | lib/threadbuilder.go | 2 | ||||
-rw-r--r-- | worker/notmuch/lib/database.go | 6 | ||||
-rw-r--r-- | worker/types/thread.go | 2 |
6 files changed, 38 insertions, 17 deletions
diff --git a/app/dirtree.go b/app/dirtree.go index 24e776d8..50f5797f 100644 --- a/app/dirtree.go +++ b/app/dirtree.go @@ -167,7 +167,11 @@ func (dt *DirectoryTree) Clicked(x int, y int) (string, bool) { if path := dt.getDirectory(node); path != "" { return path, true } - node.Hidden = !node.Hidden + if node.Hidden == 0 { + node.Hidden = 1 + } else { + node.Hidden = 0 + } dt.Invalidate() return "", false } @@ -251,8 +255,8 @@ func (dt *DirectoryTree) NextPrev(delta int) { func (dt *DirectoryTree) CollapseFolder() { if dt.listIdx >= 0 && dt.listIdx < len(dt.list) { if node := dt.list[dt.listIdx]; node != nil { - if node.Parent != nil && (node.Hidden || node.FirstChild == nil) { - node.Parent.Hidden = true + if node.Parent != nil && (node.Hidden != 0 || node.FirstChild == nil) { + node.Parent.Hidden = 1 // highlight parent node and select it for i, t := range dt.list { if t == node.Parent { @@ -263,7 +267,7 @@ func (dt *DirectoryTree) CollapseFolder() { } } } else { - node.Hidden = true + node.Hidden = 1 } dt.Invalidate() } @@ -272,7 +276,7 @@ func (dt *DirectoryTree) CollapseFolder() { func (dt *DirectoryTree) ExpandFolder() { if dt.listIdx >= 0 && dt.listIdx < len(dt.list) { - dt.list[dt.listIdx].Hidden = false + dt.list[dt.listIdx].Hidden = 0 dt.Invalidate() } } @@ -313,7 +317,7 @@ func (dt *DirectoryTree) getTreeNode(uid uint32) (int, *types.Thread) { func (dt *DirectoryTree) hiddenDirectories() map[string]bool { hidden := make(map[string]bool, 0) for _, node := range dt.list { - if node.Hidden && node.FirstChild != nil { + if node.Hidden != 0 && node.FirstChild != nil { elems := strings.Split(dt.treeDirs[getAnyUid(node)], dt.DirectoryList.worker.PathSeparator()) if levels := countLevels(node); levels < len(elems) { if node.FirstChild != nil && (levels+1) < len(elems) { @@ -337,7 +341,7 @@ func (dt *DirectoryTree) setHiddenDirectories(hiddenDirs map[string]bool) { } strDir := strings.Join(elems[:levels], dt.DirectoryList.worker.PathSeparator()) if hidden, ok := hiddenDirs[strDir]; hidden && ok { - node.Hidden = true + node.Hidden = 1 } } } @@ -438,7 +442,11 @@ func (dt *DirectoryTree) buildTreeNode(node *types.Thread, stree [][]string, def nextNode := &types.Thread{Uid: uid} node.AddChild(nextNode) if dt.UiConfig(path).DirListCollapse != 0 { - node.Hidden = depth > dt.UiConfig(path).DirListCollapse + if depth > dt.UiConfig(path).DirListCollapse { + node.Hidden = 1 + } else { + node.Hidden = 0 + } } dt.buildTreeNode(nextNode, next, defaultUid, depth+1) } @@ -449,14 +457,14 @@ func makeVisible(node *types.Thread) { return } for iter := node.Parent; iter != nil; iter = iter.Parent { - iter.Hidden = false + iter.Hidden = 0 } } func isVisible(node *types.Thread) bool { isVisible := true for iter := node.Parent; iter != nil; iter = iter.Parent { - if iter.Hidden { + if iter.Hidden != 0 { isVisible = false break } @@ -488,7 +496,7 @@ func getFlag(node *types.Thread) string { if node == nil && node.FirstChild == nil { return "" } - if node.Hidden { + if node.Hidden != 0 { return "+" } return "" diff --git a/app/msglist.go b/app/msglist.go index e57bfe9d..146d032d 100644 --- a/app/msglist.go +++ b/app/msglist.go @@ -485,7 +485,7 @@ func (t *threadView) Update(data state.DataSetter, uid uint32) { t.prev = thread t.prevSubj = subject count = countThreads(thread) - folded = thread.FirstChild != nil && thread.FirstChild.Hidden + folded = thread.FirstChild != nil && thread.FirstChild.Hidden != 0 context = thread.Context } data.SetThreading(prefix, same, count, folded, context) diff --git a/lib/msgstore.go b/lib/msgstore.go index c68c2ed8..ca5f16d9 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -517,14 +517,23 @@ func (store *MessageStore) Unfold(uid uint32) error { return store.doThreadFolding(uid, false) } -func (store *MessageStore) doThreadFolding(uid uint32, hidden bool) error { +func (store *MessageStore) doThreadFolding(uid uint32, hide bool) error { thread, err := store.Thread(uid) if err != nil { return err } + if hide && thread.FirstChild.Hidden > 0 { + return nil + } err = thread.Walk(func(t *types.Thread, _ int, __ error) error { if t.Uid != uid { - t.Hidden = hidden + if hide { + t.Hidden++ //increase fold level + } else if t.Hidden > 1 { + t.Hidden-- + } else { + t.Hidden = 0 + } } return nil }) diff --git a/lib/threadbuilder.go b/lib/threadbuilder.go index 1f2d72c6..63ae80d3 100644 --- a/lib/threadbuilder.go +++ b/lib/threadbuilder.go @@ -205,7 +205,7 @@ func (builder *ThreadBuilder) RebuildUids(threads []*types.Thread, inverse bool) t.Deleted = stored.Deleted } builder.threadMap[t.Uid] = t - if t.Deleted || t.Hidden { + if t.Deleted || t.Hidden != 0 { return nil } threaduids = append(threaduids, t.Uid) diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go index 015126c2..b2a22227 100644 --- a/worker/notmuch/lib/database.go +++ b/worker/notmuch/lib/database.go @@ -336,7 +336,11 @@ func (db *DB) makeThread(parent *types.Thread, msgs *notmuch.Messages, threadCon case true: node.Context = !match default: - node.Hidden = !match + if match { + node.Hidden = 0 + } else { + node.Hidden = 1 + } } if parent != nil && parent.FirstChild == nil { parent.FirstChild = node diff --git a/worker/types/thread.go b/worker/types/thread.go index 75651280..b4f5ac5f 100644 --- a/worker/types/thread.go +++ b/worker/types/thread.go @@ -15,7 +15,7 @@ type Thread struct { NextSibling *Thread FirstChild *Thread - Hidden bool // if this flag is set the message isn't rendered in the UI + Hidden int // if this flag is not zero the message isn't rendered in the UI Deleted bool // if this flag is set the message was deleted // Context indicates the message doesn't match the mailbox / query but |