dirlist: adapt to dynamic UIconfig
This commit is contained in:
parent
2a3d120d6f
commit
ea0df7bee4
2 changed files with 21 additions and 11 deletions
|
@ -65,7 +65,7 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dirlist := NewDirectoryList(acct, &acctUiConf, logger, worker)
|
dirlist := NewDirectoryList(conf, acct, logger, worker)
|
||||||
if acctUiConf.SidebarWidth > 0 {
|
if acctUiConf.SidebarWidth > 0 {
|
||||||
grid.AddChild(ui.NewBordered(dirlist, ui.BORDER_RIGHT))
|
grid.AddChild(ui.NewBordered(dirlist, ui.BORDER_RIGHT))
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@ import (
|
||||||
|
|
||||||
type DirectoryList struct {
|
type DirectoryList struct {
|
||||||
ui.Invalidatable
|
ui.Invalidatable
|
||||||
|
aercConf *config.AercConfig
|
||||||
acctConf *config.AccountConfig
|
acctConf *config.AccountConfig
|
||||||
uiConf *config.UIConfig
|
|
||||||
store *lib.DirStore
|
store *lib.DirStore
|
||||||
dirs []string
|
dirs []string
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
|
@ -29,17 +29,18 @@ type DirectoryList struct {
|
||||||
worker *types.Worker
|
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 {
|
logger *log.Logger, worker *types.Worker) *DirectoryList {
|
||||||
|
|
||||||
dirlist := &DirectoryList{
|
dirlist := &DirectoryList{
|
||||||
|
aercConf: conf,
|
||||||
acctConf: acctConf,
|
acctConf: acctConf,
|
||||||
uiConf: uiConf,
|
|
||||||
logger: logger,
|
logger: logger,
|
||||||
spinner: NewSpinner(uiConf),
|
|
||||||
store: lib.NewDirStore(),
|
store: lib.NewDirStore(),
|
||||||
worker: worker,
|
worker: worker,
|
||||||
}
|
}
|
||||||
|
uiConf := dirlist.UiConfig()
|
||||||
|
dirlist.spinner = NewSpinner(&uiConf)
|
||||||
dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
|
dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
|
||||||
dirlist.Invalidate()
|
dirlist.Invalidate()
|
||||||
})
|
})
|
||||||
|
@ -47,6 +48,13 @@ func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
|
||||||
return dirlist
|
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 {
|
func (dirlist *DirectoryList) List() []string {
|
||||||
return dirlist.store.List()
|
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.FillRight(formatted, width-len(s))
|
||||||
formatted = runewidth.Truncate(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 {
|
switch char {
|
||||||
case '%':
|
case '%':
|
||||||
if percent {
|
if percent {
|
||||||
|
@ -206,7 +214,7 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
|
||||||
|
|
||||||
if len(dirlist.dirs) == 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.UiConfig().EmptyDirlist)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,8 +312,9 @@ func folderMatches(folder string, pattern string) bool {
|
||||||
// will be appended at the end in alphabetical order
|
// will be appended at the end in alphabetical order
|
||||||
func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
|
func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
|
||||||
sort.Slice(dirlist.dirs, func(i, j int) bool {
|
sort.Slice(dirlist.dirs, func(i, j int) bool {
|
||||||
iInFoldersSort := findString(dirlist.acctConf.FoldersSort, dirlist.dirs[i])
|
foldersSort := dirlist.acctConf.FoldersSort
|
||||||
jInFoldersSort := findString(dirlist.acctConf.FoldersSort, dirlist.dirs[j])
|
iInFoldersSort := findString(foldersSort, dirlist.dirs[i])
|
||||||
|
jInFoldersSort := findString(foldersSort, dirlist.dirs[j])
|
||||||
if iInFoldersSort >= 0 && jInFoldersSort >= 0 {
|
if iInFoldersSort >= 0 && jInFoldersSort >= 0 {
|
||||||
return iInFoldersSort < jInFoldersSort
|
return iInFoldersSort < jInFoldersSort
|
||||||
}
|
}
|
||||||
|
@ -324,12 +333,13 @@ func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
|
||||||
func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
|
func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
|
||||||
dirlist.dirs = dirlist.store.List()
|
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 {
|
configFolders := dirlist.acctConf.Folders
|
||||||
|
if len(configFolders) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var filtered []string
|
var filtered []string
|
||||||
for _, folder := range dirlist.dirs {
|
for _, folder := range dirlist.dirs {
|
||||||
for _, cfgfolder := range dirlist.acctConf.Folders {
|
for _, cfgfolder := range configFolders {
|
||||||
if folderMatches(folder, cfgfolder) {
|
if folderMatches(folder, cfgfolder) {
|
||||||
filtered = append(filtered, folder)
|
filtered = append(filtered, folder)
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue