aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-07-05 23:10:39 +0200
committerRobin Jarry <robin@jarry.cc>2023-07-17 10:24:17 +0200
commit4c514ce4d15fd14cad528cf426bc3f853efe7f64 (patch)
treefa52247b470a6af233a6e242962ed20e4831a555 /widgets
parent11e5390fa0acbcc609ca177777548dd2d725afbc (diff)
downloadaerc-4c514ce4d15fd14cad528cf426bc3f853efe7f64.tar.gz
compose: allow changing edit-headers on the fly
Add -e|-E flags to all compose commands to allow switching between edit-headers = true/false without restarting aerc. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Tested-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'widgets')
-rw-r--r--widgets/aerc.go3
-rw-r--r--widgets/compose.go28
2 files changed, 18 insertions, 13 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 8f744b4c..faec403e 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -734,7 +734,8 @@ func (aerc *Aerc) Mailto(addr *url.URL) error {
defer ui.Invalidate()
composer, err := NewComposer(aerc, acct,
- acct.AccountConfig(), acct.Worker(), template, h, nil,
+ acct.AccountConfig(), acct.Worker(),
+ config.Compose.EditHeaders, template, h, nil,
strings.NewReader(body))
if err != nil {
return err
diff --git a/widgets/compose.go b/widgets/compose.go
index 9a54b632..2b8cbb12 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -54,6 +54,7 @@ type Composer struct {
sign bool
encrypt bool
attachKey bool
+ editHeaders bool
layout HeaderLayout
focusable []ui.MouseableDrawableInteractive
@@ -71,7 +72,7 @@ type Composer struct {
func NewComposer(
aerc *Aerc, acct *AccountView, acctConfig *config.AccountConfig,
- worker *types.Worker, template string,
+ worker *types.Worker, editHeaders bool, template string,
h *mail.Header, orig *models.OriginalMail, body io.Reader,
) (*Composer, error) {
if h == nil {
@@ -95,6 +96,8 @@ func NewComposer(
// You have to backtab to get to "From", since you usually don't edit it
focused: 1,
completer: nil,
+
+ editHeaders: editHeaders,
}
data := state.NewDataSetter()
@@ -110,7 +113,7 @@ func NewComposer(
return nil, err
}
- if err := c.ShowTerminal(); err != nil {
+ if err := c.ShowTerminal(editHeaders); err != nil {
return nil, err
}
@@ -460,7 +463,7 @@ func (c *Composer) setContents(reader io.Reader) error {
if err != nil {
return err
}
- if config.Compose.EditHeaders {
+ if c.editHeaders {
for _, h := range c.headerOrder() {
var value string
switch h {
@@ -660,7 +663,7 @@ func (c *Composer) GetBody() (*bytes.Buffer, error) {
return nil, err
}
scanner := bufio.NewScanner(c.email)
- if config.Compose.EditHeaders {
+ if c.editHeaders {
// skip headers
for scanner.Scan() {
if scanner.Text() == "" {
@@ -1142,7 +1145,7 @@ func (c *Composer) termClosed(err error) {
return
}
- if config.Compose.EditHeaders {
+ if c.editHeaders {
// parse embedded header when editor is closed
embedHeader, err := c.parseEmbeddedHeader()
if err != nil {
@@ -1172,7 +1175,7 @@ func (c *Composer) termClosed(err error) {
c.updateGrid()
}
-func (c *Composer) ShowTerminal() error {
+func (c *Composer) ShowTerminal(editHeaders bool) error {
c.Lock()
defer c.Unlock()
if c.editor != nil {
@@ -1182,6 +1185,7 @@ func (c *Composer) ShowTerminal() error {
if err != nil {
return err
}
+ c.editHeaders = editHeaders
err = c.setContents(body)
if err != nil {
return err
@@ -1213,7 +1217,7 @@ func (c *Composer) showTerminal() error {
c.focusable = append(c.focusable, c.editor)
c.review = nil
c.updateGrid()
- if config.Compose.EditHeaders {
+ if c.editHeaders {
c.focusTerminalPriv()
}
return nil
@@ -1222,7 +1226,7 @@ func (c *Composer) showTerminal() error {
func (c *Composer) PrevField() {
c.Lock()
defer c.Unlock()
- if config.Compose.EditHeaders && c.editor != nil {
+ if c.editHeaders && c.editor != nil {
return
}
c.focusable[c.focused].Focus(false)
@@ -1236,7 +1240,7 @@ func (c *Composer) PrevField() {
func (c *Composer) NextField() {
c.Lock()
defer c.Unlock()
- if config.Compose.EditHeaders && c.editor != nil {
+ if c.editHeaders && c.editor != nil {
return
}
c.focusable[c.focused].Focus(false)
@@ -1247,7 +1251,7 @@ func (c *Composer) NextField() {
func (c *Composer) FocusEditor(editor string) {
c.Lock()
defer c.Unlock()
- if config.Compose.EditHeaders && c.editor != nil {
+ if c.editHeaders && c.editor != nil {
return
}
c.focusEditor(editor)
@@ -1270,7 +1274,7 @@ func (c *Composer) focusEditor(editor string) {
func (c *Composer) AddEditor(header string, value string, appendHeader bool) error {
c.Lock()
defer c.Unlock()
- if config.Compose.EditHeaders && c.editor != nil {
+ if c.editHeaders && c.editor != nil {
return errors.New("header should be added directly in the text editor")
}
value = c.addEditor(header, value, appendHeader)
@@ -1364,7 +1368,7 @@ func (c *Composer) updateGrid() {
{Strategy: ui.SIZE_WEIGHT, Size: ui.Const(1)},
})
- if config.Compose.EditHeaders && c.review == nil {
+ if c.editHeaders && c.review == nil {
grid.Rows([]ui.GridSpec{
// 0: editor
{Strategy: ui.SIZE_WEIGHT, Size: ui.Const(1)},