dirlist: sync dirstore in filterDirsByFoldersConfig

Also sets the public List() method to return the unfiltered
list of directories directly from the store.
This commit is contained in:
Reto Brunner 2019-07-04 11:17:21 +02:00 committed by Drew DeVault
parent f9d26eef58
commit d7fecf7740

View file

@ -43,10 +43,6 @@ func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
return dirlist return dirlist
} }
func (dirlist *DirectoryList) FilteredList() []string {
return dirlist.dirs
}
func (dirlist *DirectoryList) List() []string { func (dirlist *DirectoryList) List() []string {
return dirlist.store.List() return dirlist.store.List()
} }
@ -62,6 +58,7 @@ func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
case *types.Done: case *types.Done:
sort.Strings(dirs) sort.Strings(dirs)
dirlist.store.Update(dirs) dirlist.store.Update(dirs)
dirlist.filterDirsByFoldersConfig()
dirlist.spinner.Stop() dirlist.spinner.Stop()
dirlist.Invalidate() dirlist.Invalidate()
if done != nil { if done != nil {
@ -114,14 +111,14 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
return return
} }
if len(dirlist.store.List()) == 0 { if len(dirlist.dirs) == 0 {
style := tcell.StyleDefault style := tcell.StyleDefault
ctx.Printf(0, 0, style, dirlist.uiConf.EmptyDirlist) ctx.Printf(0, 0, style, dirlist.uiConf.EmptyDirlist)
return return
} }
row := 0 row := 0
for _, name := range dirlist.store.List() { for _, name := range dirlist.dirs {
if row >= ctx.Height() { if row >= ctx.Height() {
break break
} }
@ -179,15 +176,16 @@ func (dirlist *DirectoryList) Prev() {
dirlist.nextPrev(-1) dirlist.nextPrev(-1)
} }
// filterDirsByFoldersConfig filters a folders list to only contain folders // filterDirsByFoldersConfig sets dirlist.dirs to the filtered subset of the
// present in the account.folders config option // dirstore, based on the AccountConfig.Folders option
func (dirlist *DirectoryList) filterDirsByFoldersConfig() { func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
dirlist.dirs = dirlist.store.List()
// config option defaults to show all if unset // config option defaults to show all if unset
if len(dirlist.acctConf.Folders) == 0 { if len(dirlist.acctConf.Folders) == 0 {
return return
} }
var filtered []string var filtered []string
for _, folder := range dirlist.store.List() { for _, folder := range dirlist.dirs {
for _, cfgfolder := range dirlist.acctConf.Folders { for _, cfgfolder := range dirlist.acctConf.Folders {
if folder == cfgfolder { if folder == cfgfolder {
filtered = append(filtered, folder) filtered = append(filtered, folder)