diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 5dc6df6a0..abb7cb6ee 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -53,7 +53,7 @@ func (self *ContextMgr) Replace(c types.Context) error { defer self.Unlock() - return self.ActivateContext(c, types.OnFocusOpts{}) + return self.Activate(c, types.OnFocusOpts{}) } func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) error { @@ -74,7 +74,7 @@ func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) error { contextsToDeactivate, contextToActivate := self.pushToContextStack(c) for _, contextToDeactivate := range contextsToDeactivate { - if err := self.deactivateContext(contextToDeactivate, types.OnFocusLostOpts{NewContextKey: c.GetKey()}); err != nil { + if err := self.deactivate(contextToDeactivate, types.OnFocusLostOpts{NewContextKey: c.GetKey()}); err != nil { return err } } @@ -83,7 +83,7 @@ func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) error { return nil } - return self.ActivateContext(contextToActivate, singleOpts) + return self.Activate(contextToActivate, singleOpts) } // Adjusts the context stack based on the context that's being pushed and @@ -160,44 +160,14 @@ func (self *ContextMgr) Pop() error { self.Unlock() - if err := self.deactivateContext(currentContext, types.OnFocusLostOpts{NewContextKey: newContext.GetKey()}); err != nil { + if err := self.deactivate(currentContext, types.OnFocusLostOpts{NewContextKey: newContext.GetKey()}); err != nil { return err } - return self.ActivateContext(newContext, types.OnFocusOpts{}) + return self.Activate(newContext, types.OnFocusOpts{}) } -func (self *ContextMgr) RemoveContexts(contextsToRemove []types.Context) error { - self.Lock() - - if len(self.ContextStack) == 1 { - self.Unlock() - return nil - } - - rest := lo.Filter(self.ContextStack, func(context types.Context, _ int) bool { - for _, contextToRemove := range contextsToRemove { - if context.GetKey() == contextToRemove.GetKey() { - return false - } - } - return true - }) - self.ContextStack = rest - contextToActivate := rest[len(rest)-1] - self.Unlock() - - for _, context := range contextsToRemove { - if err := self.deactivateContext(context, types.OnFocusLostOpts{NewContextKey: contextToActivate.GetKey()}); err != nil { - return err - } - } - - // activate the item at the top of the stack - return self.ActivateContext(contextToActivate, types.OnFocusOpts{}) -} - -func (self *ContextMgr) deactivateContext(c types.Context, opts types.OnFocusLostOpts) error { +func (self *ContextMgr) deactivate(c types.Context, opts types.OnFocusLostOpts) error { view, _ := self.gui.c.GocuiGui().View(c.GetViewName()) if opts.NewContextKey != context.SEARCH_CONTEXT_KEY { @@ -220,7 +190,7 @@ func (self *ContextMgr) deactivateContext(c types.Context, opts types.OnFocusLos return nil } -func (self *ContextMgr) ActivateContext(c types.Context, opts types.OnFocusOpts) error { +func (self *ContextMgr) Activate(c types.Context, opts types.OnFocusOpts) error { viewName := c.GetViewName() v, err := self.gui.c.GocuiGui().View(viewName) if err != nil { @@ -392,7 +362,7 @@ func (self *ContextMgr) ContextForKey(key types.ContextKey) types.Context { return nil } -func (self *ContextMgr) PopupContexts() []types.Context { +func (self *ContextMgr) CurrentPopup() []types.Context { self.RLock() defer self.RUnlock() 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/menu_context.go b/pkg/gui/context/menu_context.go index f1438b221..06cdf8b46 100644 --- a/pkg/gui/context/menu_context.go +++ b/pkg/gui/context/menu_context.go @@ -197,7 +197,7 @@ func (self *MenuContext) OnMenuPress(selectedItem *types.MenuItem) error { return nil } - if err := self.c.PopContext(); err != nil { + if err := self.c.Context().Pop(); err != nil { return err } diff --git a/pkg/gui/context/parent_context_mgr.go b/pkg/gui/context/parent_context_mgr.go index 50747a3a0..4f704e35e 100644 --- a/pkg/gui/context/parent_context_mgr.go +++ b/pkg/gui/context/parent_context_mgr.go @@ -4,17 +4,14 @@ import "github.com/jesseduffield/lazygit/pkg/gui/types" type ParentContextMgr struct { ParentContext types.Context - // we can't know on the calling end whether a Context is actually a nil value without reflection, so we're storing this flag here to tell us. There has got to be a better way around this - hasParent bool } var _ types.ParentContexter = (*ParentContextMgr)(nil) func (self *ParentContextMgr) SetParentContext(context types.Context) { self.ParentContext = context - self.hasParent = true } -func (self *ParentContextMgr) GetParentContext() (types.Context, bool) { - return self.ParentContext, self.hasParent +func (self *ParentContextMgr) GetParentContext() types.Context { + return self.ParentContext } diff --git a/pkg/gui/context/patch_explorer_context.go b/pkg/gui/context/patch_explorer_context.go index ee856c5d2..ac8890191 100644 --- a/pkg/gui/context/patch_explorer_context.go +++ b/pkg/gui/context/patch_explorer_context.go @@ -53,7 +53,7 @@ func NewPatchExplorerContext( func(selectedLineIdx int) error { ctx.GetMutex().Lock() defer ctx.GetMutex().Unlock() - return ctx.NavigateTo(ctx.c.IsCurrentContext(ctx), selectedLineIdx) + return ctx.NavigateTo(ctx.c.Context().IsCurrent(ctx), selectedLineIdx) }), ) 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/commit_description_controller.go b/pkg/gui/controllers/commit_description_controller.go index 80608fff5..50e089fb6 100644 --- a/pkg/gui/controllers/commit_description_controller.go +++ b/pkg/gui/controllers/commit_description_controller.go @@ -53,7 +53,7 @@ func (self *CommitDescriptionController) context() *context.CommitMessageContext } func (self *CommitDescriptionController) switchToCommitMessage() error { - return self.c.ReplaceContext(self.c.Contexts().CommitMessage) + return self.c.Context().Replace(self.c.Contexts().CommitMessage) } func (self *CommitDescriptionController) close() error { diff --git a/pkg/gui/controllers/commit_message_controller.go b/pkg/gui/controllers/commit_message_controller.go index 5c37b4da9..d989086c4 100644 --- a/pkg/gui/controllers/commit_message_controller.go +++ b/pkg/gui/controllers/commit_message_controller.go @@ -85,7 +85,7 @@ func (self *CommitMessageController) handleNextCommit() error { } func (self *CommitMessageController) switchToCommitDescription() error { - if err := self.c.ReplaceContext(self.c.Contexts().CommitDescription); err != nil { + if err := self.c.Context().Replace(self.c.Contexts().CommitDescription); err != nil { return err } return nil diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 2b2c709f3..2a9ba8271 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -178,8 +178,8 @@ func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error } func (self *CommitFilesController) discard(selectedNodes []*filetree.CommitFileNode) error { - parentContext, ok := self.c.CurrentContext().GetParentContext() - if !ok || parentContext.GetKey() != context.LOCAL_COMMITS_CONTEXT_KEY { + parentContext := self.c.Context().Current().GetParentContext() + if parentContext == nil || parentContext.GetKey() != context.LOCAL_COMMITS_CONTEXT_KEY { return errors.New(self.c.Tr.CanOnlyDiscardFromLocalCommits) } @@ -354,7 +354,7 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode } } - return self.c.PushContext(self.c.Contexts().CustomPatchBuilder, opts) + return self.c.Context().Push(self.c.Contexts().CustomPatchBuilder, opts) } if self.c.Git().Patch.PatchBuilder.Active() && self.c.Git().Patch.PatchBuilder.To != self.context().GetRef().RefName() { diff --git a/pkg/gui/controllers/confirmation_controller.go b/pkg/gui/controllers/confirmation_controller.go index 45bd16a45..542458a71 100644 --- a/pkg/gui/controllers/confirmation_controller.go +++ b/pkg/gui/controllers/confirmation_controller.go @@ -49,7 +49,7 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [ self.c.UserConfig.Keybinding.Universal.Remove, self.c.UserConfig.Keybinding.Universal.Edit) } self.c.Views().Suggestions.Subtitle = subtitle - return self.c.ReplaceContext(self.c.Contexts().Suggestions) + return self.c.Context().Replace(self.c.Contexts().Suggestions) } return nil }, diff --git a/pkg/gui/controllers/context_lines_controller.go b/pkg/gui/controllers/context_lines_controller.go index 44e191331..bdebd0949 100644 --- a/pkg/gui/controllers/context_lines_controller.go +++ b/pkg/gui/controllers/context_lines_controller.go @@ -94,7 +94,7 @@ func (self *ContextLinesController) applyChange() error { self.c.Toast(fmt.Sprintf(self.c.Tr.DiffContextSizeChanged, self.c.AppState.DiffContextSize)) self.c.SaveAppStateAndLogError() - currentContext := self.c.CurrentStaticContext() + currentContext := self.c.Context().CurrentStatic() switch currentContext.GetKey() { // we make an exception for our staging and patch building contexts because they actually need to refresh their state afterwards. case context.PATCH_BUILDING_MAIN_CONTEXT_KEY: @@ -117,6 +117,6 @@ func (self *ContextLinesController) checkCanChangeContext() error { func (self *ContextLinesController) isShowingDiff() bool { return lo.Contains( CONTEXT_KEYS_SHOWING_DIFFS, - self.c.CurrentStaticContext().GetKey(), + self.c.Context().CurrentStatic().GetKey(), ) } diff --git a/pkg/gui/controllers/custom_patch_options_menu_action.go b/pkg/gui/controllers/custom_patch_options_menu_action.go index 867e4528a..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 @@ -220,7 +220,7 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error { if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil { return err } - return self.c.PushContext(self.c.Contexts().LocalCommits) + return self.c.Context().Push(self.c.Contexts().LocalCommits) }) }, }, diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 39730ae09..934aca511 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -500,7 +500,7 @@ func (self *FilesController) EnterFile(opts types.OnFocusOpts) error { return errors.New(self.c.Tr.FileStagingRequirements) } - return self.c.PushContext(self.c.Contexts().Staging, opts) + return self.c.Context().Push(self.c.Contexts().Staging, opts) } func (self *FilesController) toggleStagedAll() error { diff --git a/pkg/gui/controllers/filtering_menu_action.go b/pkg/gui/controllers/filtering_menu_action.go index a340c3e9a..9367c5bca 100644 --- a/pkg/gui/controllers/filtering_menu_action.go +++ b/pkg/gui/controllers/filtering_menu_action.go @@ -14,7 +14,7 @@ type FilteringMenuAction struct { func (self *FilteringMenuAction) Call() error { fileName := "" author := "" - switch self.c.CurrentSideContext() { + switch self.c.Context().CurrentSide() { case self.c.Contexts().Files: node := self.c.Contexts().Files.GetSelected() if node != nil { @@ -116,7 +116,7 @@ func (self *FilteringMenuAction) setFiltering() error { repoState.SetScreenMode(types.SCREEN_HALF) } - if err := self.c.PushContext(self.c.Contexts().LocalCommits); err != nil { + if err := self.c.Context().Push(self.c.Contexts().LocalCommits); err != nil { return err } diff --git a/pkg/gui/controllers/helpers/commits_helper.go b/pkg/gui/controllers/helpers/commits_helper.go index be3a36e8d..ff6ba2e80 100644 --- a/pkg/gui/controllers/helpers/commits_helper.go +++ b/pkg/gui/controllers/helpers/commits_helper.go @@ -154,7 +154,7 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp self.UpdateCommitPanelView(opts.InitialMessage) - return self.c.PushContext(self.c.Contexts().CommitMessage) + return self.c.Context().Push(self.c.Contexts().CommitMessage) } func (self *CommitsHelper) OnCommitSuccess() { @@ -193,7 +193,7 @@ func (self *CommitsHelper) CloseCommitMessagePanel() error { self.c.Views().CommitMessage.Visible = false self.c.Views().CommitDescription.Visible = false - return self.c.PopContext() + return self.c.Context().Pop() } func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.Suggestion) error { diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index c0fb5bafb..fa2b502a9 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -28,7 +28,7 @@ func (self *ConfirmationHelper) wrappedConfirmationFunction(cancel goContext.Can return func() error { cancel() - if err := self.c.PopContext(); err != nil { + if err := self.c.Context().Pop(); err != nil { return err } @@ -241,7 +241,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ self.c.State().GetRepoState().SetCurrentPopupOpts(&opts) - return self.c.PushContext(self.c.Contexts().Confirmation) + return self.c.Context().Push(self.c.Contexts().Confirmation) } func underlineLinks(text string) string { @@ -325,7 +325,7 @@ func (self *ConfirmationHelper) getSelectedSuggestionValue() string { func (self *ConfirmationHelper) ResizeCurrentPopupPanels() { var parentPopupContext types.Context - for _, c := range self.c.CurrentPopupContexts() { + for _, c := range self.c.Context().CurrentPopup() { switch c { case self.c.Contexts().Menu: self.resizeMenu(parentPopupContext) @@ -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..94ac291b9 100644 --- a/pkg/gui/controllers/helpers/diff_helper.go +++ b/pkg/gui/controllers/helpers/diff_helper.go @@ -70,7 +70,7 @@ func (self *DiffHelper) RenderDiff() error { // which becomes an option when you bring up the diff menu, but when you're just // flicking through branches it will be using the local branch name. func (self *DiffHelper) CurrentDiffTerminals() []string { - c := self.c.CurrentSideContext() + c := self.c.Context().CurrentSide() if c.GetKey() == "" { return nil @@ -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/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index 9cb951408..8fc94243d 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -137,7 +137,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error { } self.c.Contexts().LocalCommits.SetSelection(index) - return self.c.PushContext(self.c.Contexts().LocalCommits) + return self.c.Context().Push(self.c.Contexts().LocalCommits) } if warnAboutAddedLines { diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index a5554aa58..73c345070 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -202,7 +202,7 @@ func (self *MergeAndRebaseHelper) PromptForConflictHandling() error { { Label: self.c.Tr.ViewConflictsMenuItem, OnPress: func() error { - return self.c.PushContext(self.c.Contexts().Files) + return self.c.Context().Push(self.c.Contexts().Files) }, }, { @@ -316,7 +316,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error { if err = self.ResetMarkedBaseCommit(); err != nil { return err } - return self.c.PushContext(self.c.Contexts().LocalCommits) + return self.c.Context().Push(self.c.Contexts().LocalCommits) }, }, { diff --git a/pkg/gui/controllers/helpers/merge_conflicts_helper.go b/pkg/gui/controllers/helpers/merge_conflicts_helper.go index 249be4b69..cdf1d4497 100644 --- a/pkg/gui/controllers/helpers/merge_conflicts_helper.go +++ b/pkg/gui/controllers/helpers/merge_conflicts_helper.go @@ -61,8 +61,8 @@ func (self *MergeConflictsHelper) EscapeMerge() error { // to continue the merge/rebase. In that case, we don't want to then push the // files context over it. // So long as both places call OnUIThread, we're fine. - if self.c.IsCurrentContext(self.c.Contexts().MergeConflicts) { - return self.c.PushContext(self.c.Contexts().Files) + if self.c.Context().IsCurrent(self.c.Contexts().MergeConflicts) { + return self.c.Context().Push(self.c.Contexts().Files) } return nil }) @@ -93,7 +93,7 @@ func (self *MergeConflictsHelper) SwitchToMerge(path string) error { } } - return self.c.PushContext(self.c.Contexts().MergeConflicts) + return self.c.Context().Push(self.c.Contexts().MergeConflicts) } func (self *MergeConflictsHelper) context() *context.MergeConflictsContext { @@ -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 dd4c3515a..4c2fc40d0 100644 --- a/pkg/gui/controllers/helpers/patch_building_helper.go +++ b/pkg/gui/controllers/helpers/patch_building_helper.go @@ -34,14 +34,14 @@ func (self *PatchBuildingHelper) ValidateNormalWorkingTreeState() (bool, error) // takes us from the patch building panel back to the commit files panel func (self *PatchBuildingHelper) Escape() error { - return self.c.PopContext() + return self.c.Context().Pop() } // kills the custom patch and returns us back to the commit files panel if needed func (self *PatchBuildingHelper) Reset() error { self.c.Git().Patch.PatchBuilder.Reset() - if self.c.CurrentStaticContext().GetKind() != types.SIDE_CONTEXT { + if self.c.Context().CurrentStatic().GetKind() != types.SIDE_CONTEXT { if err := self.Escape(); err != nil { return err } @@ -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/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 21c20c646..4295c11ab 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -276,8 +276,8 @@ func (self *RefreshHelper) refreshReflogAndBranches(refreshWorktrees bool, keepB func (self *RefreshHelper) refreshCommitsAndCommitFiles() { _ = self.refreshCommitsWithLimit() - ctx, ok := self.c.Contexts().CommitFiles.GetParentContext() - if ok && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY { + ctx := self.c.Contexts().CommitFiles.GetParentContext() + if ctx != nil && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY { // This makes sense when we've e.g. just amended a commit, meaning we get a new commit hash at the same position. // However if we've just added a brand new commit, it pushes the list down by one and so we would end up // showing the contents of a different commit than the one we initially entered. diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index f471f57e2..ceadc8dfa 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -109,8 +109,8 @@ 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 err := self.c.PushContext(self.c.Contexts().Branches); err != nil { + if self.c.Context().Current() != self.c.Contexts().Branches { + if err := self.c.Context().Push(self.c.Contexts().Branches); err != nil { return err } } @@ -292,8 +292,8 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest return err } - if self.c.CurrentContext() != self.c.Contexts().Branches { - if err := self.c.PushContext(self.c.Contexts().Branches); err != nil { + 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 653640e02..b282f0c66 100644 --- a/pkg/gui/controllers/helpers/search_helper.go +++ b/pkg/gui/controllers/helpers/search_helper.go @@ -41,7 +41,7 @@ func (self *SearchHelper) OpenFilterPrompt(context types.IFilterableContext) err self.OnPromptContentChanged("") promptView.RenderTextArea() - if err := self.c.PushContext(self.c.Contexts().Search); err != nil { + if err := self.c.Context().Push(self.c.Contexts().Search); err != nil { return err } @@ -60,7 +60,7 @@ func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) err promptView.ClearTextArea() promptView.RenderTextArea() - if err := self.c.PushContext(self.c.Contexts().Search); err != nil { + if err := self.c.Context().Push(self.c.Contexts().Search); err != nil { return err } @@ -118,7 +118,7 @@ func (self *SearchHelper) Confirm() error { case types.SearchTypeSearch: return self.ConfirmSearch() case types.SearchTypeNone: - return self.c.PopContext() + return self.c.Context().Pop() } return nil @@ -140,7 +140,7 @@ func (self *SearchHelper) ConfirmFilter() error { context.GetSearchHistory().Push(filterString) } - return self.c.PopContext() + return self.c.Context().Pop() } func (self *SearchHelper) ConfirmSearch() error { @@ -158,7 +158,7 @@ func (self *SearchHelper) ConfirmSearch() error { context.GetSearchHistory().Push(searchString) } - if err := self.c.PopContext(); err != nil { + if err := self.c.Context().Pop(); err != nil { return err } @@ -183,7 +183,7 @@ func modelSearchResults(context types.ISearchableContext) []gocui.SearchPosition func (self *SearchHelper) CancelPrompt() error { self.Cancel() - return self.c.PopContext() + return self.c.Context().Pop() } func (self *SearchHelper) ScrollHistory(scrollIncrement int) { @@ -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/staging_helper.go b/pkg/gui/controllers/helpers/staging_helper.go index bf4424907..5643e47e8 100644 --- a/pkg/gui/controllers/helpers/staging_helper.go +++ b/pkg/gui/controllers/helpers/staging_helper.go @@ -83,11 +83,11 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro } if mainState == nil && !secondaryFocused { - return self.c.PushContext(secondaryContext, focusOpts) + return self.c.Context().Push(secondaryContext, focusOpts) } if secondaryState == nil && secondaryFocused { - return self.c.PushContext(mainContext, focusOpts) + return self.c.Context().Push(mainContext, focusOpts) } if secondaryFocused { @@ -110,13 +110,13 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro } func (self *StagingHelper) handleStagingEscape() error { - return self.c.PushContext(self.c.Contexts().Files) + return self.c.Context().Push(self.c.Contexts().Files) } func (self *StagingHelper) secondaryStagingFocused() bool { - return self.c.CurrentStaticContext().GetKey() == self.c.Contexts().StagingSecondary.GetKey() + return self.c.Context().CurrentStatic().GetKey() == self.c.Contexts().StagingSecondary.GetKey() } func (self *StagingHelper) mainStagingFocused() bool { - return self.c.CurrentStaticContext().GetKey() == self.c.Contexts().Staging.GetKey() + return self.c.Context().CurrentStatic().GetKey() == self.c.Contexts().Staging.GetKey() } diff --git a/pkg/gui/controllers/helpers/sub_commits_helper.go b/pkg/gui/controllers/helpers/sub_commits_helper.go index f1cecf7f5..805aca5f1 100644 --- a/pkg/gui/controllers/helpers/sub_commits_helper.go +++ b/pkg/gui/controllers/helpers/sub_commits_helper.go @@ -72,5 +72,5 @@ func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error { return err } - return self.c.PushContext(self.c.Contexts().SubCommits) + return self.c.Context().Push(self.c.Contexts().SubCommits) } diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper.go b/pkg/gui/controllers/helpers/window_arrangement_helper.go index 322cd1bd6..d27e9aa82 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper.go @@ -89,8 +89,8 @@ func (self *WindowArrangementHelper) GetWindowDimensions(informationStr string, Height: height, UserConfig: self.c.UserConfig, CurrentWindow: self.windowHelper.CurrentWindow(), - CurrentSideWindow: self.c.CurrentSideContext().GetWindowName(), - CurrentStaticWindow: self.c.CurrentStaticContext().GetWindowName(), + CurrentSideWindow: self.c.Context().CurrentSide().GetWindowName(), + CurrentStaticWindow: self.c.Context().CurrentStatic().GetWindowName(), SplitMainPanel: repoState.GetSplitMainPanel(), ScreenMode: repoState.GetScreenMode(), AppStatus: appStatus, 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/jump_to_side_window_controller.go b/pkg/gui/controllers/jump_to_side_window_controller.go index 1a0f5afa4..2ef74d957 100644 --- a/pkg/gui/controllers/jump_to_side_window_controller.go +++ b/pkg/gui/controllers/jump_to_side_window_controller.go @@ -55,6 +55,6 @@ func (self *JumpToSideWindowController) goToSideWindow(window string) func() err context := self.c.Helpers().Window.GetContextForWindow(window) - return self.c.PushContext(context) + return self.c.Context().Push(context) } } diff --git a/pkg/gui/controllers/list_controller.go b/pkg/gui/controllers/list_controller.go index 711d32f79..b63954501 100644 --- a/pkg/gui/controllers/list_controller.go +++ b/pkg/gui/controllers/list_controller.go @@ -176,7 +176,7 @@ func (self *ListController) HandleClick(opts gocui.ViewMouseBindingOpts) error { func (self *ListController) pushContextIfNotFocused() error { if !self.isFocused() { - if err := self.c.PushContext(self.context); err != nil { + if err := self.c.Context().Push(self.context); err != nil { return err } } @@ -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/menu_controller.go b/pkg/gui/controllers/menu_controller.go index ddd0b2c18..61bd3b960 100644 --- a/pkg/gui/controllers/menu_controller.go +++ b/pkg/gui/controllers/menu_controller.go @@ -79,7 +79,7 @@ func (self *MenuController) close() error { return nil } - return self.c.PopContext() + return self.c.Context().Pop() } func (self *MenuController) context() *context.MenuContext { diff --git a/pkg/gui/controllers/merge_conflicts_controller.go b/pkg/gui/controllers/merge_conflicts_controller.go index 1f22e62bc..7ed5762f7 100644 --- a/pkg/gui/controllers/merge_conflicts_controller.go +++ b/pkg/gui/controllers/merge_conflicts_controller.go @@ -194,7 +194,7 @@ func (self *MergeConflictsController) context() *context.MergeConflictsContext { } func (self *MergeConflictsController) Escape() error { - return self.c.PopContext() + return self.c.Context().Pop() } func (self *MergeConflictsController) HandleEditFile() error { 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 d75fe060d..2df62b0f3 100644 --- a/pkg/gui/controllers/patch_explorer_controller.go +++ b/pkg/gui/controllers/patch_explorer_controller.go @@ -150,7 +150,7 @@ func (self *PatchExplorerController) GetMouseKeybindings(opts types.KeybindingsO return self.withRenderAndFocus(self.HandleMouseDown)() } - return self.c.PushContext(self.context, types.OnFocusOpts{ + return self.c.Context().Push(self.context, types.OnFocusOpts{ ClickedWindowName: self.context.GetWindowName(), ClickedViewLineIdx: opts.Y, }) @@ -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 7b1ba4c2d..f7cd8e56f 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() { @@ -71,10 +71,10 @@ func (self *QuitActions) Escape() error { } } - parentContext, hasParent := currentContext.GetParentContext() - if hasParent && currentContext != nil && parentContext != nil { + parentContext := currentContext.GetParentContext() + if parentContext != nil { // TODO: think about whether this should be marked as a return rather than adding to the stack - return self.c.PushContext(parentContext) + return self.c.Context().Push(parentContext) } for _, mode := range self.c.Helpers().Mode.Statuses() { diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go index bf47a20cd..cf9c40b22 100644 --- a/pkg/gui/controllers/remotes_controller.go +++ b/pkg/gui/controllers/remotes_controller.go @@ -131,7 +131,7 @@ func (self *RemotesController) enter(remote *models.Remote) error { return err } - return self.c.PushContext(remoteBranchesContext) + return self.c.Context().Push(remoteBranchesContext) } func (self *RemotesController) add() error { diff --git a/pkg/gui/controllers/rename_similarity_threshold_controller.go b/pkg/gui/controllers/rename_similarity_threshold_controller.go index 0b154aa36..f90e32da0 100644 --- a/pkg/gui/controllers/rename_similarity_threshold_controller.go +++ b/pkg/gui/controllers/rename_similarity_threshold_controller.go @@ -82,7 +82,7 @@ func (self *RenameSimilarityThresholdController) applyChange() error { self.c.Toast(fmt.Sprintf(self.c.Tr.RenameSimilarityThresholdChanged, self.c.AppState.RenameSimilarityThreshold)) self.c.SaveAppStateAndLogError() - currentContext := self.c.CurrentStaticContext() + currentContext := self.c.Context().CurrentStatic() switch currentContext.GetKey() { // we make an exception for our files context, because it actually need to refresh its state afterwards. case context.FILES_CONTEXT_KEY: @@ -95,6 +95,6 @@ func (self *RenameSimilarityThresholdController) applyChange() error { func (self *RenameSimilarityThresholdController) isShowingRenames() bool { return lo.Contains( CONTEXT_KEYS_SHOWING_RENAMES, - self.c.CurrentStaticContext().GetKey(), + self.c.Context().CurrentStatic().GetKey(), ) } diff --git a/pkg/gui/controllers/side_window_controller.go b/pkg/gui/controllers/side_window_controller.go index 0b9877494..5ad776633 100644 --- a/pkg/gui/controllers/side_window_controller.go +++ b/pkg/gui/controllers/side_window_controller.go @@ -69,7 +69,7 @@ func (self *SideWindowController) previousSideWindow() error { context := self.c.Helpers().Window.GetContextForWindow(newWindow) - return self.c.PushContext(context) + return self.c.Context().Push(context) } func (self *SideWindowController) nextSideWindow() error { @@ -92,5 +92,5 @@ func (self *SideWindowController) nextSideWindow() error { context := self.c.Helpers().Window.GetContextForWindow(newWindow) - return self.c.PushContext(context) + return self.c.Context().Push(context) } diff --git a/pkg/gui/controllers/snake_controller.go b/pkg/gui/controllers/snake_controller.go index b8e3327f7..086e42e1d 100644 --- a/pkg/gui/controllers/snake_controller.go +++ b/pkg/gui/controllers/snake_controller.go @@ -75,5 +75,5 @@ func (self *SnakeController) SetDirection(direction snake.Direction) func() erro } func (self *SnakeController) Escape() error { - return self.c.PushContext(self.c.Contexts().Submodules) + return self.c.Context().Push(self.c.Contexts().Submodules) } diff --git a/pkg/gui/controllers/staging_controller.go b/pkg/gui/controllers/staging_controller.go index 8854aa239..c3dcbafde 100644 --- a/pkg/gui/controllers/staging_controller.go +++ b/pkg/gui/controllers/staging_controller.go @@ -172,12 +172,12 @@ func (self *StagingController) Escape() error { return self.c.PostRefreshUpdate(self.context) } - return self.c.PopContext() + return self.c.Context().Pop() } func (self *StagingController) TogglePanel() error { if self.otherContext.GetState() != nil { - return self.c.PushContext(self.otherContext) + return self.c.Context().Push(self.otherContext) } return nil diff --git a/pkg/gui/controllers/status_controller.go b/pkg/gui/controllers/status_controller.go index 483acdda6..cdfa08257 100644 --- a/pkg/gui/controllers/status_controller.go +++ b/pkg/gui/controllers/status_controller.go @@ -113,7 +113,7 @@ func (self *StatusController) onClick(opts gocui.ViewMouseBindingOpts) error { return nil } - if err := self.c.PushContext(self.Context()); err != nil { + if err := self.c.Context().Push(self.Context()); err != nil { return err } diff --git a/pkg/gui/controllers/submodules_controller.go b/pkg/gui/controllers/submodules_controller.go index ba6db6250..af729cea8 100644 --- a/pkg/gui/controllers/submodules_controller.go +++ b/pkg/gui/controllers/submodules_controller.go @@ -285,7 +285,7 @@ func (self *SubmodulesController) remove(submodule *models.SubmoduleConfig) erro } func (self *SubmodulesController) easterEgg() error { - return self.c.PushContext(self.c.Contexts().Snake) + return self.c.Context().Push(self.c.Contexts().Snake) } func (self *SubmodulesController) context() *context.SubmodulesContext { diff --git a/pkg/gui/controllers/suggestions_controller.go b/pkg/gui/controllers/suggestions_controller.go index a425f356e..3908f5267 100644 --- a/pkg/gui/controllers/suggestions_controller.go +++ b/pkg/gui/controllers/suggestions_controller.go @@ -72,7 +72,7 @@ func (self *SuggestionsController) GetKeybindings(opts types.KeybindingsOpts) [] func (self *SuggestionsController) switchToConfirmation() error { self.c.Views().Suggestions.Subtitle = "" self.c.Views().Suggestions.Highlight = false - return self.c.ReplaceContext(self.c.Contexts().Confirmation) + return self.c.Context().Replace(self.c.Contexts().Confirmation) } func (self *SuggestionsController) GetOnFocusLost() func(types.OnFocusLostOpts) error { diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index 284fbd42f..92faefb79 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -89,7 +89,7 @@ func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesConte return err } - return self.c.PushContext(diffFilesContext) + return self.c.Context().Push(diffFilesContext) } func (self *SwitchToDiffFilesController) itemRepresentsCommit(ref types.Ref) *types.DisabledReason { diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go index 623ef7217..9c477be8e 100644 --- a/pkg/gui/controllers/tags_controller.go +++ b/pkg/gui/controllers/tags_controller.go @@ -115,7 +115,7 @@ func (self *TagsController) checkout(tag *models.Tag) error { if err := self.c.Helpers().Refs.CheckoutRef(tag.FullRefName(), types.CheckoutRefOptions{}); err != nil { return err } - return self.c.PushContext(self.c.Contexts().Branches) + return self.c.Context().Push(self.c.Contexts().Branches) } func (self *TagsController) localDelete(tag *models.Tag) error { diff --git a/pkg/gui/controllers/toggle_whitespace_action.go b/pkg/gui/controllers/toggle_whitespace_action.go index 41232a769..f5362ddf4 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) @@ -28,5 +28,5 @@ func (self *ToggleWhitespaceAction) Call() error { self.c.GetAppState().IgnoreWhitespaceInDiffView = !self.c.GetAppState().IgnoreWhitespaceInDiffView self.c.SaveAppStateAndLogError() - return self.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{}) + return self.c.Context().CurrentSide().HandleFocus(types.OnFocusOpts{}) } diff --git a/pkg/gui/extras_panel.go b/pkg/gui/extras_panel.go index 1d42f3c92..e3d8998d6 100644 --- a/pkg/gui/extras_panel.go +++ b/pkg/gui/extras_panel.go @@ -15,9 +15,9 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error { { Label: gui.c.Tr.ToggleShowCommandLog, OnPress: func() error { - currentContext := gui.c.CurrentStaticContext() + currentContext := gui.c.Context().CurrentStatic() if gui.c.State().GetShowExtrasWindow() && currentContext.GetKey() == context.COMMAND_LOG_CONTEXT_KEY { - if err := gui.c.PopContext(); err != nil { + if err := gui.c.Context().Pop(); err != nil { return err } } @@ -39,8 +39,8 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error { func (gui *Gui) handleFocusCommandLog() error { gui.c.State().SetShowExtrasWindow(true) // TODO: is this necessary? Can't I just call 'return from context'? - gui.State.Contexts.CommandLog.SetParentContext(gui.c.CurrentSideContext()) - return gui.c.PushContext(gui.State.Contexts.CommandLog) + gui.State.Contexts.CommandLog.SetParentContext(gui.c.Context().CurrentSide()) + return gui.c.Context().Push(gui.State.Contexts.CommandLog) } func (gui *Gui) scrollUpExtra() error { diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index fd9540ea8..98089321e 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() @@ -128,7 +128,7 @@ func (gui *Gui) handleCopySelectedSideContextItemCommitHashToClipboard() error { func (gui *Gui) handleCopySelectedSideContextItemToClipboardWithTruncation(maxWidth int) error { // important to note that this assumes we've selected an item in a side context - currentSideContext := gui.c.CurrentSideContext() + currentSideContext := gui.c.Context().CurrentSide() if currentSideContext == nil { return nil } @@ -162,7 +162,7 @@ func (gui *Gui) handleCopySelectedSideContextItemToClipboardWithTruncation(maxWi func (gui *Gui) getCopySelectedSideContextItemToClipboardDisabledReason() *types.DisabledReason { // important to note that this assumes we've selected an item in a side context - currentSideContext := gui.c.CurrentSideContext() + currentSideContext := gui.c.Context().CurrentSide() if currentSideContext == nil { // This should never happen but if it does we'll just ignore the keypress return nil diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 66fe5cb9c..b65dd80e0 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -335,7 +335,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context } } - if err := gui.c.PushContext(contextToPush); err != nil { + if err := gui.c.Context().Push(contextToPush); err != nil { return err } @@ -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 8a537f2ca..2b132c3d1 100644 --- a/pkg/gui/gui_common.go +++ b/pkg/gui/gui_common.go @@ -45,42 +45,6 @@ func (self *guiCommon) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) { return self.gui.runSubprocessWithSuspense(cmdObj) } -func (self *guiCommon) PushContext(context types.Context, opts ...types.OnFocusOpts) error { - return self.gui.State.ContextMgr.Push(context, opts...) -} - -func (self *guiCommon) PopContext() error { - return self.gui.State.ContextMgr.Pop() -} - -func (self *guiCommon) ReplaceContext(context types.Context) error { - return self.gui.State.ContextMgr.Replace(context) -} - -func (self *guiCommon) RemoveContexts(contexts []types.Context) error { - return self.gui.State.ContextMgr.RemoveContexts(contexts) -} - -func (self *guiCommon) CurrentContext() types.Context { - return self.gui.State.ContextMgr.Current() -} - -func (self *guiCommon) CurrentStaticContext() types.Context { - return self.gui.State.ContextMgr.CurrentStatic() -} - -func (self *guiCommon) CurrentSideContext() types.Context { - return self.gui.State.ContextMgr.CurrentSide() -} - -func (self *guiCommon) CurrentPopupContexts() []types.Context { - return self.gui.State.ContextMgr.PopupContexts() -} - -func (self *guiCommon) IsCurrentContext(c types.Context) bool { - return self.gui.State.ContextMgr.IsCurrent(c) -} - func (self *guiCommon) Context() types.IContextMgr { return self.gui.State.ContextMgr } @@ -89,10 +53,6 @@ func (self *guiCommon) ContextForKey(key types.ContextKey) types.Context { return self.gui.State.ContextMgr.ContextForKey(key) } -func (self *guiCommon) ActivateContext(context types.Context) error { - return self.gui.State.ContextMgr.ActivateContext(context, types.OnFocusOpts{}) -} - func (self *guiCommon) GetAppState() *config.AppState { return self.gui.Config.GetAppState() } 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..ff7923117 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -211,8 +211,8 @@ func (gui *Gui) onInitialViewsCreationForRepo() error { } } - initialContext := gui.c.CurrentContext() - if err := gui.c.ActivateContext(initialContext); err != nil { + initialContext := gui.c.Context().Current() + if err := gui.c.Context().Activate(initialContext, types.OnFocusOpts{}); err != nil { return err } diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index ca03ea69e..e21e32428 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -60,5 +60,5 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error { _ = gui.c.PostRefreshUpdate(gui.State.Contexts.Menu) // TODO: ensure that if we're opened a menu from within a menu that it renders correctly - return gui.c.PushContext(gui.State.Contexts.Menu) + return gui.c.Context().Push(gui.State.Contexts.Menu) } 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 c6885d717..b4a731c59 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -57,24 +57,9 @@ type IGuiCommon interface { RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) RunSubprocessAndRefresh(oscommands.ICmdObj) error - PushContext(context Context, opts ...OnFocusOpts) error - PopContext() error - ReplaceContext(context Context) error - // Removes all given contexts from the stack. If a given context is not in the stack, it is ignored. - // This is for when you have a group of contexts that are bundled together e.g. with the commit message panel. - // If you want to remove a single context, you should probably use PopContext instead. - RemoveContexts([]Context) error - CurrentContext() Context - CurrentStaticContext() Context - CurrentSideContext() Context - CurrentPopupContexts() []Context - IsCurrentContext(Context) bool - // TODO: replace the above context-based methods with just using Context() e.g. replace PushContext() with Context().Push() Context() IContextMgr ContextForKey(key ContextKey) Context - ActivateContext(context Context) error - GetConfig() config.AppConfigurer GetAppState() *config.AppState SaveAppState() error diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index 70458c16f..49a6e6e35 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -35,8 +35,7 @@ const ( type ParentContexter interface { SetParentContext(Context) - // we return a bool here to tell us whether or not the returned value just wraps a nil - GetParentContext() (Context, bool) + GetParentContext() Context } type NeedsRerenderOnWidthChangeLevel int @@ -279,9 +278,11 @@ type IContextMgr interface { Push(context Context, opts ...OnFocusOpts) error Pop() error Replace(context Context) error + Activate(context Context, opts OnFocusOpts) error Current() Context CurrentStatic() Context CurrentSide() Context + CurrentPopup() []Context IsCurrent(c Context) bool ForEach(func(Context)) AllList() []IListContext diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 1043920ec..19eb37783 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -78,7 +78,7 @@ func (gui *Gui) onViewTabClick(windowName string, tabIndex int) error { return nil } - return gui.c.PushContext(context) + return gui.c.Context().Push(context) } func (gui *Gui) handleNextTab() error { @@ -119,7 +119,7 @@ func (gui *Gui) handlePrevTab() error { func getTabbedView(gui *Gui) *gocui.View { // It safe assumption that only static contexts have tabs - context := gui.c.CurrentStaticContext() + context := gui.c.Context().CurrentStatic() view, _ := gui.g.View(context.GetViewName()) return view }