aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-18 02:04:01 +0100
committerRobin Jarry <robin@jarry.cc>2023-11-23 00:14:54 +0100
commit30d28d0542997ad55a59439775929c63b2de8616 (patch)
tree20d52e73e1b97d76b9bde126c9dfc8a02e46d554 /app
parent85d0936df6861c41a1dddd91a2f3b97afd8e127a (diff)
downloadaerc-30d28d0542997ad55a59439775929c63b2de8616.tar.gz
dirtree: add custom virtual directory role
Add a new directory role to indicate virtual nodes in the directory tree. This allows to style the virtual nodes differently and apply different behaviors in some commands (i.e. rmdir). Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'app')
-rw-r--r--app/dirtree.go24
1 files changed, 24 insertions, 0 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)
}