diff options
author | Robin Jarry <robin@jarry.cc> | 2022-12-12 15:03:30 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-12-14 11:22:58 +0100 |
commit | c05c2ffe0424b048b10e7dd1aca59ae9cf631f12 (patch) | |
tree | 13a3a84eb74fdea77996161f01bec5596f67f39f /widgets/account.go | |
parent | 9d0297e9d913a92b2d7ae02692e83f0f4093a766 (diff) | |
download | aerc-c05c2ffe0424b048b10e7dd1aca59ae9cf631f12.tar.gz |
config: make various sections accessible via global vars
There is only one instance of AercConfig which is associated to the Aerc
widget. Everywhere we need to access configuration options, we need
somehow to get a reference either to the Aerc widget or to a pointer to
the AercConfig instance. This makes the code cluttered.
Remove the AercConfig structure and every place where it is referenced.
Instead, declare global variables for every configuration section and
access them directly from the `config` module.
Since bindings and ui sections can be "contextual" (i.e. per account,
per folder or per subject), leave most local references intact.
Replacing them with config.{Ui,Binds}.For{Account,Folder,Subject} would
make this patch even more unreadable. This is something that may be
addressed in the future.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'widgets/account.go')
-rw-r--r-- | widgets/account.go | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/widgets/account.go b/widgets/account.go index 838dd624..6bcb5b83 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -26,7 +26,6 @@ type AccountView struct { sync.Mutex acct *config.AccountConfig aerc *Aerc - conf *config.AercConfig dirlist DirectoryLister labels []string grid *ui.Grid @@ -55,17 +54,17 @@ func (acct *AccountView) UiConfig() *config.UIConfig { return acct.uiConf } -func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountConfig, +func NewAccountView( + aerc *Aerc, acct *config.AccountConfig, host TabHost, deferLoop chan struct{}, ) (*AccountView, error) { - acctUiConf := conf.Ui.ForAccount(acct.Name) + acctUiConf := config.Ui.ForAccount(acct.Name) view := &AccountView{ acct: acct, aerc: aerc, - conf: conf, host: host, - state: statusline.NewState(acct.Name, len(conf.Accounts) > 1, conf.Statusline), + state: statusline.NewState(acct.Name, len(config.Accounts) > 1), uiConf: acctUiConf, } @@ -86,12 +85,12 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon } view.worker = worker - view.dirlist = NewDirectoryList(conf, acct, worker) + view.dirlist = NewDirectoryList(acct, worker) if acctUiConf.SidebarWidth > 0 { view.grid.AddChild(ui.NewBordered(view.dirlist, ui.BORDER_RIGHT, acctUiConf)) } - view.msglist = NewMessageList(conf, aerc) + view.msglist = NewMessageList(aerc, view) view.grid.AddChild(view.msglist).At(0, 1) go func() { @@ -291,8 +290,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { acct.dirlist.UiConfig(name).ReverseThreadOrder, acct.dirlist.UiConfig(name).SortThreadSiblings, func(msg *models.MessageInfo) { - acct.conf.Triggers.ExecNewEmail(acct.acct, - acct.conf, msg) + config.Triggers.ExecNewEmail(acct.acct, msg) }, func() { if acct.dirlist.UiConfig(name).NewMessageBell { acct.host.Beep() @@ -526,7 +524,7 @@ func (acct *AccountView) UpdateSplitView() { return } orig := acct.split - acct.split = NewMessageViewer(acct, acct.conf, view) + acct.split = NewMessageViewer(acct, view) acct.grid.ReplaceChild(orig, acct.split) if orig != nil { orig.Close() @@ -585,7 +583,7 @@ func (acct *AccountView) Split(n int) error { acct.aerc.PushError(err.Error()) return } - acct.split = NewMessageViewer(acct, acct.conf, view) + acct.split = NewMessageViewer(acct, view) acct.grid.AddChild(acct.split).At(1, 1) }) ui.Invalidate() @@ -628,7 +626,7 @@ func (acct *AccountView) Vsplit(n int) error { acct.aerc.PushError(err.Error()) return } - acct.split = NewMessageViewer(acct, acct.conf, view) + acct.split = NewMessageViewer(acct, view) acct.grid.AddChild(acct.split).At(0, 2) }) ui.Invalidate() |