aboutsummaryrefslogtreecommitdiff
path: root/widgets/dirlist.go
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-01-26 12:43:46 +0100
committerDrew DeVault <sir@cmpwn.com>2020-01-28 10:36:01 -0500
commitea0df7bee433fedae5716906ea56141f92b9ce53 (patch)
treee4cee0f53401d0774758437bf4052973bd091e1f /widgets/dirlist.go
parent2a3d120d6f138918ba8e62f04db78c327cb3ec18 (diff)
dirlist: adapt to dynamic UIconfig
Diffstat (limited to 'widgets/dirlist.go')
-rw-r--r--widgets/dirlist.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index edc84c6..5cdbe06 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -18,8 +18,8 @@ import (
type DirectoryList struct {
ui.Invalidatable
+ aercConf *config.AercConfig
acctConf *config.AccountConfig
- uiConf *config.UIConfig
store *lib.DirStore
dirs []string
logger *log.Logger
@@ -29,17 +29,18 @@ type DirectoryList struct {
worker *types.Worker
}
-func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
+func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
logger *log.Logger, worker *types.Worker) *DirectoryList {
dirlist := &DirectoryList{
+ aercConf: conf,
acctConf: acctConf,
- uiConf: uiConf,
logger: logger,
- spinner: NewSpinner(uiConf),
store: lib.NewDirStore(),
worker: worker,
}
+ uiConf := dirlist.UiConfig()
+ dirlist.spinner = NewSpinner(&uiConf)
dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
dirlist.Invalidate()
})
@@ -47,6 +48,13 @@ func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
return dirlist
}
+func (dirlist *DirectoryList) UiConfig() config.UIConfig {
+ return dirlist.aercConf.GetUiConfig(map[config.ContextType]string{
+ config.UI_CONTEXT_ACCOUNT: dirlist.acctConf.Name,
+ config.UI_CONTEXT_FOLDER: dirlist.Selected(),
+ })
+}
+
func (dirlist *DirectoryList) List() []string {
return dirlist.store.List()
}
@@ -118,7 +126,7 @@ func (dirlist *DirectoryList) getDirString(name string, width int, recentUnseen
formatted = runewidth.FillRight(formatted, width-len(s))
formatted = runewidth.Truncate(formatted, width-len(s), "…")
}
- for _, char := range dirlist.uiConf.DirListFormat {
+ for _, char := range dirlist.UiConfig().DirListFormat {
switch char {
case '%':
if percent {
@@ -206,7 +214,7 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
if len(dirlist.dirs) == 0 {
style := tcell.StyleDefault
- ctx.Printf(0, 0, style, dirlist.uiConf.EmptyDirlist)
+ ctx.Printf(0, 0, style, dirlist.UiConfig().EmptyDirlist)
return
}
@@ -304,8 +312,9 @@ func folderMatches(folder string, pattern string) bool {
// will be appended at the end in alphabetical order
func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
sort.Slice(dirlist.dirs, func(i, j int) bool {
- iInFoldersSort := findString(dirlist.acctConf.FoldersSort, dirlist.dirs[i])
- jInFoldersSort := findString(dirlist.acctConf.FoldersSort, dirlist.dirs[j])
+ foldersSort := dirlist.acctConf.FoldersSort
+ iInFoldersSort := findString(foldersSort, dirlist.dirs[i])
+ jInFoldersSort := findString(foldersSort, dirlist.dirs[j])
if iInFoldersSort >= 0 && jInFoldersSort >= 0 {
return iInFoldersSort < jInFoldersSort
}
@@ -324,12 +333,13 @@ func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
dirlist.dirs = dirlist.store.List()
// config option defaults to show all if unset
- if len(dirlist.acctConf.Folders) == 0 {
+ configFolders := dirlist.acctConf.Folders
+ if len(configFolders) == 0 {
return
}
var filtered []string
for _, folder := range dirlist.dirs {
- for _, cfgfolder := range dirlist.acctConf.Folders {
+ for _, cfgfolder := range configFolders {
if folderMatches(folder, cfgfolder) {
filtered = append(filtered, folder)
break