Set empty message in dirlist if no folder exist.

This commit is contained in:
Reto Brunner 2019-06-12 08:31:52 +02:00 committed by Drew DeVault
parent 626f91c483
commit 99c363b724
5 changed files with 40 additions and 18 deletions

View File

@ -27,6 +27,11 @@ sidebar-width=20
# Default: (no messages) # Default: (no messages)
empty-message=(no messages) empty-message=(no messages)
# Message to display when no folders exists or are all filtered
#
# Default: (no folders)
empty-dirlist=(no folders)
[viewer] [viewer]
# #
# Specifies the pager to use when displaying emails. Note that some filters # Specifies the pager to use when displaying emails. Note that some filters

View File

@ -26,6 +26,7 @@ type UIConfig struct {
SidebarWidth int `ini:"sidebar-width"` SidebarWidth int `ini:"sidebar-width"`
PreviewHeight int `ini:"preview-height"` PreviewHeight int `ini:"preview-height"`
EmptyMessage string `ini:"empty-message"` EmptyMessage string `ini:"empty-message"`
EmptyDirlist string `ini:"empty-dirlist"`
} }
const ( const (
@ -259,6 +260,7 @@ func LoadConfig(root *string, sharedir string) (*AercConfig, error) {
SidebarWidth: 20, SidebarWidth: 20,
PreviewHeight: 12, PreviewHeight: 12,
EmptyMessage: "(no messages)", EmptyMessage: "(no messages)",
EmptyDirlist: "(no folders)",
}, },
} }
// These bindings are not configurable // These bindings are not configurable

View File

@ -49,6 +49,11 @@ These options are configured in the *[ui]* section of aerc.conf.
Default: (no messages) Default: (no messages)
*empty-dirlist*
Message to display when no folders exists or are all filtered.
Default: (no folders)
## VIEWER ## VIEWER
These options are configured in the *[viewer]* section of aerc.conf. These options are configured in the *[viewer]* section of aerc.conf.

View File

@ -47,7 +47,7 @@ func NewAccountView(conf *config.AercConfig, acct *config.AccountConfig,
} }
} }
dirlist := NewDirectoryList(acct, logger, worker) dirlist := NewDirectoryList(acct, &conf.Ui, logger, worker)
if conf.Ui.SidebarWidth > 0 { if conf.Ui.SidebarWidth > 0 {
grid.AddChild(ui.NewBordered(dirlist, ui.BORDER_RIGHT)) grid.AddChild(ui.NewBordered(dirlist, ui.BORDER_RIGHT))
} }
@ -144,7 +144,9 @@ func (acct *AccountView) connected(msg types.WorkerMessage) {
if dir == "" && len(dirs) > 0 { if dir == "" && len(dirs) > 0 {
dir = dirs[0] dir = dirs[0]
} }
acct.dirlist.Select(dir) if dir != "" {
acct.dirlist.Select(dir)
}
acct.logger.Println("Connected.") acct.logger.Println("Connected.")
acct.host.SetStatus("Connected.") acct.host.SetStatus("Connected.")
}) })

View File

@ -13,7 +13,8 @@ import (
type DirectoryList struct { type DirectoryList struct {
ui.Invalidatable ui.Invalidatable
conf *config.AccountConfig acctConf *config.AccountConfig
uiConf *config.UIConfig
dirs []string dirs []string
logger *log.Logger logger *log.Logger
selecting string selecting string
@ -22,14 +23,15 @@ type DirectoryList struct {
worker *types.Worker worker *types.Worker
} }
func NewDirectoryList(conf *config.AccountConfig, func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
logger *log.Logger, worker *types.Worker) *DirectoryList { logger *log.Logger, worker *types.Worker) *DirectoryList {
dirlist := &DirectoryList{ dirlist := &DirectoryList{
conf: conf, acctConf: acctConf,
logger: logger, uiConf: uiConf,
spinner: NewSpinner(), logger: logger,
worker: worker, spinner: NewSpinner(),
worker: worker,
} }
dirlist.spinner.OnInvalidate(func(_ ui.Drawable) { dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
dirlist.Invalidate() dirlist.Invalidate()
@ -101,15 +103,21 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
return return
} }
if len(dirlist.dirs) == 0 {
style := tcell.StyleDefault
ctx.Printf(0, 0, style, dirlist.uiConf.EmptyDirlist)
return
}
row := 0 row := 0
for _, name := range dirlist.dirs { for _, name := range dirlist.dirs {
if row >= ctx.Height() { if row >= ctx.Height() {
break break
} }
if len(dirlist.conf.Folders) > 1 && name != dirlist.selected { if len(dirlist.acctConf.Folders) > 1 && name != dirlist.selected {
idx := sort.SearchStrings(dirlist.conf.Folders, name) idx := sort.SearchStrings(dirlist.acctConf.Folders, name)
if idx == len(dirlist.conf.Folders) || if idx == len(dirlist.acctConf.Folders) ||
dirlist.conf.Folders[idx] != name { dirlist.acctConf.Folders[idx] != name {
continue continue
} }
} }
@ -136,10 +144,10 @@ func (dirlist *DirectoryList) nextPrev(delta int) {
j = 0 j = 0
} }
name := dirlist.dirs[j] name := dirlist.dirs[j]
if len(dirlist.conf.Folders) > 1 && name != dirlist.selected { if len(dirlist.acctConf.Folders) > 1 && name != dirlist.selected {
idx := sort.SearchStrings(dirlist.conf.Folders, name) idx := sort.SearchStrings(dirlist.acctConf.Folders, name)
if idx == len(dirlist.conf.Folders) || if idx == len(dirlist.acctConf.Folders) ||
dirlist.conf.Folders[idx] != name { dirlist.acctConf.Folders[idx] != name {
continue continue
} }
@ -164,12 +172,12 @@ func (dirlist *DirectoryList) Prev() {
// present in the account.folders config option // present in the account.folders config option
func (dirlist *DirectoryList) filterDirsByFoldersConfig() { func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
// config option defaults to show all if unset // config option defaults to show all if unset
if len(dirlist.conf.Folders) == 0 { if len(dirlist.acctConf.Folders) == 0 {
return return
} }
var filtered []string var filtered []string
for _, folder := range dirlist.dirs { for _, folder := range dirlist.dirs {
for _, cfgfolder := range dirlist.conf.Folders { for _, cfgfolder := range dirlist.acctConf.Folders {
if folder == cfgfolder { if folder == cfgfolder {
filtered = append(filtered, folder) filtered = append(filtered, folder)
break break