2018-02-28 03:17:26 +01:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2018-06-01 09:58:00 +02:00
|
|
|
"github.com/gdamore/tcell"
|
2018-02-28 03:17:26 +01:00
|
|
|
|
2019-01-13 18:39:06 +01:00
|
|
|
"git.sr.ht/~sircmpwn/aerc2/config"
|
2019-02-10 22:46:13 +01:00
|
|
|
"git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
2018-02-28 03:17:26 +01:00
|
|
|
libui "git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Aerc struct {
|
2019-01-13 19:33:43 +01:00
|
|
|
accounts map[string]*AccountView
|
2019-03-11 02:15:24 +01:00
|
|
|
cmd func(cmd string) error
|
2019-01-13 19:33:43 +01:00
|
|
|
grid *libui.Grid
|
|
|
|
tabs *libui.Tabs
|
2018-02-28 03:17:26 +01:00
|
|
|
}
|
|
|
|
|
2019-03-11 02:15:24 +01:00
|
|
|
func NewAerc(conf *config.AercConfig, logger *log.Logger,
|
|
|
|
cmd func(cmd string) error) *Aerc {
|
|
|
|
|
2018-02-28 03:17:26 +01:00
|
|
|
tabs := libui.NewTabs()
|
|
|
|
|
2018-06-12 01:23:09 +02:00
|
|
|
mainGrid := libui.NewGrid().Rows([]libui.GridSpec{
|
2018-06-12 15:50:46 +02:00
|
|
|
{libui.SIZE_EXACT, 1},
|
|
|
|
{libui.SIZE_WEIGHT, 1},
|
2018-02-28 03:17:26 +01:00
|
|
|
}).Columns([]libui.GridSpec{
|
2019-03-16 01:40:28 +01:00
|
|
|
{libui.SIZE_EXACT, conf.Ui.SidebarWidth},
|
2018-06-12 15:50:46 +02:00
|
|
|
{libui.SIZE_WEIGHT, 1},
|
2018-02-28 03:17:26 +01:00
|
|
|
})
|
|
|
|
|
2018-06-12 01:23:09 +02:00
|
|
|
mainGrid.AddChild(libui.NewText("aerc").
|
2018-02-28 03:17:26 +01:00
|
|
|
Strategy(libui.TEXT_CENTER).
|
2018-06-01 09:58:00 +02:00
|
|
|
Color(tcell.ColorBlack, tcell.ColorWhite))
|
2018-06-12 01:23:09 +02:00
|
|
|
mainGrid.AddChild(tabs.TabStrip).At(0, 1)
|
|
|
|
mainGrid.AddChild(tabs.TabContent).At(1, 0).Span(1, 2)
|
2018-02-28 03:17:26 +01:00
|
|
|
|
2019-01-14 14:14:03 +01:00
|
|
|
aerc := &Aerc{
|
|
|
|
accounts: make(map[string]*AccountView),
|
2019-03-11 02:15:24 +01:00
|
|
|
cmd: cmd,
|
2019-01-14 14:14:03 +01:00
|
|
|
grid: mainGrid,
|
|
|
|
tabs: tabs,
|
|
|
|
}
|
2019-01-13 19:25:56 +01:00
|
|
|
|
2019-01-13 18:39:06 +01:00
|
|
|
for _, acct := range conf.Accounts {
|
2019-03-15 06:46:14 +01:00
|
|
|
view := NewAccountView(conf, &acct, logger, cmd)
|
2019-01-14 14:14:03 +01:00
|
|
|
aerc.accounts[acct.Name] = view
|
2019-01-13 19:03:28 +01:00
|
|
|
tabs.Add(view, acct.Name)
|
2018-06-12 01:23:09 +02:00
|
|
|
}
|
2018-02-28 03:17:26 +01:00
|
|
|
|
2019-01-14 14:14:03 +01:00
|
|
|
return aerc
|
2018-02-28 03:17:26 +01:00
|
|
|
}
|
|
|
|
|
2019-02-10 22:46:13 +01:00
|
|
|
func (aerc *Aerc) Children() []ui.Drawable {
|
2019-01-20 21:08:30 +01:00
|
|
|
return aerc.grid.Children()
|
|
|
|
}
|
|
|
|
|
2018-02-28 03:17:26 +01:00
|
|
|
func (aerc *Aerc) OnInvalidate(onInvalidate func(d libui.Drawable)) {
|
2019-01-13 19:25:56 +01:00
|
|
|
aerc.grid.OnInvalidate(func(_ libui.Drawable) {
|
|
|
|
onInvalidate(aerc)
|
|
|
|
})
|
2018-02-28 03:17:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (aerc *Aerc) Invalidate() {
|
|
|
|
aerc.grid.Invalidate()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (aerc *Aerc) Draw(ctx *libui.Context) {
|
|
|
|
aerc.grid.Draw(ctx)
|
|
|
|
}
|
|
|
|
|
2018-06-01 09:58:00 +02:00
|
|
|
func (aerc *Aerc) Event(event tcell.Event) bool {
|
2019-01-13 19:33:43 +01:00
|
|
|
acct, _ := aerc.tabs.Tabs[aerc.tabs.Selected].Content.(*AccountView)
|
|
|
|
return acct.Event(event)
|
2018-02-28 03:17:26 +01:00
|
|
|
}
|
2019-01-14 14:14:03 +01:00
|
|
|
|
2019-03-11 02:15:24 +01:00
|
|
|
func (aerc *Aerc) SelectedAccount() *AccountView {
|
|
|
|
return aerc.accounts[aerc.tabs.Tabs[aerc.tabs.Selected].Name]
|
2019-01-14 14:14:03 +01:00
|
|
|
}
|