aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-05-13 12:29:16 +0200
committerRobin Jarry <robin@jarry.cc>2023-05-16 13:56:58 +0200
commit06723ff579b692867c6ab87e3838d04e9d044912 (patch)
treeace4f7fe43eccabd6ec732ebfc8757702fd404cc
parentda1f014b7050195d7f3e6f849bc105d87efc227b (diff)
downloadaerc-06723ff579b692867c6ab87e3838d04e9d044912.tar.gz
dirtree: clear msglist for virtual nodes
Clear the message list when a virtual node is selected. Add a VirtualNodeCallback to the Dirlist interface. Reported-by: Tim Culverhouse <tim@timculverhouse.com> Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--widgets/account.go5
-rw-r--r--widgets/dirlist.go5
-rw-r--r--widgets/dirtree.go15
3 files changed, 25 insertions, 0 deletions
diff --git a/widgets/account.go b/widgets/account.go
index a99f7a48..e28804de 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -95,6 +95,11 @@ func NewAccountView(
view.msglist = NewMessageList(aerc, view)
view.grid.AddChild(view.msglist).At(0, 1)
+ view.dirlist.OnVirtualNode(func() {
+ view.msglist.SetStore(nil)
+ view.Invalidate()
+ })
+
go func() {
defer log.PanicHandler()
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index 6a10c99a..25d1e7ff 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -31,6 +31,8 @@ type DirectoryLister interface {
List() []string
ClearList()
+ OnVirtualNode(func())
+
NextPrev(int)
CollapseFolder()
@@ -99,6 +101,9 @@ func (dirlist *DirectoryList) ClearList() {
dirlist.dirs = []string{}
}
+func (dirlist *DirectoryList) OnVirtualNode(_ func()) {
+}
+
func (dirlist *DirectoryList) Update(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
diff --git a/widgets/dirtree.go b/widgets/dirtree.go
index c11a1fd0..98b25850 100644
--- a/widgets/dirtree.go
+++ b/widgets/dirtree.go
@@ -23,6 +23,9 @@ type DirectoryTree struct {
list []*types.Thread
treeDirs []string
+
+ virtual bool
+ virtualCb func()
}
func NewDirectoryTree(dirlist *DirectoryList) DirectoryLister {
@@ -30,10 +33,15 @@ func NewDirectoryTree(dirlist *DirectoryList) DirectoryLister {
DirectoryList: dirlist,
listIdx: -1,
list: make([]*types.Thread, 0),
+ virtualCb: func() {},
}
return dt
}
+func (dt *DirectoryTree) OnVirtualNode(cb func()) {
+ dt.virtualCb = cb
+}
+
func (dt *DirectoryTree) ClearList() {
dt.list = make([]*types.Thread, 0)
dt.selected = ""
@@ -168,6 +176,9 @@ func (dt *DirectoryTree) Clicked(x int, y int) (string, bool) {
}
func (dt *DirectoryTree) SelectedMsgStore() (*lib.MessageStore, bool) {
+ if dt.virtual {
+ return nil, false
+ }
if findString(dt.treeDirs, dt.selected) < 0 {
dt.buildTree()
if idx := findString(dt.treeDirs, dt.selected); idx >= 0 {
@@ -229,7 +240,11 @@ func (dt *DirectoryTree) NextPrev(delta int) {
dt.listIdx = newIdx
if path := dt.getDirectory(dt.list[dt.listIdx]); path != "" {
+ dt.virtual = false
dt.Select(path)
+ } else {
+ dt.virtual = true
+ dt.virtualCb()
}
}