diff options
author | Jeffas <dev@jeffas.io> | 2019-09-05 23:32:36 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-09-11 11:41:34 -0400 |
commit | f6216bb6213a15cdcdf50089f3c4a8e9a30d9337 (patch) | |
tree | 3075b68379ae7c13cb9eedc53b7cf033672478a9 /widgets/aerc.go | |
parent | a441e3b3a55d11e7cc9444298051ff339d1b7519 (diff) |
Add Mouseable
This adds the Mouseable interface. When this is implemented for a
component that item can accept and process mouseevents.
At the top level when a mouse event is received it is passed to the
grid's handler and then it trickles down until it reaches a component
that can actually handle it, such as the tablist, dirlist or msglist.
A mouse event is passed so that components can handle other things such
as scrolling with the mousewheel. The components themselves then perform
the necessary actions.
Clicking emails in the messagelist opens them in a new tab.
Textinputs can be clicked to position the cursor inside them.
Mouseevents are not forwarded to the terminal at the moment.
Elements which do not handle mouse events are not required to implement
the Mouseable interface.
Diffstat (limited to 'widgets/aerc.go')
-rw-r--r-- | widgets/aerc.go | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go index 87009cd..fe3c1e2 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -74,7 +74,7 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger, conf.Triggers.ExecuteCommand = cmd for i, acct := range conf.Accounts { - view := NewAccountView(conf, &conf.Accounts[i], logger, aerc) + view := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc) aerc.accounts[acct.Name] = view tabs.Add(view, acct.Name) } @@ -85,6 +85,22 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger, aerc.NewTab(wizard, "New account") } + tabs.CloseTab = func(index int) { + switch content := aerc.tabs.Tabs[index].Content.(type) { + case *AccountView: + return + case *AccountWizard: + return + case *Composer: + aerc.RemoveTab(content) + content.Close() + case *Terminal: + content.Close(nil) + case *MessageViewer: + aerc.RemoveTab(content) + } + } + return aerc } @@ -235,7 +251,12 @@ func (aerc *Aerc) Event(event tcell.Event) bool { return false } case *tcell.EventMouse: - aerc.tabs.MouseEvent(event) + if event.Buttons() == tcell.ButtonNone { + return false + } + x, y := event.Position() + aerc.grid.MouseEvent(x, y, event) + return true } return false } @@ -260,8 +281,8 @@ func (aerc *Aerc) SelectedTab() ui.Drawable { return aerc.tabs.Tabs[aerc.tabs.Selected].Content } -func (aerc *Aerc) NewTab(drawable ui.Drawable, name string) *ui.Tab { - tab := aerc.tabs.Add(drawable, name) +func (aerc *Aerc) NewTab(clickable ui.Drawable, name string) *ui.Tab { + tab := aerc.tabs.Add(clickable, name) aerc.tabs.Select(len(aerc.tabs.Tabs) - 1) return tab } @@ -275,19 +296,11 @@ func (aerc *Aerc) ReplaceTab(tabSrc ui.Drawable, tabTarget ui.Drawable, name str } func (aerc *Aerc) NextTab() { - next := aerc.tabs.Selected + 1 - if next >= len(aerc.tabs.Tabs) { - next = 0 - } - aerc.tabs.Select(next) + aerc.tabs.NextTab() } func (aerc *Aerc) PrevTab() { - next := aerc.tabs.Selected - 1 - if next < 0 { - next = len(aerc.tabs.Tabs) - 1 - } - aerc.tabs.Select(next) + aerc.tabs.PrevTab() } func (aerc *Aerc) SelectTab(name string) bool { |