1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-31 23:19:40 +02:00

centralise setting of main views context

This commit is contained in:
Jesse Duffield 2020-08-19 08:04:39 +10:00
parent 2488e0044d
commit f0c3d3fc4d
5 changed files with 8 additions and 6 deletions

View File

@ -209,7 +209,6 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error {
} }
} }
gui.changeMainViewsContext("patch-building") // TODO: bring into context code
if err := gui.switchContext(gui.Contexts.PatchBuilding.Context); err != nil { if err := gui.switchContext(gui.Contexts.PatchBuilding.Context); err != nil {
return err return err
} }

View File

@ -1,6 +1,8 @@
package gui package gui
import ( import (
"fmt"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
) )
@ -104,6 +106,10 @@ func (gui *Gui) switchContext(c Context) error {
gui.State.ContextStack = append(gui.State.ContextStack, c) gui.State.ContextStack = append(gui.State.ContextStack, c)
} }
if c.GetViewName() == "main" {
gui.changeMainViewsContext(c.GetKey())
}
return gui.activateContext(c) return gui.activateContext(c)
}) })
@ -422,6 +428,8 @@ func (gui *Gui) changeMainViewsContext(context string) {
case "normal", "patch-building", "staging", "merging": case "normal", "patch-building", "staging", "merging":
gui.getMainView().Context = context gui.getMainView().Context = context
gui.getSecondaryView().Context = context gui.getSecondaryView().Context = context
default:
panic(fmt.Sprintf("unknown context for main: %s", context))
} }
gui.State.MainContext = context gui.State.MainContext = context

View File

@ -165,7 +165,6 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error
if file.HasMergeConflicts { if file.HasMergeConflicts {
return gui.createErrorPanel(gui.Tr.SLocalize("FileStagingRequirements")) return gui.createErrorPanel(gui.Tr.SLocalize("FileStagingRequirements"))
} }
gui.changeMainViewsContext("staging") // TODO: move into context code
gui.switchContext(gui.Contexts.Staging.Context) gui.switchContext(gui.Contexts.Staging.Context)
return gui.refreshStagingPanel(forceSecondaryFocused, selectedLineIdx) // TODO: check if this is broken, try moving into context code return gui.refreshStagingPanel(forceSecondaryFocused, selectedLineIdx) // TODO: check if this is broken, try moving into context code
@ -577,7 +576,6 @@ func (gui *Gui) handleSwitchToMerge() error {
if !file.HasInlineMergeConflicts { if !file.HasInlineMergeConflicts {
return gui.createErrorPanel(gui.Tr.SLocalize("FileNoMergeCons")) return gui.createErrorPanel(gui.Tr.SLocalize("FileNoMergeCons"))
} }
gui.changeMainViewsContext("merging") // TODO: move into context code
return gui.switchContext(gui.Contexts.Merging.Context) return gui.switchContext(gui.Contexts.Merging.Context)
} }

View File

@ -343,8 +343,6 @@ func (gui *Gui) onInitialViewsCreation() error {
return err return err
} }
gui.changeMainViewsContext("normal")
if gui.showRecentRepos { if gui.showRecentRepos {
if err := gui.handleCreateRecentReposMenu(); err != nil { if err := gui.handleCreateRecentReposMenu(); err != nil {
return err return err

View File

@ -325,7 +325,6 @@ func (gui *Gui) handleToggleSelectHunk(g *gocui.Gui, v *gocui.View) error {
} }
func (gui *Gui) handleEscapeLineByLinePanel() { func (gui *Gui) handleEscapeLineByLinePanel() {
gui.changeMainViewsContext("normal")
gui.State.Panels.LineByLine = nil gui.State.Panels.LineByLine = nil
} }