aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/dirtree.go24
-rw-r--r--commands/account/rmdir.go7
-rw-r--r--doc/aerc-templates.7.scd12
-rw-r--r--models/models.go2
4 files changed, 43 insertions, 2 deletions
diff --git a/app/dirtree.go b/app/dirtree.go
index 8f8730b4..1e0e76fb 100644
--- a/app/dirtree.go
+++ b/app/dirtree.go
@@ -43,6 +43,30 @@ func (dt *DirectoryTree) OnVirtualNode(cb func()) {
dt.virtualCb = cb
}
+func (dt *DirectoryTree) Selected() string {
+ if dt.listIdx < 0 || dt.listIdx >= len(dt.list) {
+ return dt.DirectoryList.Selected()
+ }
+ node := dt.list[dt.listIdx]
+ sep := dt.DirectoryList.worker.PathSeparator()
+ elems := strings.Split(dt.treeDirs[getAnyUid(node)], sep)
+ n := countLevels(node)
+ if n < 0 || n >= len(elems) {
+ return ""
+ }
+ return strings.Join(elems[:(n+1)], sep)
+}
+
+func (dt *DirectoryTree) SelectedDirectory() *models.Directory {
+ if dt.virtual {
+ return &models.Directory{
+ Name: dt.Selected(),
+ Role: models.VirtualRole,
+ }
+ }
+ return dt.DirectoryList.SelectedDirectory()
+}
+
func (dt *DirectoryTree) ClearList() {
dt.list = make([]*types.Thread, 0)
}
diff --git a/commands/account/rmdir.go b/commands/account/rmdir.go
index 6590a819..0793c7b8 100644
--- a/commands/account/rmdir.go
+++ b/commands/account/rmdir.go
@@ -5,6 +5,7 @@ import (
"time"
"git.sr.ht/~rjarry/aerc/app"
+ "git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
)
@@ -31,6 +32,12 @@ func (r RemoveDir) Execute(args []string) error {
return errors.New("Refusing to remove non-empty directory; use -f")
}
+ if d := acct.Directories().SelectedDirectory(); d != nil {
+ if d.Role == models.VirtualRole {
+ return errors.New("Cannot remove a virtual node")
+ }
+ }
+
curDir := acct.SelectedDirectory()
var newDir string
dirFound := false
diff --git a/doc/aerc-templates.7.scd b/doc/aerc-templates.7.scd
index 25db5990..026d54e0 100644
--- a/doc/aerc-templates.7.scd
+++ b/doc/aerc-templates.7.scd
@@ -194,8 +194,16 @@ available always.
{{.RUE}}
```
- IANA role of the mailbox, converted to lowercase. aerc uses one custom
- role: 'query', which is given to mailboxes from a notmuch query-map
+ IANA role of the mailbox, converted to lowercase:
+
+ ```
+ {{.Role}}
+ ```
+
+ *aerc* implements two additional custom roles: A 'query' role is given
+ to folders from a notmuch query-map
+ and 'virtual' indicates a virtual node in the directory tree listing:
+
```
{{if eq .Role "query"}}{{...}}{{else}}{{...}}{{end}}
```
diff --git a/models/models.go b/models/models.go
index 1b864341..42e60b8b 100644
--- a/models/models.go
+++ b/models/models.go
@@ -59,6 +59,8 @@ const (
TrashRole Role = "trash"
// Custom aerc roles
QueryRole Role = "query"
+ // virtual node created by the directory tree
+ VirtualRole Role = "virtual"
)
type Directory struct {