tabs: rename SelectedTab to SelectedTabContent

This function returns an ui.Drawable. Use a more explicit name. This
prepares for adding a new SelectedTab function which will return
an ui.Tab.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Koni Marti <koni.marti@gmail.com>
This commit is contained in:
Robin Jarry 2022-07-18 12:54:55 +02:00
parent c49a065496
commit c841f36513
29 changed files with 36 additions and 36 deletions

View File

@ -59,7 +59,7 @@ func getCommands(selected libui.Drawable) []*commands.Commands {
} }
func execCommand(aerc *widgets.Aerc, ui *libui.UI, cmd []string) error { func execCommand(aerc *widgets.Aerc, ui *libui.UI, cmd []string) error {
cmds := getCommands(aerc.SelectedTab()) cmds := getCommands(aerc.SelectedTabContent())
for i, set := range cmds { for i, set := range cmds {
err := set.ExecuteCommand(aerc, cmd) err := set.ExecuteCommand(aerc, cmd)
if _, ok := err.(commands.NoSuchCommand); ok { if _, ok := err.(commands.NoSuchCommand); ok {
@ -81,7 +81,7 @@ func execCommand(aerc *widgets.Aerc, ui *libui.UI, cmd []string) error {
func getCompletions(aerc *widgets.Aerc, cmd string) []string { func getCompletions(aerc *widgets.Aerc, cmd string) []string {
var completions []string var completions []string
for _, set := range getCommands(aerc.SelectedTab()) { for _, set := range getCommands(aerc.SelectedTabContent()) {
completions = append(completions, set.GetCompletions(aerc, cmd)...) completions = append(completions, set.GetCompletions(aerc, cmd)...)
} }
sort.Strings(completions) sort.Strings(completions)

View File

@ -24,7 +24,7 @@ func (Abort) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return errors.New("Usage: abort") return errors.New("Usage: abort")
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
aerc.RemoveTab(composer) aerc.RemoveTab(composer)
composer.Close() composer.Close()

View File

@ -25,7 +25,7 @@ func (AttachKey) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: attach-key") return errors.New("Usage: attach-key")
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
return composer.SetAttachKey(!composer.AttachKey()) return composer.SetAttachKey(!composer.AttachKey())
} }

View File

@ -47,7 +47,7 @@ func (Attach) Execute(aerc *widgets.Aerc, args []string) error {
return nil return nil
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
composer.AddAttachment(path) composer.AddAttachment(path)
aerc.PushSuccess(fmt.Sprintf("Attached %s", pathinfo.Name())) aerc.PushSuccess(fmt.Sprintf("Attached %s", pathinfo.Name()))

View File

@ -25,7 +25,7 @@ func (CC) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) > 1 { if len(args) > 1 {
addrs = strings.Join(args[1:], " ") addrs = strings.Join(args[1:], " ")
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
switch args[0] { switch args[0] {
case "cc": case "cc":

View File

@ -18,13 +18,13 @@ func (Detach) Aliases() []string {
} }
func (Detach) Complete(aerc *widgets.Aerc, args []string) []string { func (Detach) Complete(aerc *widgets.Aerc, args []string) []string {
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
return composer.GetAttachments() return composer.GetAttachments()
} }
func (Detach) Execute(aerc *widgets.Aerc, args []string) error { func (Detach) Execute(aerc *widgets.Aerc, args []string) error {
var path string var path string
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
if len(args) > 1 { if len(args) > 1 {
path = strings.Join(args[1:], " ") path = strings.Join(args[1:], " ")

View File

@ -24,7 +24,7 @@ func (Edit) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return errors.New("Usage: edit") return errors.New("Usage: edit")
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
composer.ShowTerminal() composer.ShowTerminal()
composer.FocusTerminal() composer.FocusTerminal()
return nil return nil

View File

@ -25,7 +25,7 @@ func (Encrypt) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: encrypt") return errors.New("Usage: encrypt")
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
composer.SetEncrypt(!composer.Encrypt()) composer.SetEncrypt(!composer.Encrypt())
return nil return nil

View File

@ -60,7 +60,7 @@ func (Header) Execute(aerc *widgets.Aerc, args []string) error {
} }
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
args[optind] = strings.TrimRight(args[optind], ":") args[optind] = strings.TrimRight(args[optind], ":")

View File

@ -24,7 +24,7 @@ func (NextPrevField) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) > 2 { if len(args) > 2 {
return nextPrevFieldUsage(args[0]) return nextPrevFieldUsage(args[0])
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
if args[0] == "prev-field" { if args[0] == "prev-field" {
composer.PrevField() composer.PrevField()
} else { } else {

View File

@ -35,7 +35,7 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
if acct == nil { if acct == nil {
return errors.New("No account selected") return errors.New("No account selected")
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
config := composer.Config() config := composer.Config()
tabName := aerc.TabNames()[aerc.SelectedTabIndex()] tabName := aerc.TabNames()[aerc.SelectedTabIndex()]

View File

@ -43,7 +43,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) > 1 { if len(args) > 1 {
return errors.New("Usage: send") return errors.New("Usage: send")
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
tabName := aerc.TabNames()[aerc.SelectedTabIndex()] tabName := aerc.TabNames()[aerc.SelectedTabIndex()]
config := composer.Config() config := composer.Config()

View File

@ -26,7 +26,7 @@ func (Sign) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: sign") return errors.New("Usage: sign")
} }
composer, _ := aerc.SelectedTab().(*widgets.Composer) composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
err := composer.SetSign(!composer.Sign()) err := composer.SetSign(!composer.Sign())
if err != nil { if err != nil {

View File

@ -33,7 +33,7 @@ func (ExecCmd) Execute(aerc *widgets.Aerc, args []string) error {
cmd := exec.Command(args[1], args[2:]...) cmd := exec.Command(args[1], args[2:]...)
env := os.Environ() env := os.Environ()
switch view := aerc.SelectedTab().(type) { switch view := aerc.SelectedTabContent().(type) {
case *widgets.AccountView: case *widgets.AccountView:
env = append(env, fmt.Sprintf("account=%s", view.AccountConfig().Name)) env = append(env, fmt.Sprintf("account=%s", view.AccountConfig().Name))
env = append(env, fmt.Sprintf("folder=%s", view.Directories().Selected())) env = append(env, fmt.Sprintf("folder=%s", view.Directories().Selected()))

View File

@ -60,7 +60,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Options -A and -F are mutually exclusive") return errors.New("Options -A and -F are mutually exclusive")
} }
widget := aerc.SelectedTab().(widgets.ProvidesMessage) widget := aerc.SelectedTabContent().(widgets.ProvidesMessage)
acct := widget.SelectedAccount() acct := widget.SelectedAccount()
if acct == nil { if acct == nil {
return errors.New("No account selected") return errors.New("No account selected")

View File

@ -63,7 +63,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: pipe [-mp] <cmd> [args...]") return errors.New("Usage: pipe [-mp] <cmd> [args...]")
} }
provider := aerc.SelectedTab().(widgets.ProvidesMessage) provider := aerc.SelectedTabContent().(widgets.ProvidesMessage)
if !pipeFull && !pipePart { if !pipeFull && !pipePart {
if _, ok := provider.(*widgets.MessageViewer); ok { if _, ok := provider.(*widgets.MessageViewer); ok {
pipePart = true pipePart = true

View File

@ -51,7 +51,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: recall [-f]") return errors.New("Usage: recall [-f]")
} }
widget := aerc.SelectedTab().(widgets.ProvidesMessage) widget := aerc.SelectedTabContent().(widgets.ProvidesMessage)
acct := widget.SelectedAccount() acct := widget.SelectedAccount()
if acct == nil { if acct == nil {
return errors.New("No account selected") return errors.New("No account selected")

View File

@ -55,7 +55,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
} }
} }
widget := aerc.SelectedTab().(widgets.ProvidesMessage) widget := aerc.SelectedTabContent().(widgets.ProvidesMessage)
acct := widget.SelectedAccount() acct := widget.SelectedAccount()
if acct == nil { if acct == nil {

View File

@ -37,7 +37,7 @@ func (Unsubscribe) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return errors.New("Usage: unsubscribe") return errors.New("Usage: unsubscribe")
} }
widget := aerc.SelectedTab().(widgets.ProvidesMessage) widget := aerc.SelectedTabContent().(widgets.ProvidesMessage)
msg, err := widget.SelectedMessage() msg, err := widget.SelectedMessage()
if err != nil { if err != nil {
return err return err
@ -135,7 +135,7 @@ func parseUnsubscribeMethods(header string) (methods []*url.URL) {
} }
func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error { func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error {
widget := aerc.SelectedTab().(widgets.ProvidesMessage) widget := aerc.SelectedTabContent().(widgets.ProvidesMessage)
acct := widget.SelectedAccount() acct := widget.SelectedAccount()
if acct == nil { if acct == nil {
return errors.New("No account selected") return errors.New("No account selected")

View File

@ -14,7 +14,7 @@ type helper struct {
} }
func newHelper(aerc *widgets.Aerc) *helper { func newHelper(aerc *widgets.Aerc) *helper {
return &helper{aerc.SelectedTab().(widgets.ProvidesMessages)} return &helper{aerc.SelectedTabContent().(widgets.ProvidesMessages)}
} }
func (h *helper) markedOrSelectedUids() ([]uint32, error) { func (h *helper) markedOrSelectedUids() ([]uint32, error) {

View File

@ -24,7 +24,7 @@ func (Close) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return errors.New("Usage: close") return errors.New("Usage: close")
} }
mv, _ := aerc.SelectedTab().(*widgets.MessageViewer) mv, _ := aerc.SelectedTabContent().(*widgets.MessageViewer)
mv.Close() mv.Close()
aerc.RemoveTab(mv) aerc.RemoveTab(mv)
return nil return nil

View File

@ -35,7 +35,7 @@ func (NextPrevPart) Execute(aerc *widgets.Aerc, args []string) error {
return nextPrevPartUsage(args[0]) return nextPrevPartUsage(args[0])
} }
} }
mv, _ := aerc.SelectedTab().(*widgets.MessageViewer) mv, _ := aerc.SelectedTabContent().(*widgets.MessageViewer)
for ; n > 0; n-- { for ; n > 0; n-- {
if args[0] == "prev-part" { if args[0] == "prev-part" {
mv.PreviousPart() mv.PreviousPart()

View File

@ -27,7 +27,7 @@ func (NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
if err != nil { if err != nil {
return err return err
} }
mv, _ := aerc.SelectedTab().(*widgets.MessageViewer) mv, _ := aerc.SelectedTabContent().(*widgets.MessageViewer)
acct := mv.SelectedAccount() acct := mv.SelectedAccount()
if acct == nil { if acct == nil {
return errors.New("No account selected") return errors.New("No account selected")

View File

@ -25,7 +25,7 @@ func (Open) Aliases() []string {
} }
func (Open) Complete(aerc *widgets.Aerc, args []string) []string { func (Open) Complete(aerc *widgets.Aerc, args []string) []string {
mv := aerc.SelectedTab().(*widgets.MessageViewer) mv := aerc.SelectedTabContent().(*widgets.MessageViewer)
if mv != nil { if mv != nil {
if p := mv.SelectedMessagePart(); p != nil { if p := mv.SelectedMessagePart(); p != nil {
return commands.CompletionFromList(aerc, p.Links, args) return commands.CompletionFromList(aerc, p.Links, args)
@ -35,7 +35,7 @@ func (Open) Complete(aerc *widgets.Aerc, args []string) []string {
} }
func (Open) Execute(aerc *widgets.Aerc, args []string) error { func (Open) Execute(aerc *widgets.Aerc, args []string) error {
mv := aerc.SelectedTab().(*widgets.MessageViewer) mv := aerc.SelectedTabContent().(*widgets.MessageViewer)
p := mv.SelectedMessagePart() p := mv.SelectedMessagePart()
if args[0] == "open-link" && len(args) > 1 { if args[0] == "open-link" && len(args) > 1 {

View File

@ -99,9 +99,9 @@ func (Save) Execute(aerc *widgets.Aerc, args []string) error {
return err return err
} }
mv, ok := aerc.SelectedTab().(*widgets.MessageViewer) mv, ok := aerc.SelectedTabContent().(*widgets.MessageViewer)
if !ok { if !ok {
return fmt.Errorf("SelectedTab is not a MessageViewer") return fmt.Errorf("SelectedTabContent is not a MessageViewer")
} }
if params.attachments { if params.attachments {

View File

@ -24,7 +24,7 @@ func (ToggleHeaders) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) > 1 { if len(args) > 1 {
return toggleHeadersUsage(args[0]) return toggleHeadersUsage(args[0])
} }
mv, _ := aerc.SelectedTab().(*widgets.MessageViewer) mv, _ := aerc.SelectedTabContent().(*widgets.MessageViewer)
mv.ToggleHeaders() mv.ToggleHeaders()
return nil return nil
} }

View File

@ -25,7 +25,7 @@ func (ToggleKeyPassthrough) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return errors.New("Usage: toggle-key-passthrough") return errors.New("Usage: toggle-key-passthrough")
} }
mv, _ := aerc.SelectedTab().(*widgets.MessageViewer) mv, _ := aerc.SelectedTabContent().(*widgets.MessageViewer)
keyPassthroughEnabled := mv.ToggleKeyPassthrough() keyPassthroughEnabled := mv.ToggleKeyPassthrough()
if acct := mv.SelectedAccount(); acct != nil { if acct := mv.SelectedAccount(); acct != nil {
acct.SetStatus(statusline.Passthrough(keyPassthroughEnabled)) acct.SetStatus(statusline.Passthrough(keyPassthroughEnabled))

View File

@ -24,7 +24,7 @@ func (Close) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return errors.New("Usage: close") return errors.New("Usage: close")
} }
term, _ := aerc.SelectedTab().(*widgets.Terminal) term, _ := aerc.SelectedTabContent().(*widgets.Terminal)
term.Close(nil) term.Close(nil)
return nil return nil
} }

View File

@ -192,7 +192,7 @@ func (aerc *Aerc) getBindings() *config.KeyBindings {
if aerc.SelectedAccount() != nil { if aerc.SelectedAccount() != nil {
selectedAccountName = aerc.SelectedAccount().acct.Name selectedAccountName = aerc.SelectedAccount().acct.Name
} }
switch view := aerc.SelectedTab().(type) { switch view := aerc.SelectedTabContent().(type) {
case *AccountView: case *AccountView:
binds := aerc.conf.MergeContextualBinds(aerc.conf.Bindings.MessageList, config.BIND_CONTEXT_ACCOUNT, selectedAccountName, "messages") binds := aerc.conf.MergeContextualBinds(aerc.conf.Bindings.MessageList, config.BIND_CONTEXT_ACCOUNT, selectedAccountName, "messages")
return aerc.conf.MergeContextualBinds(binds, config.BIND_CONTEXT_FOLDER, view.SelectedDirectory(), "messages") return aerc.conf.MergeContextualBinds(binds, config.BIND_CONTEXT_FOLDER, view.SelectedDirectory(), "messages")
@ -310,7 +310,7 @@ func (aerc *Aerc) Logger() *log.Logger {
} }
func (aerc *Aerc) SelectedAccount() *AccountView { func (aerc *Aerc) SelectedAccount() *AccountView {
return aerc.account(aerc.SelectedTab()) return aerc.account(aerc.SelectedTabContent())
} }
func (aerc *Aerc) account(d ui.Drawable) *AccountView { func (aerc *Aerc) account(d ui.Drawable) *AccountView {
@ -333,7 +333,7 @@ func (aerc *Aerc) SelectedAccountUiConfig() *config.UIConfig {
return acct.UiConfig() return acct.UiConfig()
} }
func (aerc *Aerc) SelectedTab() ui.Drawable { func (aerc *Aerc) SelectedTabContent() ui.Drawable {
if aerc.NumTabs() == 0 || aerc.SelectedTabIndex() >= aerc.NumTabs() { if aerc.NumTabs() == 0 || aerc.SelectedTabIndex() >= aerc.NumTabs() {
return nil return nil
} }