c841f36513
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>
48 lines
935 B
Go
48 lines
935 B
Go
package compose
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
|
)
|
|
|
|
type Detach struct{}
|
|
|
|
func init() {
|
|
register(Detach{})
|
|
}
|
|
|
|
func (Detach) Aliases() []string {
|
|
return []string{"detach"}
|
|
}
|
|
|
|
func (Detach) Complete(aerc *widgets.Aerc, args []string) []string {
|
|
composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
|
|
return composer.GetAttachments()
|
|
}
|
|
|
|
func (Detach) Execute(aerc *widgets.Aerc, args []string) error {
|
|
var path string
|
|
composer, _ := aerc.SelectedTabContent().(*widgets.Composer)
|
|
|
|
if len(args) > 1 {
|
|
path = strings.Join(args[1:], " ")
|
|
} else {
|
|
// if no attachment is specified, delete the first in the list
|
|
atts := composer.GetAttachments()
|
|
if len(atts) > 0 {
|
|
path = atts[0]
|
|
} else {
|
|
return fmt.Errorf("No attachments to delete")
|
|
}
|
|
}
|
|
|
|
if err := composer.DeleteAttachment(path); err != nil {
|
|
return err
|
|
}
|
|
|
|
aerc.PushSuccess(fmt.Sprintf("Detached %s", path))
|
|
|
|
return nil
|
|
}
|