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>
This commit is contained in:
parent
2be985fecb
commit
753adb9069
10 changed files with 93 additions and 18 deletions
3
aerc.go
3
aerc.go
|
@ -13,6 +13,7 @@ import (
|
||||||
"git.sr.ht/~sircmpwn/aerc/commands"
|
"git.sr.ht/~sircmpwn/aerc/commands"
|
||||||
"git.sr.ht/~sircmpwn/aerc/commands/account"
|
"git.sr.ht/~sircmpwn/aerc/commands/account"
|
||||||
"git.sr.ht/~sircmpwn/aerc/commands/compose"
|
"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/msgview"
|
||||||
"git.sr.ht/~sircmpwn/aerc/commands/terminal"
|
"git.sr.ht/~sircmpwn/aerc/commands/terminal"
|
||||||
"git.sr.ht/~sircmpwn/aerc/config"
|
"git.sr.ht/~sircmpwn/aerc/config"
|
||||||
|
@ -25,6 +26,7 @@ func getCommands(selected libui.Drawable) []*commands.Commands {
|
||||||
case *widgets.AccountView:
|
case *widgets.AccountView:
|
||||||
return []*commands.Commands{
|
return []*commands.Commands{
|
||||||
account.AccountCommands,
|
account.AccountCommands,
|
||||||
|
msg.MessageCommands,
|
||||||
commands.GlobalCommands,
|
commands.GlobalCommands,
|
||||||
}
|
}
|
||||||
case *widgets.Composer:
|
case *widgets.Composer:
|
||||||
|
@ -35,6 +37,7 @@ func getCommands(selected libui.Drawable) []*commands.Commands {
|
||||||
case *widgets.MessageViewer:
|
case *widgets.MessageViewer:
|
||||||
return []*commands.Commands{
|
return []*commands.Commands{
|
||||||
msgview.MessageViewCommands,
|
msgview.MessageViewCommands,
|
||||||
|
msg.MessageCommands,
|
||||||
commands.GlobalCommands,
|
commands.GlobalCommands,
|
||||||
}
|
}
|
||||||
case *widgets.Terminal:
|
case *widgets.Terminal:
|
||||||
|
|
|
@ -24,7 +24,7 @@ func ViewMessage(aerc *widgets.Aerc, args []string) error {
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
viewer := widgets.NewMessageViewer(aerc.Config(), store, msg)
|
viewer := widgets.NewMessageViewer(acct, aerc.Config(), store, msg)
|
||||||
aerc.NewTab(viewer, msg.Envelope.Subject)
|
aerc.NewTab(viewer, msg.Envelope.Subject)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package account
|
package msg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -19,12 +19,13 @@ func Copy(aerc *widgets.Aerc, args []string) error {
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return errors.New("Usage: mv <folder>")
|
return errors.New("Usage: mv <folder>")
|
||||||
}
|
}
|
||||||
acct := aerc.SelectedAccount()
|
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
|
||||||
|
acct := widget.SelectedAccount()
|
||||||
if acct == nil {
|
if acct == nil {
|
||||||
return errors.New("No account selected")
|
return errors.New("No account selected")
|
||||||
}
|
}
|
||||||
msg := acct.Messages().Selected()
|
msg := widget.SelectedMessage()
|
||||||
store := acct.Messages().Store()
|
store := widget.Store()
|
||||||
store.Copy([]uint32{msg.Uid}, args[1], func(msg types.WorkerMessage) {
|
store.Copy([]uint32{msg.Uid}, args[1], func(msg types.WorkerMessage) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *types.Done:
|
case *types.Done:
|
|
@ -1,4 +1,4 @@
|
||||||
package account
|
package msg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -19,12 +19,18 @@ func DeleteMessage(aerc *widgets.Aerc, args []string) error {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return errors.New("Usage: :delete")
|
return errors.New("Usage: :delete")
|
||||||
}
|
}
|
||||||
acct := aerc.SelectedAccount()
|
|
||||||
|
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
|
||||||
|
acct := widget.SelectedAccount()
|
||||||
if acct == nil {
|
if acct == nil {
|
||||||
return errors.New("No account selected")
|
return errors.New("No account selected")
|
||||||
}
|
}
|
||||||
store := acct.Messages().Store()
|
store := widget.Store()
|
||||||
msg := acct.Messages().Selected()
|
msg := widget.SelectedMessage()
|
||||||
|
_, isMsgView := widget.(*widgets.MessageViewer)
|
||||||
|
if isMsgView {
|
||||||
|
aerc.RemoveTab(widget)
|
||||||
|
}
|
||||||
acct.Messages().Next()
|
acct.Messages().Next()
|
||||||
store.Delete([]uint32{msg.Uid}, func(msg types.WorkerMessage) {
|
store.Delete([]uint32{msg.Uid}, func(msg types.WorkerMessage) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
|
@ -1,4 +1,4 @@
|
||||||
package account
|
package msg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -19,12 +19,17 @@ func Move(aerc *widgets.Aerc, args []string) error {
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return errors.New("Usage: mv <folder>")
|
return errors.New("Usage: mv <folder>")
|
||||||
}
|
}
|
||||||
acct := aerc.SelectedAccount()
|
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
|
||||||
|
acct := widget.SelectedAccount()
|
||||||
if acct == nil {
|
if acct == nil {
|
||||||
return errors.New("No account selected")
|
return errors.New("No account selected")
|
||||||
}
|
}
|
||||||
msg := acct.Messages().Selected()
|
msg := widget.SelectedMessage()
|
||||||
store := acct.Messages().Store()
|
store := widget.Store()
|
||||||
|
_, isMsgView := widget.(*widgets.MessageViewer)
|
||||||
|
if isMsgView {
|
||||||
|
aerc.RemoveTab(widget)
|
||||||
|
}
|
||||||
acct.Messages().Next()
|
acct.Messages().Next()
|
||||||
store.Move([]uint32{msg.Uid}, args[1], func(msg types.WorkerMessage) {
|
store.Move([]uint32{msg.Uid}, args[1], func(msg types.WorkerMessage) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
16
commands/msg/msg.go
Normal file
16
commands/msg/msg.go
Normal file
|
@ -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)
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package account
|
package msg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"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()
|
conf := acct.AccountConfig()
|
||||||
us, _ := gomail.ParseAddress(conf.From)
|
us, _ := gomail.ParseAddress(conf.From)
|
||||||
store := acct.Messages().Store()
|
store := widget.Store()
|
||||||
msg := acct.Messages().Selected()
|
msg := widget.SelectedMessage()
|
||||||
acct.Logger().Println("Replying to email " + msg.Envelope.MessageId)
|
acct.Logger().Println("Replying to email " + msg.Envelope.MessageId)
|
||||||
|
|
||||||
var (
|
var (
|
|
@ -157,6 +157,18 @@ func (acct *AccountView) Messages() *MessageList {
|
||||||
return acct.msglist
|
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) {
|
func (acct *AccountView) onMessage(msg types.WorkerMessage) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *types.Done:
|
case *types.Done:
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
|
|
||||||
type MessageViewer struct {
|
type MessageViewer struct {
|
||||||
ui.Invalidatable
|
ui.Invalidatable
|
||||||
|
acct *AccountView
|
||||||
conf *config.AercConfig
|
conf *config.AercConfig
|
||||||
err error
|
err error
|
||||||
grid *ui.Grid
|
grid *ui.Grid
|
||||||
|
@ -55,7 +56,7 @@ func formatAddresses(addrs []*imap.Address) string {
|
||||||
return val.String()
|
return val.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMessageViewer(conf *config.AercConfig,
|
func NewMessageViewer(acct *AccountView, conf *config.AercConfig,
|
||||||
store *lib.MessageStore, msg *types.MessageInfo) *MessageViewer {
|
store *lib.MessageStore, msg *types.MessageInfo) *MessageViewer {
|
||||||
|
|
||||||
grid := ui.NewGrid().Rows([]ui.GridSpec{
|
grid := ui.NewGrid().Rows([]ui.GridSpec{
|
||||||
|
@ -124,6 +125,7 @@ func NewMessageViewer(conf *config.AercConfig,
|
||||||
grid.AddChild(switcher).At(1, 0)
|
grid.AddChild(switcher).At(1, 0)
|
||||||
|
|
||||||
return &MessageViewer{
|
return &MessageViewer{
|
||||||
|
acct: acct,
|
||||||
grid: grid,
|
grid: grid,
|
||||||
msg: msg,
|
msg: msg,
|
||||||
store: store,
|
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 {
|
func (mv *MessageViewer) CurrentPart() *PartInfo {
|
||||||
switcher := mv.switcher
|
switcher := mv.switcher
|
||||||
part := switcher.parts[switcher.selected]
|
part := switcher.parts[switcher.selected]
|
||||||
|
|
14
widgets/providesmessage.go
Normal file
14
widgets/providesmessage.go
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Reference in a new issue