Skip to content

Commit

Permalink
expand,collapse: allow specifying folder name
Browse files Browse the repository at this point in the history
In addition of expanding collapsing the currently selected folder with
no argument, allow specifying a folder name.

Changelog-added: `:expand-folder` and `:collapse-folder` can now act
 on a non selected folder.
Suggested-by: Drew Devault <[email protected]>
Signed-off-by: Robin Jarry <[email protected]>
Tested-by: Inwit <[email protected]>
  • Loading branch information
rjarry committed Dec 21, 2024
1 parent 553fabb commit 5600215
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
8 changes: 4 additions & 4 deletions app/dirlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type DirectoryLister interface {

NextPrev(int)

CollapseFolder()
ExpandFolder()
CollapseFolder(string)
ExpandFolder(string)

SelectedMsgStore() (*lib.MessageStore, bool)
MsgStore(string) (*lib.MessageStore, bool)
Expand Down Expand Up @@ -170,11 +170,11 @@ func (dirlist *DirectoryList) Update(msg types.WorkerMessage) {
}
}

func (dirlist *DirectoryList) CollapseFolder() {
func (dirlist *DirectoryList) CollapseFolder(string) {
// no effect for the DirectoryList
}

func (dirlist *DirectoryList) ExpandFolder() {
func (dirlist *DirectoryList) ExpandFolder(string) {
// no effect for the DirectoryList
}

Expand Down
41 changes: 23 additions & 18 deletions app/dirtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,30 +304,35 @@ func (dt *DirectoryTree) selectIndex(i 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 != 0 || node.FirstChild == nil) {
node.Parent.Hidden = 1
// highlight parent node and select it
for i, t := range dt.list {
if t == node.Parent {
dt.selectIndex(i)
}
}
} else {
node.Hidden = 1
func (dt *DirectoryTree) CollapseFolder(name string) {
name = strings.TrimRight(name, dt.worker.PathSeparator())
index, node := dt.getTreeNode(models.UID(name))
if node == nil {
return
}
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 && index == dt.listIdx {
dt.selectIndex(i)
break
}
dt.Invalidate()
}
} else {
node.Hidden = 1
}
dt.Invalidate()
}

func (dt *DirectoryTree) ExpandFolder() {
if dt.listIdx >= 0 && dt.listIdx < len(dt.list) {
dt.list[dt.listIdx].Hidden = 0
dt.Invalidate()
func (dt *DirectoryTree) ExpandFolder(name string) {
name = strings.TrimRight(name, dt.worker.PathSeparator())
_, node := dt.getTreeNode(models.UID(name))
if node == nil {
return
}
node.Hidden = 0
dt.Invalidate()
}

func (dt *DirectoryTree) countVisible(list []*types.Thread) (n int) {
Expand Down
21 changes: 17 additions & 4 deletions commands/account/expand-folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"git.sr.ht/~rjarry/aerc/commands"
)

type ExpandCollapseFolder struct{}
type ExpandCollapseFolder struct {
Folder string `opt:"folder" required:"false" complete:"CompleteFolder" desc:"Folder name."`
}

func init() {
commands.Register(ExpandCollapseFolder{})
Expand All @@ -25,15 +27,26 @@ func (ExpandCollapseFolder) Aliases() []string {
return []string{"expand-folder", "collapse-folder"}
}

func (ExpandCollapseFolder) Execute(args []string) error {
func (*ExpandCollapseFolder) CompleteFolder(arg string) []string {
acct := app.SelectedAccount()
if acct == nil {
return nil
}
return commands.FilterList(acct.Directories().List(), arg, nil)
}

func (e ExpandCollapseFolder) Execute(args []string) error {
acct := app.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
if e.Folder == "" {
e.Folder = acct.Directories().Selected()
}
if args[0] == "expand-folder" {
acct.Directories().ExpandFolder()
acct.Directories().ExpandFolder(e.Folder)
} else {
acct.Directories().CollapseFolder()
acct.Directories().CollapseFolder(e.Folder)
}
return nil
}
9 changes: 5 additions & 4 deletions doc/aerc.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,11 @@ message list, the message in the message viewer, etc).
Cycles to the next (or previous) folder shown in the sidebar, repeated
_<n>_ times (default: _1_).

*:expand-folder*++
*:collapse-folder*
Expands or collapses the current folder when the directory tree is
enabled.
*:expand-folder* [_<folder>_]++
*:collapse-folder* [_<folder>_]
Expands or collapses a folder when the directory tree is enabled. If no
_<folder>_ argument is specified, the currently selected folder is acted
upon.

*:export-mbox* _<file>_
Exports messages in the current folder to an mbox file. If there are marked
Expand Down

0 comments on commit 5600215

Please sign in to comment.