Simplify approach to directory list
This doesn't really need to be abstract tbh
This commit is contained in:
parent
257affcd48
commit
cf66462000
|
@ -122,13 +122,25 @@ func (acct *AccountView) Event(event tcell.Event) bool {
|
||||||
func (acct *AccountView) connected(msg types.WorkerMessage) {
|
func (acct *AccountView) connected(msg types.WorkerMessage) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *types.Done:
|
case *types.Done:
|
||||||
acct.statusline.Set("Connected.")
|
acct.statusline.Set("Listing mailboxes...")
|
||||||
acct.logger.Println("Connected.")
|
acct.logger.Println("Listing mailboxes...")
|
||||||
acct.dirlist.UpdateList()
|
acct.dirlist.UpdateList(func(dirs []string) {
|
||||||
|
var dir string
|
||||||
|
for _, _dir := range dirs {
|
||||||
|
if _dir == "INBOX" {
|
||||||
|
dir = _dir
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if dir == "" {
|
||||||
|
dir = dirs[0]
|
||||||
|
}
|
||||||
|
acct.dirlist.Select(dir)
|
||||||
|
acct.logger.Println("Connected.")
|
||||||
|
acct.statusline.Set("Connected.")
|
||||||
|
})
|
||||||
case *types.CertificateApprovalRequest:
|
case *types.CertificateApprovalRequest:
|
||||||
// TODO: Ask the user
|
// TODO: Ask the user
|
||||||
acct.logger.Println("Approved unknown certificate.")
|
|
||||||
acct.statusline.Push("Approved unknown certificate.", 5*time.Second)
|
|
||||||
acct.worker.PostAction(&types.ApproveCertificate{
|
acct.worker.PostAction(&types.ApproveCertificate{
|
||||||
Message: types.RespondTo(msg),
|
Message: types.RespondTo(msg),
|
||||||
Approved: true,
|
Approved: true,
|
||||||
|
|
|
@ -16,6 +16,7 @@ type DirectoryList struct {
|
||||||
dirs []string
|
dirs []string
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
onInvalidate func(d ui.Drawable)
|
onInvalidate func(d ui.Drawable)
|
||||||
|
selected string
|
||||||
worker *types.Worker
|
worker *types.Worker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ func NewDirectoryList(conf *config.AccountConfig,
|
||||||
return &DirectoryList{conf: conf, logger: logger, worker: worker}
|
return &DirectoryList{conf: conf, logger: logger, worker: worker}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dirlist *DirectoryList) UpdateList() {
|
func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
|
||||||
var dirs []string
|
var dirs []string
|
||||||
dirlist.worker.PostAction(
|
dirlist.worker.PostAction(
|
||||||
&types.ListDirectories{}, func(msg types.WorkerMessage) {
|
&types.ListDirectories{}, func(msg types.WorkerMessage) {
|
||||||
|
@ -37,10 +38,18 @@ func (dirlist *DirectoryList) UpdateList() {
|
||||||
sort.Strings(dirs)
|
sort.Strings(dirs)
|
||||||
dirlist.dirs = dirs
|
dirlist.dirs = dirs
|
||||||
dirlist.Invalidate()
|
dirlist.Invalidate()
|
||||||
|
if done != nil {
|
||||||
|
done(dirs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dirlist *DirectoryList) Select(name string) {
|
||||||
|
dirlist.selected = name
|
||||||
|
dirlist.Invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
func (dirlist *DirectoryList) OnInvalidate(onInvalidate func(d ui.Drawable)) {
|
func (dirlist *DirectoryList) OnInvalidate(onInvalidate func(d ui.Drawable)) {
|
||||||
dirlist.onInvalidate = onInvalidate
|
dirlist.onInvalidate = onInvalidate
|
||||||
}
|
}
|
||||||
|
@ -58,14 +67,20 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
|
||||||
if row >= ctx.Height() {
|
if row >= ctx.Height() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if len(dirlist.conf.Folders) > 1 {
|
if len(dirlist.conf.Folders) > 1 && name != dirlist.selected {
|
||||||
idx := sort.SearchStrings(dirlist.conf.Folders, name)
|
idx := sort.SearchStrings(dirlist.conf.Folders, name)
|
||||||
if idx == len(dirlist.conf.Folders) ||
|
if idx == len(dirlist.conf.Folders) ||
|
||||||
dirlist.conf.Folders[idx] != name {
|
dirlist.conf.Folders[idx] != name {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.Printf(0, row, tcell.StyleDefault, "%s", name)
|
style := tcell.StyleDefault
|
||||||
|
if name == dirlist.selected {
|
||||||
|
style = style.Background(tcell.ColorWhite).
|
||||||
|
Foreground(tcell.ColorBlack)
|
||||||
|
}
|
||||||
|
ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
|
||||||
|
ctx.Printf(0, row, style, "%s", name)
|
||||||
row++
|
row++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue