2019-07-27 14:38:53 +00:00
|
|
|
package compose
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.sr.ht/~sircmpwn/aerc/widgets"
|
|
|
|
"github.com/gdamore/tcell"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Detach struct{}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
register(Detach{})
|
|
|
|
}
|
|
|
|
|
2019-09-03 19:34:03 +00:00
|
|
|
func (Detach) Aliases() []string {
|
2019-07-27 14:38:53 +00:00
|
|
|
return []string{"detach"}
|
|
|
|
}
|
|
|
|
|
2019-09-03 19:34:03 +00:00
|
|
|
func (Detach) Complete(aerc *widgets.Aerc, args []string) []string {
|
2019-07-27 14:38:53 +00:00
|
|
|
composer, _ := aerc.SelectedTab().(*widgets.Composer)
|
|
|
|
|
|
|
|
return composer.GetAttachments()
|
|
|
|
}
|
|
|
|
|
2019-09-03 19:34:03 +00:00
|
|
|
func (Detach) Execute(aerc *widgets.Aerc, args []string) error {
|
2019-07-27 14:38:53 +00:00
|
|
|
var path string
|
|
|
|
composer, _ := aerc.SelectedTab().(*widgets.Composer)
|
|
|
|
|
|
|
|
if len(args) > 2 {
|
|
|
|
return fmt.Errorf("Usage: :detach [path]")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(args) == 2 {
|
|
|
|
path = 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.PushStatus(fmt.Sprintf("Detached %s", path), 10*time.Second).
|
|
|
|
Color(tcell.ColorDefault, tcell.ColorGreen)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|