From f0c3d3fc4d43f5b7487540d5c0356f62b3b2997d Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 19 Aug 2020 08:04:39 +1000 Subject: [PATCH] centralise setting of main views context --- pkg/gui/commit_files_panel.go | 1 - pkg/gui/context.go | 8 ++++++++ pkg/gui/files_panel.go | 2 -- pkg/gui/layout.go | 2 -- pkg/gui/line_by_line_panel.go | 1 - 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 3765ba0cc..27f02297c 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -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 { return err } diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 1e466151e..522932664 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -1,6 +1,8 @@ package gui import ( + "fmt" + "github.com/jesseduffield/gocui" ) @@ -104,6 +106,10 @@ func (gui *Gui) switchContext(c Context) error { gui.State.ContextStack = append(gui.State.ContextStack, c) } + if c.GetViewName() == "main" { + gui.changeMainViewsContext(c.GetKey()) + } + return gui.activateContext(c) }) @@ -422,6 +428,8 @@ func (gui *Gui) changeMainViewsContext(context string) { case "normal", "patch-building", "staging", "merging": gui.getMainView().Context = context gui.getSecondaryView().Context = context + default: + panic(fmt.Sprintf("unknown context for main: %s", context)) } gui.State.MainContext = context diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index b9f69c161..b116271db 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -165,7 +165,6 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error if file.HasMergeConflicts { return gui.createErrorPanel(gui.Tr.SLocalize("FileStagingRequirements")) } - gui.changeMainViewsContext("staging") // TODO: move into context code gui.switchContext(gui.Contexts.Staging.Context) 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 { return gui.createErrorPanel(gui.Tr.SLocalize("FileNoMergeCons")) } - gui.changeMainViewsContext("merging") // TODO: move into context code return gui.switchContext(gui.Contexts.Merging.Context) } diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index a96b2c169..094c7271c 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -343,8 +343,6 @@ func (gui *Gui) onInitialViewsCreation() error { return err } - gui.changeMainViewsContext("normal") - if gui.showRecentRepos { if err := gui.handleCreateRecentReposMenu(); err != nil { return err diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index 1aedcabc1..6bec51308 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -325,7 +325,6 @@ func (gui *Gui) handleToggleSelectHunk(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleEscapeLineByLinePanel() { - gui.changeMainViewsContext("normal") gui.State.Panels.LineByLine = nil }