aboutsummaryrefslogtreecommitdiff
path: root/widgets
diff options
context:
space:
mode:
authorGalen Abell <galen@galenabell.com>2019-07-27 10:38:53 -0400
committerDrew DeVault <sir@cmpwn.com>2019-07-27 12:37:55 -0400
commit0ee7d30187920751c6e79facbd87ebce86d62ec9 (patch)
tree3b56110366eb95e40049fef851747f42ff53e4c9 /widgets
parenta669233614d3b4134baabd3325cb64e8f0f2cdeb (diff)
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.
Diffstat (limited to 'widgets')
-rw-r--r--widgets/compose.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/widgets/compose.go b/widgets/compose.go
index 6a41e70..3dd569d 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)