dirtree: add dirtree-collapse config setting

Adds a setting to the configuration to configure at which level the
folders in the dirtree are collapsed by default.

In my case, this is useful because my organisation has some rather deep
nesting in the folder structure, and a _lot_ of folders, and this way I
can keep my dirtree uncluttered while still having all folders there if
I need them.

Signed-off-by: Sijmen <me@sijman.nl>
This commit is contained in:
Sijmen 2022-08-10 20:09:15 +02:00
parent 1b91b68e73
commit 72449419ee
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48
4 changed files with 14 additions and 3 deletions

View file

@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Import/Export mbox files with `:import-mbox` and `:export-mbox`. - Import/Export mbox files with `:import-mbox` and `:export-mbox`.
- `address-book-cmd` can now also be specified in `accounts.conf`. - `address-book-cmd` can now also be specified in `accounts.conf`.
- Run `check-mail-cmd` with `:check-mail`. - Run `check-mail-cmd` with `:check-mail`.
- Configurable default collapse depth for directory tree.
### Changed ### Changed

View file

@ -103,6 +103,12 @@ dirlist-delay=200ms
# Default: false # Default: false
dirlist-tree=false dirlist-tree=false
# If dirlist-tree is enabled, set level at which folders are collapsed by
# default. Set to 0 to disable.
#
# Default: 0
dirlist-collapse=0
# List of space-separated criteria to sort the messages by, see *sort* # List of space-separated criteria to sort the messages by, see *sort*
# command in *aerc*(1) for reference. Prefixing a criterion with "-r " # command in *aerc*(1) for reference. Prefixing a criterion with "-r "
# reverses that criterion. # reverses that criterion.

View file

@ -62,6 +62,7 @@ type UIConfig struct {
DirListFormat string `ini:"dirlist-format"` DirListFormat string `ini:"dirlist-format"`
DirListDelay time.Duration `ini:"dirlist-delay"` DirListDelay time.Duration `ini:"dirlist-delay"`
DirListTree bool `ini:"dirlist-tree"` DirListTree bool `ini:"dirlist-tree"`
DirListCollapse int `ini:"dirlist-collapse"`
Sort []string `delim:" "` Sort []string `delim:" "`
NextMessageOnDelete bool `ini:"next-message-on-delete"` NextMessageOnDelete bool `ini:"next-message-on-delete"`
CompletionDelay time.Duration `ini:"completion-delay"` CompletionDelay time.Duration `ini:"completion-delay"`

View file

@ -327,7 +327,7 @@ func (dt *DirectoryTree) buildTree() {
copy(dt.treeDirs, dt.dirs) copy(dt.treeDirs, dt.dirs)
root := &types.Thread{Uid: 0} root := &types.Thread{Uid: 0}
buildTree(root, sTree, 0xFFFFFF) dt.buildTreeNode(root, sTree, 0xFFFFFF, 1)
threads := make([]*types.Thread, 0) threads := make([]*types.Thread, 0)
@ -373,7 +373,7 @@ func (dt *DirectoryTree) buildTree() {
} }
} }
func buildTree(node *types.Thread, stree [][]string, defaultUid uint32) { func (dt *DirectoryTree) buildTreeNode(node *types.Thread, stree [][]string, defaultUid uint32, depth int) {
m := make(map[string][][]string) m := make(map[string][][]string)
for _, branch := range stree { for _, branch := range stree {
if len(branch) > 1 { if len(branch) > 1 {
@ -398,7 +398,10 @@ func buildTree(node *types.Thread, stree [][]string, defaultUid uint32) {
} }
nextNode := &types.Thread{Uid: uid} nextNode := &types.Thread{Uid: uid}
node.AddChild(nextNode) node.AddChild(nextNode)
buildTree(nextNode, next, defaultUid) if dt.UiConfig().DirListCollapse != 0 {
node.Hidden = depth > dt.UiConfig().DirListCollapse
}
dt.buildTreeNode(nextNode, next, defaultUid, depth+1)
} }
} }