diff options
author | Daniel Bridges <bridges2@gmail.com> | 2019-08-01 11:29:21 -0700 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-08-03 10:43:55 -0400 |
commit | f4b774146387f147d6e693d789889bfdd817a290 (patch) | |
tree | 9698171277749cc9885a161de45895c57649d130 /widgets | |
parent | b72bb27cb45f25d1df0d93be17474d8a08715411 (diff) | |
download | aerc-f4b774146387f147d6e693d789889bfdd817a290.tar.gz |
Add cc and bcc commands
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/compose.go | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/widgets/compose.go b/widgets/compose.go index a0a5259..e2615ed 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -34,9 +34,11 @@ type Composer struct { email *os.File attachments []string grid *ui.Grid + header *ui.Grid review *reviewMessage worker *types.Worker + layout HeaderLayout focusable []ui.DrawableInteractive focused int } @@ -54,38 +56,26 @@ func NewComposer(conf *config.AercConfig, layout, editors, focusable := buildComposeHeader( conf.Compose.HeaderLayout, defaults) - header, headerHeight := layout.grid( - func(header string) ui.Drawable { return editors[header] }, - ) - - grid := ui.NewGrid().Rows([]ui.GridSpec{ - {ui.SIZE_EXACT, headerHeight}, - {ui.SIZE_WEIGHT, 1}, - }).Columns([]ui.GridSpec{ - {ui.SIZE_WEIGHT, 1}, - }) - email, err := ioutil.TempFile("", "aerc-compose-*.eml") if err != nil { // TODO: handle this better return nil } - grid.AddChild(header).At(0, 0) - c := &Composer{ editors: editors, acct: acct, config: conf, defaults: defaults, email: email, - grid: grid, worker: worker, + layout: layout, // You have to backtab to get to "From", since you usually don't edit it focused: 1, focusable: focusable, } + c.updateGrid() c.ShowTerminal() return c @@ -518,6 +508,46 @@ func (c *Composer) NextField() { c.focusable[c.focused].Focus(true) } +// AddEditor appends a new header editor to the compose window. +func (c *Composer) AddEditor(header string, value string) { + if _, ok := c.editors[header]; ok { + c.editors[header].input.Set(value) + return + } + e := newHeaderEditor(header, value) + c.editors[header] = e + c.layout = append(c.layout, []string{header}) + // Insert focus of new editor before terminal editor + c.focusable = append( + c.focusable[:len(c.focusable)-1], + e, + c.focusable[len(c.focusable)-1], + ) + c.updateGrid() +} + +// updateGrid should be called when the underlying header layout is changed. +func (c *Composer) updateGrid() { + header, height := c.layout.grid( + func(h string) ui.Drawable { return c.editors[h] }, + ) + + if c.grid == nil { + c.grid = ui.NewGrid().Columns([]ui.GridSpec{{ui.SIZE_WEIGHT, 1}}) + } + + c.grid.Rows([]ui.GridSpec{ + {ui.SIZE_EXACT, height}, + {ui.SIZE_WEIGHT, 1}, + }) + + if c.header != nil { + c.grid.RemoveChild(c.header) + } + c.header = header + c.grid.AddChild(c.header).At(0, 0) +} + func (c *Composer) reloadEmail() error { name := c.email.Name() c.email.Close() |