From 0ee7d30187920751c6e79facbd87ebce86d62ec9 Mon Sep 17 00:00:00 2001 From: Galen Abell Date: Sat, 27 Jul 2019 10:38:53 -0400 Subject: Add :detach command Add a command for removing attachments from a composed message. Syntax is :detach [path], with path being an optional argument specifying the path of one existing attachment. If no path is specified, the first attachment is removed. --- widgets/compose.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'widgets') diff --git a/widgets/compose.go b/widgets/compose.go index 6a41e706..3dd569d8 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -434,8 +434,28 @@ func writeAttachment(path string, writer *mail.Writer) error { return nil } +func (c *Composer) GetAttachments() []string { + return c.attachments +} + func (c *Composer) AddAttachment(path string) { c.attachments = append(c.attachments, path) + c.resetReview() +} + +func (c *Composer) DeleteAttachment(path string) error { + for i, a := range c.attachments { + if a == path { + c.attachments = append(c.attachments[:i], c.attachments[i+1:]...) + c.resetReview() + return nil + } + } + + return errors.New("attachment does not exist") +} + +func (c *Composer) resetReview() { if c.review != nil { c.grid.RemoveChild(c.review) c.review = newReviewMessage(c, nil) -- cgit