diff options
author | Reto Brunner <reto@labrat.space> | 2019-07-04 11:17:21 +0200 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-04 12:24:16 -0400 |
commit | d7fecf7740655e9d772963fd7e2a6d2af81458df (patch) | |
tree | 84237464c4d77bbfad39fefe79b9cb875956283c | |
parent | f9d26eef58ce2b9fa1e2443032c17c2ccc6afa36 (diff) | |
download | aerc-d7fecf7740655e9d772963fd7e2a6d2af81458df.tar.gz |
dirlist: sync dirstore in filterDirsByFoldersConfig
Also sets the public List() method to return the unfiltered
list of directories directly from the store.
-rw-r--r-- | widgets/dirlist.go | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/widgets/dirlist.go b/widgets/dirlist.go index 1cbc055f..2e7dd066 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -43,10 +43,6 @@ func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig, return dirlist } -func (dirlist *DirectoryList) FilteredList() []string { - return dirlist.dirs -} - func (dirlist *DirectoryList) List() []string { return dirlist.store.List() } @@ -62,6 +58,7 @@ func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) { case *types.Done: sort.Strings(dirs) dirlist.store.Update(dirs) + dirlist.filterDirsByFoldersConfig() dirlist.spinner.Stop() dirlist.Invalidate() if done != nil { @@ -114,14 +111,14 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) { return } - if len(dirlist.store.List()) == 0 { + if len(dirlist.dirs) == 0 { style := tcell.StyleDefault ctx.Printf(0, 0, style, dirlist.uiConf.EmptyDirlist) return } row := 0 - for _, name := range dirlist.store.List() { + for _, name := range dirlist.dirs { if row >= ctx.Height() { break } @@ -179,15 +176,16 @@ func (dirlist *DirectoryList) Prev() { dirlist.nextPrev(-1) } -// filterDirsByFoldersConfig filters a folders list to only contain folders -// present in the account.folders config option +// filterDirsByFoldersConfig sets dirlist.dirs to the filtered subset of the +// dirstore, based on the AccountConfig.Folders option func (dirlist *DirectoryList) filterDirsByFoldersConfig() { + dirlist.dirs = dirlist.store.List() // config option defaults to show all if unset if len(dirlist.acctConf.Folders) == 0 { return } var filtered []string - for _, folder := range dirlist.store.List() { + for _, folder := range dirlist.dirs { for _, cfgfolder := range dirlist.acctConf.Folders { if folder == cfgfolder { filtered = append(filtered, folder) |