diff options
author | Robin Jarry <robin@jarry.cc> | 2023-12-04 23:39:49 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-01-20 21:56:25 +0100 |
commit | 159fb38daf5336758abc425447cf2c2ed51de59a (patch) | |
tree | e7be3bea878b12e441332f89d7bc3c63db477c05 /commands/msgview/next.go | |
parent | d2817371867e94b621de4054b235d53312db8073 (diff) | |
download | aerc-159fb38daf5336758abc425447cf2c2ed51de59a.tar.gz |
commands: refactor registration
Register all commands with the same function and store them in the same
map.
Use bit flags to determine in which contexts each command should be
available.
Remove duplicate commands now that the same command can be exposed in
multiple contexts.
Refactor API to allow executing commands from other commands without
import cycles.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Tested-by: Johannes Thyssen Tishman <johannes@thyssentishman.com>
Diffstat (limited to 'commands/msgview/next.go')
-rw-r--r-- | commands/msgview/next.go | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/commands/msgview/next.go b/commands/msgview/next.go deleted file mode 100644 index c953cd5d..00000000 --- a/commands/msgview/next.go +++ /dev/null @@ -1,83 +0,0 @@ -package msgview - -import ( - "errors" - "fmt" - "strconv" - "strings" - - "git.sr.ht/~rjarry/aerc/app" - "git.sr.ht/~rjarry/aerc/commands/account" - "git.sr.ht/~rjarry/aerc/lib" - "git.sr.ht/~rjarry/aerc/models" - "git.sr.ht/~rjarry/aerc/worker/types" -) - -type NextPrevMsg struct { - Amount int `opt:"n" default:"1" metavar:"N[%]" action:"ParseAmount"` - Percent bool -} - -func init() { - register(NextPrevMsg{}) -} - -func (np *NextPrevMsg) ParseAmount(arg string) error { - if strings.HasSuffix(arg, "%") { - np.Percent = true - arg = strings.TrimSuffix(arg, "%") - } - i, err := strconv.ParseInt(arg, 10, 64) - if err != nil { - return err - } - np.Amount = int(i) - return nil -} - -func (NextPrevMsg) Aliases() []string { - return []string{"next", "next-message", "prev", "prev-message"} -} - -func (np NextPrevMsg) Execute(args []string) error { - cmd := account.NextPrevMsg{Amount: np.Amount, Percent: np.Percent} - err := cmd.Execute(args) - if err != nil { - return err - } - - mv, _ := app.SelectedTabContent().(*app.MessageViewer) - acct := mv.SelectedAccount() - if acct == nil { - return errors.New("No account selected") - } - store := mv.Store() - if store == nil { - return fmt.Errorf("Cannot perform action. No message store set.") - } - executeNextPrev := func(nextMsg *models.MessageInfo) { - lib.NewMessageStoreView(nextMsg, mv.MessageView().SeenFlagSet(), - store, app.CryptoProvider(), app.DecryptKeys, - func(view lib.MessageView, err error) { - if err != nil { - app.PushError(err.Error()) - return - } - nextMv := app.NewMessageViewer(acct, view) - app.ReplaceTab(mv, nextMv, - nextMsg.Envelope.Subject, true) - }) - } - if nextMsg := store.Selected(); nextMsg != nil { - executeNextPrev(nextMsg) - } else { - store.FetchHeaders([]uint32{store.SelectedUid()}, - func(msg types.WorkerMessage) { - if m, ok := msg.(*types.MessageInfo); ok { - executeNextPrev(m.Info) - } - }) - } - - return nil -} |