summary refs log tree commit diff stats
path: root/widgets/directories.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-01-13 14:32:22 -0500
committerDrew DeVault <sir@cmpwn.com>2019-01-13 14:32:22 -0500
commit755aa9af731c6faac64cbe3ad77324fb2850a7ae (patch)
treebf46de891839f66f262ba7d977c22488eaf756f7 /widgets/directories.go
parent2349b7de869e5abc16a419a073273af99b62aad2 (diff)
downloadaerc-755aa9af731c6faac64cbe3ad77324fb2850a7ae.tar.gz
Filter dirlist according to user config
Diffstat (limited to 'widgets/directories.go')
-rw-r--r--widgets/directories.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/widgets/directories.go b/widgets/directories.go
index a9ea7d4..16b0e5a 100644
--- a/widgets/directories.go
+++ b/widgets/directories.go
@@ -6,19 +6,23 @@ import (
 
 	"github.com/gdamore/tcell"
 
+	"git.sr.ht/~sircmpwn/aerc2/config"
 	"git.sr.ht/~sircmpwn/aerc2/lib/ui"
 	"git.sr.ht/~sircmpwn/aerc2/worker/types"
 )
 
 type DirectoryList struct {
+	conf         *config.AccountConfig
 	dirs         []string
 	logger       *log.Logger
 	onInvalidate func(d ui.Drawable)
 	worker       *types.Worker
 }
 
-func NewDirectoryList(logger *log.Logger, worker *types.Worker) *DirectoryList {
-	return &DirectoryList{logger: logger, worker: worker}
+func NewDirectoryList(conf *config.AccountConfig,
+	logger *log.Logger, worker *types.Worker) *DirectoryList {
+
+	return &DirectoryList{conf: conf, logger: logger, worker: worker}
 }
 
 func (dirlist *DirectoryList) UpdateList() {
@@ -49,10 +53,19 @@ func (dirlist *DirectoryList) Invalidate() {
 
 func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
 	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
-	for i, name := range dirlist.dirs {
-		if i >= ctx.Height() {
+	row := 0
+	for _, name := range dirlist.dirs {
+		if row >= ctx.Height() {
 			break
 		}
-		ctx.Printf(0, i, tcell.StyleDefault, "%s", name)
+		if len(dirlist.conf.Folders) > 1 {
+			idx := sort.SearchStrings(dirlist.conf.Folders, name)
+			if idx == len(dirlist.conf.Folders) ||
+				dirlist.conf.Folders[idx] != name {
+				continue
+			}
+		}
+		ctx.Printf(0, row, tcell.StyleDefault, "%s", name)
+		row++
 	}
 }