summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-09-30 08:27:12 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-10-02 08:09:42 +1000
commit3b93b5dde410fbed657f04c16d6b89c80c5be861 (patch)
tree8e2ba0a5e124f2131d0b385566777b2b42dccf71 /pkg/gui
parent7ddb916a18ddb5c12a7d6f10b13bb470bf3c1724 (diff)
make it easier to add a tab to a view
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/context.go4
-rw-r--r--pkg/gui/keybindings.go9
-rw-r--r--pkg/gui/layout.go11
3 files changed, 16 insertions, 8 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index 91d1d8738..585838505 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -664,6 +664,10 @@ func (gui *Gui) changeMainViewsContext(contextKey string) {
func (gui *Gui) viewTabNames(viewName string) []string {
tabContexts := gui.ViewTabContextMap[viewName]
+ if len(tabContexts) == 0 {
+ return nil
+ }
+
result := make([]string, len(tabContexts))
for i, tabContext := range tabContexts {
result[i] = tabContext.tab
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 9ef0019b2..5abe3d989 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -1574,13 +1574,10 @@ func (gui *Gui) keybindings() error {
}
}
- tabClickBindings := map[string]func(int) error{
- "branches": func(tabIndex int) error { return gui.onViewTabClick("branches", tabIndex) },
- "commits": func(tabIndex int) error { return gui.onViewTabClick("commits", tabIndex) },
- }
+ for viewName := range gui.viewTabContextMap() {
+ tabClickCallback := func(tabIndex int) error { return gui.onViewTabClick(viewName, tabIndex) }
- for viewName, binding := range tabClickBindings {
- if err := gui.g.SetTabClickBinding(viewName, binding); err != nil {
+ if err := gui.g.SetTabClickBinding(viewName, tabClickCallback); err != nil {
return err
}
}
diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go
index a52f95ba5..2aa01c6a7 100644
--- a/pkg/gui/layout.go
+++ b/pkg/gui/layout.go
@@ -147,7 +147,6 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return err
}
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
- branchesView.Tabs = gui.viewTabNames("branches")
branchesView.FgColor = textColor
branchesView.ContainsList = true
}
@@ -168,7 +167,6 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return err
}
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
- commitsView.Tabs = gui.viewTabNames("commits")
commitsView.FgColor = textColor
commitsView.ContainsList = true
}
@@ -336,6 +334,15 @@ func (gui *Gui) layout(g *gocui.Gui) error {
func (gui *Gui) onInitialViewsCreation() error {
gui.setInitialViewContexts()
+ // add tabs to views
+ for _, view := range gui.g.Views() {
+ tabs := gui.viewTabNames(view.Name())
+ if len(tabs) == 0 {
+ continue
+ }
+ view.Tabs = tabs
+ }
+
if err := gui.switchContext(gui.defaultSideContext()); err != nil {
return err
}