Add new lib/dirstore to source completions from
This commit is contained in:
parent
2a0961701c
commit
546dfcd76d
2 changed files with 27 additions and 4 deletions
20
lib/dirstore.go
Normal file
20
lib/dirstore.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package lib
|
||||||
|
|
||||||
|
type DirStore struct {
|
||||||
|
dirs []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDirStore() *DirStore {
|
||||||
|
return &DirStore{
|
||||||
|
dirs: make([]string, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *DirStore) Update(dirs []string) {
|
||||||
|
store.dirs = make([]string, len(dirs))
|
||||||
|
copy(store.dirs, dirs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *DirStore) List() []string {
|
||||||
|
return store.dirs
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
|
||||||
"git.sr.ht/~sircmpwn/aerc/config"
|
"git.sr.ht/~sircmpwn/aerc/config"
|
||||||
|
"git.sr.ht/~sircmpwn/aerc/lib"
|
||||||
"git.sr.ht/~sircmpwn/aerc/lib/ui"
|
"git.sr.ht/~sircmpwn/aerc/lib/ui"
|
||||||
"git.sr.ht/~sircmpwn/aerc/worker/types"
|
"git.sr.ht/~sircmpwn/aerc/worker/types"
|
||||||
)
|
)
|
||||||
|
@ -15,6 +16,7 @@ type DirectoryList struct {
|
||||||
ui.Invalidatable
|
ui.Invalidatable
|
||||||
acctConf *config.AccountConfig
|
acctConf *config.AccountConfig
|
||||||
uiConf *config.UIConfig
|
uiConf *config.UIConfig
|
||||||
|
store *lib.DirStore
|
||||||
dirs []string
|
dirs []string
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
selecting string
|
selecting string
|
||||||
|
@ -31,6 +33,7 @@ func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
|
||||||
uiConf: uiConf,
|
uiConf: uiConf,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
spinner: NewSpinner(),
|
spinner: NewSpinner(),
|
||||||
|
store: lib.NewDirStore(),
|
||||||
worker: worker,
|
worker: worker,
|
||||||
}
|
}
|
||||||
dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
|
dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
|
||||||
|
@ -54,7 +57,7 @@ func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
|
||||||
dirs = append(dirs, msg.Name)
|
dirs = append(dirs, msg.Name)
|
||||||
case *types.Done:
|
case *types.Done:
|
||||||
sort.Strings(dirs)
|
sort.Strings(dirs)
|
||||||
dirlist.dirs = dirs
|
dirlist.store.Update(dirs)
|
||||||
dirlist.spinner.Stop()
|
dirlist.spinner.Stop()
|
||||||
dirlist.Invalidate()
|
dirlist.Invalidate()
|
||||||
if done != nil {
|
if done != nil {
|
||||||
|
@ -107,14 +110,14 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(dirlist.dirs) == 0 {
|
if len(dirlist.store.List()) == 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.dirs {
|
for _, name := range dirlist.store.List() {
|
||||||
if row >= ctx.Height() {
|
if row >= ctx.Height() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -180,7 +183,7 @@ func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var filtered []string
|
var filtered []string
|
||||||
for _, folder := range dirlist.dirs {
|
for _, folder := range dirlist.store.List() {
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue