about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKevin Kuehler <keur@ocf.berkeley.edu>2019-06-01 22:15:04 -0700
committerDrew DeVault <sir@cmpwn.com>2019-06-02 10:16:29 -0400
commit753adb90692e4821f8caea1d5d86cd69e312efa7 (patch)
tree79f7563e0ef68264b12244160b3274b678875624
parent2be985fecb0d76e8fa7cdc46c8de92b6caab9552 (diff)
downloadaerc-753adb90692e4821f8caea1d5d86cd69e312efa7.tar.gz
widget: Add ProvidesMessage interface
Consists of 3 functions
* Store: Access to MessageStore type
* SelectedAccount: Access to Account widget that the target widget
belongs to
* SelectedMessage: Current message (selected in msglist or the one we
are viewing)

Signed-off-by: Kevin Kuehler <keur@ocf.berkeley.edu>
-rw-r--r--aerc.go3
-rw-r--r--commands/account/view.go2
-rw-r--r--commands/msg/copy.go (renamed from commands/account/copy.go)9
-rw-r--r--commands/msg/delete.go (renamed from commands/account/delete.go)14
-rw-r--r--commands/msg/move.go (renamed from commands/account/move.go)13
-rw-r--r--commands/msg/msg.go16
-rw-r--r--commands/msg/reply.go (renamed from commands/account/reply.go)12
-rw-r--r--widgets/account.go12
-rw-r--r--widgets/msgviewer.go16
-rw-r--r--widgets/providesmessage.go14
10 files changed, 93 insertions, 18 deletions
diff --git a/aerc.go b/aerc.go
index 22df069..ffce931 100644
--- a/aerc.go
+++ b/aerc.go
@@ -13,6 +13,7 @@ import (
 	"git.sr.ht/~sircmpwn/aerc/commands"
 	"git.sr.ht/~sircmpwn/aerc/commands/account"
 	"git.sr.ht/~sircmpwn/aerc/commands/compose"
+	"git.sr.ht/~sircmpwn/aerc/commands/msg"
 	"git.sr.ht/~sircmpwn/aerc/commands/msgview"
 	"git.sr.ht/~sircmpwn/aerc/commands/terminal"
 	"git.sr.ht/~sircmpwn/aerc/config"
@@ -25,6 +26,7 @@ func getCommands(selected libui.Drawable) []*commands.Commands {
 	case *widgets.AccountView:
 		return []*commands.Commands{
 			account.AccountCommands,
+			msg.MessageCommands,
 			commands.GlobalCommands,
 		}
 	case *widgets.Composer:
@@ -35,6 +37,7 @@ func getCommands(selected libui.Drawable) []*commands.Commands {
 	case *widgets.MessageViewer:
 		return []*commands.Commands{
 			msgview.MessageViewCommands,
+			msg.MessageCommands,
 			commands.GlobalCommands,
 		}
 	case *widgets.Terminal:
diff --git a/commands/account/view.go b/commands/account/view.go
index 40abec3..f7f3ec6 100644
--- a/commands/account/view.go
+++ b/commands/account/view.go
@@ -24,7 +24,7 @@ func ViewMessage(aerc *widgets.Aerc, args []string) error {
 	if msg == nil {
 		return nil
 	}
-	viewer := widgets.NewMessageViewer(aerc.Config(), store, msg)
+	viewer := widgets.NewMessageViewer(acct, aerc.Config(), store, msg)
 	aerc.NewTab(viewer, msg.Envelope.Subject)
 	return nil
 }
diff --git a/commands/account/copy.go b/commands/msg/copy.go
index da26fec..57c93a3 100644
--- a/commands/account/copy.go
+++ b/commands/msg/copy.go
@@ -1,4 +1,4 @@
-package account
+package msg
 
 import (
 	"errors"
@@ -19,12 +19,13 @@ func Copy(aerc *widgets.Aerc, args []string) error {
 	if len(args) != 2 {
 		return errors.New("Usage: mv <folder>")
 	}
-	acct := aerc.SelectedAccount()
+	widget := aerc.SelectedTab().(widgets.ProvidesMessage)
+	acct := widget.SelectedAccount()
 	if acct == nil {
 		return errors.New("No account selected")
 	}
-	msg := acct.Messages().Selected()
-	store := acct.Messages().Store()
+	msg := widget.SelectedMessage()
+	store := widget.Store()
 	store.Copy([]uint32{msg.Uid}, args[1], func(msg types.WorkerMessage) {
 		switch msg := msg.(type) {
 		case *types.Done:
diff --git a/commands/account/delete.go b/commands/msg/delete.go
index 65d6eb9..082dbe3 100644
--- a/commands/account/delete.go
+++ b/commands/msg/delete.go
@@ -1,4 +1,4 @@
-package account
+package msg
 
 import (
 	"errors"
@@ -19,12 +19,18 @@ func DeleteMessage(aerc *widgets.Aerc, args []string) error {
 	if len(args) != 1 {
 		return errors.New("Usage: :delete")
 	}
-	acct := aerc.SelectedAccount()
+
+	widget := aerc.SelectedTab().(widgets.ProvidesMessage)
+	acct := widget.SelectedAccount()
 	if acct == nil {
 		return errors.New("No account selected")
 	}
-	store := acct.Messages().Store()
-	msg := acct.Messages().Selected()
+	store := widget.Store()
+	msg := widget.SelectedMessage()
+	_, isMsgView := widget.(*widgets.MessageViewer)
+	if isMsgView {
+		aerc.RemoveTab(widget)
+	}
 	acct.Messages().Next()
 	store.Delete([]uint32{msg.Uid}, func(msg types.WorkerMessage) {
 		switch msg := msg.(type) {
diff --git a/commands/account/move.go b/commands/msg/move.go
index d58a279..1224efa 100644
--- a/commands/account/move.go
+++ b/commands/msg/move.go
@@ -1,4 +1,4 @@
-package account
+package msg
 
 import (
 	"errors"
@@ -19,12 +19,17 @@ func Move(aerc *widgets.Aerc, args []string) error {
 	if len(args) != 2 {
 		return errors.New("Usage: mv <folder>")
 	}
-	acct := aerc.SelectedAccount()
+	widget := aerc.SelectedTab().(widgets.ProvidesMessage)
+	acct := widget.SelectedAccount()
 	if acct == nil {
 		return errors.New("No account selected")
 	}
-	msg := acct.Messages().Selected()
-	store := acct.Messages().Store()
+	msg := widget.SelectedMessage()
+	store := widget.Store()
+	_, isMsgView := widget.(*widgets.MessageViewer)
+	if isMsgView {
+		aerc.RemoveTab(widget)
+	}
 	acct.Messages().Next()
 	store.Move([]uint32{msg.Uid}, args[1], func(msg types.WorkerMessage) {
 		switch msg := msg.(type) {
diff --git a/commands/msg/msg.go b/commands/msg/msg.go
new file mode 100644
index 0000000..73755aa
--- /dev/null
+++ b/commands/msg/msg.go
@@ -0,0 +1,16 @@
+package msg
+
+import (
+	"git.sr.ht/~sircmpwn/aerc/commands"
+)
+
+var (
+	MessageCommands *commands.Commands
+)
+
+func register(name string, cmd commands.AercCommand) {
+	if MessageCommands == nil {
+		MessageCommands = commands.NewCommands()
+	}
+	MessageCommands.Register(name, cmd)
+}
diff --git a/commands/account/reply.go b/commands/msg/reply.go
index ecc6239..e09a118 100644
--- a/commands/account/reply.go
+++ b/commands/msg/reply.go
@@ -1,4 +1,4 @@
-package account
+package msg
 
 import (
 	"bufio"
@@ -63,11 +63,15 @@ func Reply(aerc *widgets.Aerc, args []string) error {
 		}
 	}
 
-	acct := aerc.SelectedAccount()
+	widget := aerc.SelectedTab().(widgets.ProvidesMessage)
+	acct := widget.SelectedAccount()
+	if acct == nil {
+		return errors.New("No account selected")
+	}
 	conf := acct.AccountConfig()
 	us, _ := gomail.ParseAddress(conf.From)
-	store := acct.Messages().Store()
-	msg := acct.Messages().Selected()
+	store := widget.Store()
+	msg := widget.SelectedMessage()
 	acct.Logger().Println("Replying to email " + msg.Envelope.MessageId)
 
 	var (
diff --git a/widgets/account.go b/widgets/account.go
index f553a92..4526c02 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -157,6 +157,18 @@ func (acct *AccountView) Messages() *MessageList {
 	return acct.msglist
 }
 
+func (acct *AccountView) Store() *lib.MessageStore {
+	return acct.msglist.Store()
+}
+
+func (acct *AccountView) SelectedMessage() *types.MessageInfo {
+	return acct.msglist.Selected()
+}
+
+func (acct *AccountView) SelectedAccount() *AccountView {
+	return acct
+}
+
 func (acct *AccountView) onMessage(msg types.WorkerMessage) {
 	switch msg := msg.(type) {
 	case *types.Done:
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index cf360bc..9230ba3 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -24,6 +24,7 @@ import (
 
 type MessageViewer struct {
 	ui.Invalidatable
+	acct     *AccountView
 	conf     *config.AercConfig
 	err      error
 	grid     *ui.Grid
@@ -55,7 +56,7 @@ func formatAddresses(addrs []*imap.Address) string {
 	return val.String()
 }
 
-func NewMessageViewer(conf *config.AercConfig,
+func NewMessageViewer(acct *AccountView, conf *config.AercConfig,
 	store *lib.MessageStore, msg *types.MessageInfo) *MessageViewer {
 
 	grid := ui.NewGrid().Rows([]ui.GridSpec{
@@ -124,6 +125,7 @@ func NewMessageViewer(conf *config.AercConfig,
 	grid.AddChild(switcher).At(1, 0)
 
 	return &MessageViewer{
+		acct:     acct,
 		grid:     grid,
 		msg:      msg,
 		store:    store,
@@ -185,6 +187,18 @@ func (mv *MessageViewer) OnInvalidate(fn func(d ui.Drawable)) {
 	})
 }
 
+func (mv *MessageViewer) Store() *lib.MessageStore {
+	return mv.store
+}
+
+func (mv *MessageViewer) SelectedAccount() *AccountView {
+	return mv.acct
+}
+
+func (mv *MessageViewer) SelectedMessage() *types.MessageInfo {
+	return mv.msg
+}
+
 func (mv *MessageViewer) CurrentPart() *PartInfo {
 	switcher := mv.switcher
 	part := switcher.parts[switcher.selected]
diff --git a/widgets/providesmessage.go b/widgets/providesmessage.go
new file mode 100644
index 0000000..341f83f
--- /dev/null
+++ b/widgets/providesmessage.go
@@ -0,0 +1,14 @@
+package widgets
+
+import (
+	"git.sr.ht/~sircmpwn/aerc/worker/types"
+	"git.sr.ht/~sircmpwn/aerc/lib"
+	"git.sr.ht/~sircmpwn/aerc/lib/ui"
+)
+
+type ProvidesMessage interface {
+	ui.Drawable
+	Store()           *lib.MessageStore
+	SelectedMessage() *types.MessageInfo
+	SelectedAccount() *AccountView
+}
t;vc@akkartik.com> 2016-09-17 00:43:20 -0700 3380' href='/akkartik/mu/commit/029tools.cc?h=hlt&id=192d59d3bb9ee0baa1afd82cb5d0f352bdc6e403'>192d59d3 ^
9edabeaa ^



e41e8e09 ^
9edabeaa ^
5f0280a9 ^
e41e8e09 ^
9edabeaa ^
6c96a437 ^
5f0280a9 ^


9edabeaa ^


3a538211 ^
5f98a10c ^
3a538211 ^
795f5244 ^
166e3c0d ^
5f98a10c ^
166e3c0d ^

3a538211 ^
5f98a10c ^

3a538211 ^



5f98a10c ^
3a538211 ^
795f5244 ^
166e3c0d ^
5f98a10c ^
166e3c0d ^

3a538211 ^
5f98a10c ^

3a538211 ^



e00d4854 ^
3a538211 ^
795f5244 ^
166e3c0d ^
e00d4854 ^
166e3c0d ^

3a538211 ^
e00d4854 ^
3a538211 ^
e00d4854 ^
3a538211 ^






795f5244 ^
166e3c0d ^



3a538211 ^













795f5244 ^
166e3c0d ^



3a538211 ^

77cdc6d0 ^
3a538211 ^


61286c8d ^


795f5244 ^
61286c8d ^





f28f2636 ^

61286c8d ^





3a538211 ^




795f5244 ^
166e3c0d ^



3a538211 ^

6c96a437 ^
3a538211 ^
cdd6fd09 ^
cf3ac87f ^
3a538211 ^
cf3ac87f ^





3a538211 ^
17401c38 ^
3a538211 ^
6c96a437 ^
cdd6fd09 ^
3a538211 ^
4082acd2 ^
3a538211 ^


c55e49b6 ^
3a538211 ^





795f5244 ^
166e3c0d ^



3a538211 ^








795f5244 ^
5fdd8e96 ^
3a538211 ^
5f98a10c ^
9dcbec39 ^
3a538211 ^

78c50205 ^
9dcbec39 ^
ac8acc7b ^
5fdd8e96 ^



aa088845 ^
cfb142b9 ^
3a538211 ^



3a538211 ^


795f5244 ^
166e3c0d ^



3a538211 ^




601ff75b ^



















6c96a437 ^
e41e8e09 ^
601ff75b ^
07a64183 ^
601ff75b ^

0ce24b26 ^
9a81d746 ^
0ce24b26 ^















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320