about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-01-26 12:43:46 +0100
committerDrew DeVault <sir@cmpwn.com>2020-01-28 10:36:01 -0500
commitea0df7bee433fedae5716906ea56141f92b9ce53 (patch)
treee4cee0f53401d0774758437bf4052973bd091e1f
parent2a3d120d6f138918ba8e62f04db78c327cb3ec18 (diff)
downloadaerc-ea0df7bee433fedae5716906ea56141f92b9ce53.tar.gz
dirlist: adapt to dynamic UIconfig
-rw-r--r--widgets/account.go2
-rw-r--r--widgets/dirlist.go30
2 files changed, 21 insertions, 11 deletions
diff --git a/widgets/account.go b/widgets/account.go
index 455c28e..f8b6581 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -65,7 +65,7 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
 		}
 	}
 
-	dirlist := NewDirectoryList(acct, &acctUiConf, logger, worker)
+	dirlist := NewDirectoryList(conf, acct, logger, worker)
 	if acctUiConf.SidebarWidth > 0 {
 		grid.AddChild(ui.NewBordered(dirlist, ui.BORDER_RIGHT))
 	}
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index edc84c6..5cdbe06 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -18,8 +18,8 @@ import (
 
 type DirectoryList struct {
 	ui.Invalidatable
+	aercConf  *config.AercConfig
 	acctConf  *config.AccountConfig
-	uiConf    *config.UIConfig
 	store     *lib.DirStore
 	dirs      []string
 	logger    *log.Logger
@@ -29,17 +29,18 @@ type DirectoryList struct {
 	worker    *types.Worker
 }
 
-func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
+func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
 	logger *log.Logger, worker *types.Worker) *DirectoryList {
 
 	dirlist := &DirectoryList{
+		aercConf: conf,
 		acctConf: acctConf,
-		uiConf:   uiConf,
 		logger:   logger,
-		spinner:  NewSpinner(uiConf),
 		store:    lib.NewDirStore(),
 		worker:   worker,
 	}
+	uiConf := dirlist.UiConfig()
+	dirlist.spinner = NewSpinner(&uiConf)
 	dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
 		dirlist.Invalidate()
 	})
@@ -47,6 +48,13 @@ func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
 	return dirlist
 }
 
+func (dirlist *DirectoryList) UiConfig() config.UIConfig {
+	return dirlist.aercConf.GetUiConfig(map[config.ContextType]string{
+		config.UI_CONTEXT_ACCOUNT: dirlist.acctConf.Name,
+		config.UI_CONTEXT_FOLDER:  dirlist.Selected(),
+	})
+}
+
 func (dirlist *DirectoryList) List() []string {
 	return dirlist.store.List()
 }
@@ -118,7 +126,7 @@ func (dirlist *DirectoryList) getDirString(name string, width int, recentUnseen
 		formatted = runewidth.FillRight(formatted, width-len(s))
 		formatted = runewidth.Truncate(formatted, width-len(s), "…")
 	}
-	for _, char := range dirlist.uiConf.DirListFormat {
+	for _, char := range dirlist.UiConfig().DirListFormat {
 		switch char {
 		case '%':
 			if percent {
@@ -206,7 +214,7 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
 
 	if len(dirlist.dirs) == 0 {
 		style := tcell.StyleDefault
-		ctx.Printf(0, 0, style, dirlist.uiConf.EmptyDirlist)
+		ctx.Printf(0, 0, style, dirlist.UiConfig().EmptyDirlist)
 		return
 	}
 
@@ -304,8 +312,9 @@ func folderMatches(folder string, pattern string) bool {
 // will be appended at the end in alphabetical order
 func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
 	sort.Slice(dirlist.dirs, func(i, j int) bool {
-		iInFoldersSort := findString(dirlist.acctConf.FoldersSort, dirlist.dirs[i])
-		jInFoldersSort := findString(dirlist.acctConf.FoldersSort, dirlist.dirs[j])
+		foldersSort := dirlist.acctConf.FoldersSort
+		iInFoldersSort := findString(foldersSort, dirlist.dirs[i])
+		jInFoldersSort := findString(foldersSort, dirlist.dirs[j])
 		if iInFoldersSort >= 0 && jInFoldersSort >= 0 {
 			return iInFoldersSort < jInFoldersSort
 		}
@@ -324,12 +333,13 @@ func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
 func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
 	dirlist.dirs = dirlist.store.List()
 	// config option defaults to show all if unset
-	if len(dirlist.acctConf.Folders) == 0 {
+	configFolders := dirlist.acctConf.Folders
+	if len(configFolders) == 0 {
 		return
 	}
 	var filtered []string
 	for _, folder := range dirlist.dirs {
-		for _, cfgfolder := range dirlist.acctConf.Folders {
+		for _, cfgfolder := range configFolders {
 			if folderMatches(folder, cfgfolder) {
 				filtered = append(filtered, folder)
 				break
NG?h=v1.7.0&id=4ea0f69aed8d4c173d9abbd0a1bd76d6afe69ccb'>^
f8f6f7f9 ^
176e8a68 ^
f8f6f7f9 ^





f8f6f7f9 ^




7bf5f967 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79