mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-03 00:57:52 +02:00
make it easier to add a tab to a view
This commit is contained in:
@ -664,6 +664,10 @@ func (gui *Gui) changeMainViewsContext(contextKey string) {
|
|||||||
func (gui *Gui) viewTabNames(viewName string) []string {
|
func (gui *Gui) viewTabNames(viewName string) []string {
|
||||||
tabContexts := gui.ViewTabContextMap[viewName]
|
tabContexts := gui.ViewTabContextMap[viewName]
|
||||||
|
|
||||||
|
if len(tabContexts) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
result := make([]string, len(tabContexts))
|
result := make([]string, len(tabContexts))
|
||||||
for i, tabContext := range tabContexts {
|
for i, tabContext := range tabContexts {
|
||||||
result[i] = tabContext.tab
|
result[i] = tabContext.tab
|
||||||
|
@ -1574,13 +1574,10 @@ func (gui *Gui) keybindings() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tabClickBindings := map[string]func(int) error{
|
for viewName := range gui.viewTabContextMap() {
|
||||||
"branches": func(tabIndex int) error { return gui.onViewTabClick("branches", tabIndex) },
|
tabClickCallback := func(tabIndex int) error { return gui.onViewTabClick(viewName, tabIndex) }
|
||||||
"commits": func(tabIndex int) error { return gui.onViewTabClick("commits", tabIndex) },
|
|
||||||
}
|
|
||||||
|
|
||||||
for viewName, binding := range tabClickBindings {
|
if err := gui.g.SetTabClickBinding(viewName, tabClickCallback); err != nil {
|
||||||
if err := gui.g.SetTabClickBinding(viewName, binding); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,6 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
|
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
|
||||||
branchesView.Tabs = gui.viewTabNames("branches")
|
|
||||||
branchesView.FgColor = textColor
|
branchesView.FgColor = textColor
|
||||||
branchesView.ContainsList = true
|
branchesView.ContainsList = true
|
||||||
}
|
}
|
||||||
@ -168,7 +167,6 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
|
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
|
||||||
commitsView.Tabs = gui.viewTabNames("commits")
|
|
||||||
commitsView.FgColor = textColor
|
commitsView.FgColor = textColor
|
||||||
commitsView.ContainsList = true
|
commitsView.ContainsList = true
|
||||||
}
|
}
|
||||||
@ -336,6 +334,15 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
func (gui *Gui) onInitialViewsCreation() error {
|
func (gui *Gui) onInitialViewsCreation() error {
|
||||||
gui.setInitialViewContexts()
|
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 {
|
if err := gui.switchContext(gui.defaultSideContext()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user