fix: Set proper UIConfig for msgstores

The merged UIConfig used to create new message stores is based on the
selected directory. If the message store is created by other means than
selecting (ListDirectories for maildir/notmuch/mbox, or check-mail) it
may have an incorrect configuration if the user has folder-specific
values for:

- Threaded view
- Client built threads
- Client threads delay
- Sort criteria
- NewMessage bell

Use the correct merged UIConfig when creating a new message store.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-08-12 14:51:25 -05:00 committed by Robin Jarry
parent 0db924dc14
commit e1b62db583
4 changed files with 28 additions and 24 deletions

View File

@ -42,7 +42,7 @@ type AccountView struct {
func (acct *AccountView) UiConfig() *config.UIConfig {
if dirlist := acct.Directories(); dirlist != nil {
return dirlist.UiConfig()
return dirlist.UiConfig("")
}
return acct.uiConf
}
@ -291,16 +291,17 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
if store, ok := acct.dirlist.MsgStore(msg.Info.Name); ok {
store.Update(msg)
} else {
name := msg.Info.Name
store = lib.NewMessageStore(acct.worker, msg.Info,
acct.GetSortCriteria(),
acct.UiConfig().ThreadingEnabled,
acct.UiConfig().ForceClientThreads,
acct.UiConfig().ClientThreadsDelay,
acct.dirlist.UiConfig(name).ThreadingEnabled,
acct.dirlist.UiConfig(name).ForceClientThreads,
acct.dirlist.UiConfig(name).ClientThreadsDelay,
func(msg *models.MessageInfo) {
acct.conf.Triggers.ExecNewEmail(acct.acct,
acct.conf, msg)
}, func() {
if acct.UiConfig().NewMessageBell {
if acct.dirlist.UiConfig(name).NewMessageBell {
acct.host.Beep()
}
})

View File

@ -43,7 +43,7 @@ type DirectoryLister interface {
FilterDirs([]string, []string, bool) []string
UiConfig() *config.UIConfig
UiConfig(string) *config.UIConfig
}
type DirectoryList struct {
@ -78,7 +78,7 @@ func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
skipSelectCancel: cancel,
uiConf: uiConfMap,
}
uiConf := dirlist.UiConfig()
uiConf := dirlist.UiConfig("")
dirlist.spinner = NewSpinner(uiConf)
dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
dirlist.Invalidate()
@ -92,15 +92,18 @@ func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
return dirlist
}
func (dirlist *DirectoryList) UiConfig() *config.UIConfig {
if ui, ok := dirlist.uiConf[dirlist.Selected()]; ok {
func (dirlist *DirectoryList) UiConfig(dir string) *config.UIConfig {
if dir == "" {
dir = dirlist.Selected()
}
if ui, ok := dirlist.uiConf[dir]; ok {
return ui
}
ui := dirlist.aercConf.GetUiConfig(map[config.ContextType]string{
config.UI_CONTEXT_ACCOUNT: dirlist.acctConf.Name,
config.UI_CONTEXT_FOLDER: dirlist.Selected(),
config.UI_CONTEXT_FOLDER: dir,
})
dirlist.uiConf[dirlist.Selected()] = ui
dirlist.uiConf[dir] = ui
return ui
}
@ -154,7 +157,7 @@ func (dirlist *DirectoryList) Select(name string) {
defer logging.PanicHandler()
select {
case <-time.After(dirlist.UiConfig().DirListDelay):
case <-time.After(dirlist.UiConfig(name).DirListDelay):
newStore := true
for _, s := range dirlist.store.List() {
if s == dirlist.selecting {
@ -218,7 +221,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.UiConfig().DirListFormat {
for _, char := range dirlist.UiConfig(name).DirListFormat {
switch char {
case '%':
if percent {
@ -283,7 +286,7 @@ func (dirlist *DirectoryList) getRUEString(name string) string {
func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ',
dirlist.UiConfig().GetStyle(config.STYLE_DIRLIST_DEFAULT))
dirlist.UiConfig("").GetStyle(config.STYLE_DIRLIST_DEFAULT))
if dirlist.spinner.IsRunning() {
dirlist.spinner.Draw(ctx)
@ -291,8 +294,8 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
}
if len(dirlist.dirs) == 0 {
style := dirlist.UiConfig().GetStyle(config.STYLE_DIRLIST_DEFAULT)
ctx.Printf(0, 0, style, dirlist.UiConfig().EmptyDirlist)
style := dirlist.UiConfig("").GetStyle(config.STYLE_DIRLIST_DEFAULT)
ctx.Printf(0, 0, style, dirlist.UiConfig("").EmptyDirlist)
return
}
@ -324,10 +327,10 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
case 2:
dirStyle = append(dirStyle, config.STYLE_DIRLIST_RECENT)
}
style := dirlist.UiConfig().GetComposedStyle(
style := dirlist.UiConfig(name).GetComposedStyle(
config.STYLE_DIRLIST_DEFAULT, dirStyle)
if name == dirlist.selecting {
style = dirlist.UiConfig().GetComposedStyleSelected(
style = dirlist.UiConfig(name).GetComposedStyleSelected(
config.STYLE_DIRLIST_DEFAULT, dirStyle)
}
ctx.Fill(0, row, textWidth, 1, ' ', style)

View File

@ -51,7 +51,7 @@ func (dt *DirectoryTree) UpdateList(done func([]string)) {
func (dt *DirectoryTree) Draw(ctx *ui.Context) {
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ',
dt.UiConfig().GetStyle(config.STYLE_DIRLIST_DEFAULT))
dt.UiConfig("").GetStyle(config.STYLE_DIRLIST_DEFAULT))
if dt.DirectoryList.spinner.IsRunning() {
dt.DirectoryList.spinner.Draw(ctx)
@ -60,8 +60,8 @@ func (dt *DirectoryTree) Draw(ctx *ui.Context) {
n := dt.countVisible(dt.list)
if n == 0 {
style := dt.UiConfig().GetStyle(config.STYLE_DIRLIST_DEFAULT)
ctx.Printf(0, 0, style, dt.UiConfig().EmptyDirlist)
style := dt.UiConfig("").GetStyle(config.STYLE_DIRLIST_DEFAULT)
ctx.Printf(0, 0, style, dt.UiConfig("").EmptyDirlist)
return
}
@ -104,10 +104,10 @@ func (dt *DirectoryTree) Draw(ctx *ui.Context) {
case 2:
dirStyle = append(dirStyle, config.STYLE_DIRLIST_RECENT)
}
style := dt.UiConfig().GetComposedStyle(
style := dt.UiConfig(path).GetComposedStyle(
config.STYLE_DIRLIST_DEFAULT, dirStyle)
if i == dt.listIdx {
style = dt.UiConfig().GetComposedStyleSelected(
style = dt.UiConfig(path).GetComposedStyleSelected(
config.STYLE_DIRLIST_DEFAULT, dirStyle)
}
ctx.Fill(0, row, textWidth, 1, ' ', style)

View File

@ -201,7 +201,7 @@ func (ml *MessageList) drawRow(textWidth int, ctx *ui.Context, uid uint32, row i
// should implement a better per-message styling method
// Check if we have any applicable ContextualUIConfigs
confs := ml.aerc.conf.GetContextualUIConfigs()
uiConfig := acct.Directories().UiConfig()
uiConfig := acct.Directories().UiConfig(store.DirInfo.Name)
for _, c := range confs {
if c.ContextType == config.UI_CONTEXT_SUBJECT && msg.Envelope != nil {
if c.Regex.Match([]byte(msg.Envelope.Subject)) {