From 7ed94c041047b32db4df38b3a0330d89ae99656c Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 8 Aug 2024 10:26:55 +0200 Subject: [PATCH] Replace CurrentContext() with Context().Current() --- pkg/gui/context/local_commits_context.go | 2 +- pkg/gui/context/sub_commits_context.go | 2 +- pkg/gui/controllers/commits_files_controller.go | 2 +- pkg/gui/controllers/custom_patch_options_menu_action.go | 4 ++-- pkg/gui/controllers/helpers/confirmation_helper.go | 2 +- pkg/gui/controllers/helpers/diff_helper.go | 2 +- pkg/gui/controllers/helpers/merge_conflicts_helper.go | 2 +- pkg/gui/controllers/helpers/patch_building_helper.go | 2 +- pkg/gui/controllers/helpers/refs_helper.go | 4 ++-- pkg/gui/controllers/helpers/search_helper.go | 2 +- pkg/gui/controllers/helpers/window_helper.go | 2 +- pkg/gui/controllers/list_controller.go | 2 +- pkg/gui/controllers/options_menu_action.go | 2 +- pkg/gui/controllers/patch_explorer_controller.go | 2 +- pkg/gui/controllers/quit_actions.go | 2 +- pkg/gui/controllers/toggle_whitespace_action.go | 2 +- pkg/gui/global_handlers.go | 4 ++-- pkg/gui/gui.go | 2 +- pkg/gui/gui_common.go | 4 ---- pkg/gui/gui_driver.go | 2 +- pkg/gui/layout.go | 2 +- pkg/gui/options_map.go | 2 +- pkg/gui/types/common.go | 1 - 23 files changed, 24 insertions(+), 29 deletions(-) diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index fcb9b00ca..aeab10e66 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -34,7 +34,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext { getDisplayStrings := func(startIdx int, endIdx int) [][]string { selectedCommitHash := "" - if c.CurrentContext().GetKey() == LOCAL_COMMITS_CONTEXT_KEY { + if c.Context().Current().GetKey() == LOCAL_COMMITS_CONTEXT_KEY { selectedCommit := viewModel.GetSelected() if selectedCommit != nil { selectedCommitHash = selectedCommit.Hash diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index ddbb380c5..7a9dfa476 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -47,7 +47,7 @@ func NewSubCommitsContext( } selectedCommitHash := "" - if c.CurrentContext().GetKey() == SUB_COMMITS_CONTEXT_KEY { + if c.Context().Current().GetKey() == SUB_COMMITS_CONTEXT_KEY { selectedCommit := viewModel.GetSelected() if selectedCommit != nil { selectedCommitHash = selectedCommit.Hash diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index e1c8c8c5a..0cf08b554 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -178,7 +178,7 @@ func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error } func (self *CommitFilesController) discard(selectedNodes []*filetree.CommitFileNode) error { - parentContext, ok := self.c.CurrentContext().GetParentContext() + parentContext, ok := self.c.Context().Current().GetParentContext() if !ok || parentContext.GetKey() != context.LOCAL_COMMITS_CONTEXT_KEY { return errors.New(self.c.Tr.CanOnlyDiscardFromLocalCommits) } diff --git a/pkg/gui/controllers/custom_patch_options_menu_action.go b/pkg/gui/controllers/custom_patch_options_menu_action.go index efcdab02b..5c9cbd2c5 100644 --- a/pkg/gui/controllers/custom_patch_options_menu_action.go +++ b/pkg/gui/controllers/custom_patch_options_menu_action.go @@ -66,7 +66,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error { }, }...) - if self.c.CurrentContext().GetKey() == self.c.Contexts().LocalCommits.GetKey() { + if self.c.Context().Current().GetKey() == self.c.Contexts().LocalCommits.GetKey() { selectedCommit := self.c.Contexts().LocalCommits.GetSelected() if selectedCommit != nil && self.c.Git().Patch.PatchBuilder.To != selectedCommit.Hash { @@ -122,7 +122,7 @@ func (self *CustomPatchOptionsMenuAction) validateNormalWorkingTreeState() (bool } func (self *CustomPatchOptionsMenuAction) returnFocusFromPatchExplorerIfNecessary() error { - if self.c.CurrentContext().GetKey() == self.c.Contexts().CustomPatchBuilder.GetKey() { + if self.c.Context().Current().GetKey() == self.c.Contexts().CustomPatchBuilder.GetKey() { return self.c.Helpers().PatchBuilding.Escape() } return nil diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index 330b9e77d..47e3e89d4 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -431,7 +431,7 @@ func (self *ConfirmationHelper) IsPopupPanel(context types.Context) bool { } func (self *ConfirmationHelper) IsPopupPanelFocused() bool { - return self.IsPopupPanel(self.c.CurrentContext()) + return self.IsPopupPanel(self.c.Context().Current()) } func (self *ConfirmationHelper) TooltipForMenuItem(menuItem *types.MenuItem) string { diff --git a/pkg/gui/controllers/helpers/diff_helper.go b/pkg/gui/controllers/helpers/diff_helper.go index 8b5c01cd3..ad46a589c 100644 --- a/pkg/gui/controllers/helpers/diff_helper.go +++ b/pkg/gui/controllers/helpers/diff_helper.go @@ -93,7 +93,7 @@ func (self *DiffHelper) currentDiffTerminal() string { } func (self *DiffHelper) currentlySelectedFilename() string { - currentContext := self.c.CurrentContext() + currentContext := self.c.Context().Current() switch currentContext := currentContext.(type) { case types.IListContext: diff --git a/pkg/gui/controllers/helpers/merge_conflicts_helper.go b/pkg/gui/controllers/helpers/merge_conflicts_helper.go index f49f46428..abf353300 100644 --- a/pkg/gui/controllers/helpers/merge_conflicts_helper.go +++ b/pkg/gui/controllers/helpers/merge_conflicts_helper.go @@ -123,7 +123,7 @@ func (self *MergeConflictsHelper) RefreshMergeState() error { self.c.Contexts().MergeConflicts.GetMutex().Lock() defer self.c.Contexts().MergeConflicts.GetMutex().Unlock() - if self.c.CurrentContext().GetKey() != context.MERGE_CONFLICTS_CONTEXT_KEY { + if self.c.Context().Current().GetKey() != context.MERGE_CONFLICTS_CONTEXT_KEY { return nil } diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go index 23ab9e7d1..930aa986a 100644 --- a/pkg/gui/controllers/helpers/patch_building_helper.go +++ b/pkg/gui/controllers/helpers/patch_building_helper.go @@ -54,7 +54,7 @@ func (self *PatchBuildingHelper) Reset() error { } // refreshing the current context so that the secondary panel is hidden if necessary. - return self.c.PostRefreshUpdate(self.c.CurrentContext()) + return self.c.PostRefreshUpdate(self.c.Context().Current()) } func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpts) error { diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index 2643ba968..ceadc8dfa 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -109,7 +109,7 @@ func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchN checkout := func(branchName string) error { // Switch to the branches context _before_ starting to check out the // branch, so that we see the inline status - if self.c.CurrentContext() != self.c.Contexts().Branches { + if self.c.Context().Current() != self.c.Contexts().Branches { if err := self.c.Context().Push(self.c.Contexts().Branches); err != nil { return err } @@ -292,7 +292,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest return err } - if self.c.CurrentContext() != self.c.Contexts().Branches { + if self.c.Context().Current() != self.c.Contexts().Branches { if err := self.c.Context().Push(self.c.Contexts().Branches); err != nil { return err } diff --git a/pkg/gui/controllers/helpers/search_helper.go b/pkg/gui/controllers/helpers/search_helper.go index cb6a47bdf..b282f0c66 100644 --- a/pkg/gui/controllers/helpers/search_helper.go +++ b/pkg/gui/controllers/helpers/search_helper.go @@ -262,7 +262,7 @@ func (self *SearchHelper) ReApplySearch(ctx types.Context) { if ctx == state.Context { // Re-render the "x of y" search status, unless the search prompt is // open for typing. - if self.c.CurrentContext().GetKey() != context.SEARCH_CONTEXT_KEY { + if self.c.Context().Current().GetKey() != context.SEARCH_CONTEXT_KEY { self.RenderSearchStatus(searchableContext) } } diff --git a/pkg/gui/controllers/helpers/window_helper.go b/pkg/gui/controllers/helpers/window_helper.go index c0bdc2ab6..e2b0e38f0 100644 --- a/pkg/gui/controllers/helpers/window_helper.go +++ b/pkg/gui/controllers/helpers/window_helper.go @@ -61,7 +61,7 @@ func (self *WindowHelper) windowViewNameMap() *utils.ThreadSafeMap[string, strin } func (self *WindowHelper) CurrentWindow() string { - return self.c.CurrentContext().GetWindowName() + return self.c.Context().Current().GetWindowName() } // assumes the context's windowName has been set to the new window if necessary diff --git a/pkg/gui/controllers/list_controller.go b/pkg/gui/controllers/list_controller.go index 9fb8f95ec..b63954501 100644 --- a/pkg/gui/controllers/list_controller.go +++ b/pkg/gui/controllers/list_controller.go @@ -185,7 +185,7 @@ func (self *ListController) pushContextIfNotFocused() error { } func (self *ListController) isFocused() bool { - return self.c.CurrentContext().GetKey() == self.context.GetKey() + return self.c.Context().Current().GetKey() == self.context.GetKey() } func (self *ListController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { diff --git a/pkg/gui/controllers/options_menu_action.go b/pkg/gui/controllers/options_menu_action.go index d46025afc..7f3f1de64 100644 --- a/pkg/gui/controllers/options_menu_action.go +++ b/pkg/gui/controllers/options_menu_action.go @@ -12,7 +12,7 @@ type OptionsMenuAction struct { } func (self *OptionsMenuAction) Call() error { - ctx := self.c.CurrentContext() + ctx := self.c.Context().Current() // Don't show menu while displaying popup. if ctx.GetKind() == types.PERSISTENT_POPUP || ctx.GetKind() == types.TEMPORARY_POPUP { return nil diff --git a/pkg/gui/controllers/patch_explorer_controller.go b/pkg/gui/controllers/patch_explorer_controller.go index e96ea0aa4..2df62b0f3 100644 --- a/pkg/gui/controllers/patch_explorer_controller.go +++ b/pkg/gui/controllers/patch_explorer_controller.go @@ -293,7 +293,7 @@ func (self *PatchExplorerController) CopySelectedToClipboard() error { } func (self *PatchExplorerController) isFocused() bool { - return self.c.CurrentContext().GetKey() == self.context.GetKey() + return self.c.Context().Current().GetKey() == self.context.GetKey() } func (self *PatchExplorerController) withRenderAndFocus(f func() error) func() error { diff --git a/pkg/gui/controllers/quit_actions.go b/pkg/gui/controllers/quit_actions.go index 761ef1286..78c7e4564 100644 --- a/pkg/gui/controllers/quit_actions.go +++ b/pkg/gui/controllers/quit_actions.go @@ -49,7 +49,7 @@ func (self *QuitActions) confirmQuitDuringUpdate() error { } func (self *QuitActions) Escape() error { - currentContext := self.c.CurrentContext() + currentContext := self.c.Context().Current() if listContext, ok := currentContext.(types.IListContext); ok { if listContext.GetList().IsSelectingRange() { diff --git a/pkg/gui/controllers/toggle_whitespace_action.go b/pkg/gui/controllers/toggle_whitespace_action.go index 41232a769..59d09fa98 100644 --- a/pkg/gui/controllers/toggle_whitespace_action.go +++ b/pkg/gui/controllers/toggle_whitespace_action.go @@ -19,7 +19,7 @@ func (self *ToggleWhitespaceAction) Call() error { context.PATCH_BUILDING_MAIN_CONTEXT_KEY, } - if lo.Contains(contextsThatDontSupportIgnoringWhitespace, self.c.CurrentContext().GetKey()) { + if lo.Contains(contextsThatDontSupportIgnoringWhitespace, self.c.Context().Current().GetKey()) { // Ignoring whitespace is not supported in these views. Let the user // know that it's not going to work in case they try to turn it on. return errors.New(self.c.Tr.IgnoreWhitespaceNotSupportedHere) diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index fd9540ea8..5d4e886bf 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -27,7 +27,7 @@ func (gui *Gui) scrollDownView(view *gocui.View) { func (gui *Gui) scrollUpMain() error { var view *gocui.View - if gui.c.CurrentContext().GetWindowName() == "secondary" { + if gui.c.Context().Current().GetWindowName() == "secondary" { view = gui.secondaryView() } else { view = gui.mainView() @@ -48,7 +48,7 @@ func (gui *Gui) scrollUpMain() error { func (gui *Gui) scrollDownMain() error { var view *gocui.View - if gui.c.CurrentContext().GetWindowName() == "secondary" { + if gui.c.Context().Current().GetWindowName() == "secondary" { view = gui.secondaryView() } else { view = gui.mainView() diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index a7cb506c5..b65dd80e0 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -360,7 +360,7 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context { gui.State.CurrentPopupOpts = nil gui.Mutexes.PopupMutex.Unlock() - return gui.c.CurrentContext() + return gui.c.Context().Current() } contextTree := gui.contextTree() diff --git a/pkg/gui/gui_common.go b/pkg/gui/gui_common.go index 09ef709d3..a346df509 100644 --- a/pkg/gui/gui_common.go +++ b/pkg/gui/gui_common.go @@ -45,10 +45,6 @@ func (self *guiCommon) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) { return self.gui.runSubprocessWithSuspense(cmdObj) } -func (self *guiCommon) CurrentContext() types.Context { - return self.gui.State.ContextMgr.Current() -} - func (self *guiCommon) CurrentStaticContext() types.Context { return self.gui.State.ContextMgr.CurrentStatic() } diff --git a/pkg/gui/gui_driver.go b/pkg/gui/gui_driver.go index 5de0ad4ee..b3dfa1b82 100644 --- a/pkg/gui/gui_driver.go +++ b/pkg/gui/gui_driver.go @@ -75,7 +75,7 @@ func (self *GuiDriver) Keys() config.KeybindingConfig { } func (self *GuiDriver) CurrentContext() types.Context { - return self.gui.c.CurrentContext() + return self.gui.c.Context().Current() } func (self *GuiDriver) ContextForView(viewName string) types.Context { diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index 3bf6a7c35..8c26fef80 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -211,7 +211,7 @@ func (gui *Gui) onInitialViewsCreationForRepo() error { } } - initialContext := gui.c.CurrentContext() + initialContext := gui.c.Context().Current() if err := gui.c.ActivateContext(initialContext); err != nil { return err } diff --git a/pkg/gui/options_map.go b/pkg/gui/options_map.go index 01bb3e212..021e4d7bf 100644 --- a/pkg/gui/options_map.go +++ b/pkg/gui/options_map.go @@ -33,7 +33,7 @@ func (gui *Gui) renderContextOptionsMap() { // to want to press that key. For example, when in cherry-picking mode, we // want to prominently show the keybinding for pasting commits. func (self *OptionsMapMgr) renderContextOptionsMap() { - currentContext := self.c.CurrentContext() + currentContext := self.c.Context().Current() currentContextBindings := currentContext.GetKeybindings(self.c.KeybindingsOpts()) globalBindings := self.c.Contexts().Global.GetKeybindings(self.c.KeybindingsOpts()) diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index bbb106ae0..f01108779 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -57,7 +57,6 @@ type IGuiCommon interface { RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) RunSubprocessAndRefresh(oscommands.ICmdObj) error - CurrentContext() Context CurrentStaticContext() Context CurrentSideContext() Context CurrentPopupContexts() []Context