Debian Codegraph @

commands/account/clear.go

raw
1 package account
2
3 import (
4 "errors"
5
6 "git.sr.ht/~rjarry/aerc/app"
7 "git.sr.ht/~rjarry/aerc/commands"
8 "git.sr.ht/~rjarry/aerc/lib/state"
9 )
10
11 type Clear struct {
12 Selected bool `opt:"-s" desc:"Select first message after clearing."`
13 }
14
15 func init() {
16 commands.Register(Clear{})
17 }
18
19 func (Clear) Description() string {
20 return "Clear the current search or filter criteria."
21 }
22
23 func (Clear) Context() commands.CommandContext {
24 return commands.MESSAGE_LIST
25 }
26
27 func (Clear) Aliases() []string {
28 return []string{"clear"}
29 }
30
31 func (c Clear) Execute(args []string) error {
32 acct := app.SelectedAccount()
33 if acct == nil {
34 return errors.New("No account selected")
35 }
36 store := acct.Store()
37 if store == nil {
38 return errors.New("Cannot perform action. Messages still loading")
39 }
40
41 if c.Selected {
42 defer store.Select("")
43 }
44 store.ApplyClear()
45 acct.SetStatus(state.SearchFilterClear())
46
47 return nil
48 }