From b3215a750c0ffdf09935ac7d0809ac731a2e7c22 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 10 Oct 2024 14:35:28 +0200 Subject: [PATCH] Cleanup: get rid of the variadic parameter of ContextMgr.Push Apparently this was an attempt at working around go's lack of default arguments, but it's very unidiomatic and a bit confusing. Make it a normal parameter instead, so all clients have to pass it explicitly. --- pkg/gui/context.go | 14 ++------------ .../custom_patch_options_menu_action.go | 2 +- pkg/gui/controllers/filtering_menu_action.go | 2 +- pkg/gui/controllers/helpers/commits_helper.go | 2 +- pkg/gui/controllers/helpers/confirmation_helper.go | 2 +- pkg/gui/controllers/helpers/fixup_helper.go | 2 +- .../controllers/helpers/merge_and_rebase_helper.go | 4 ++-- .../controllers/helpers/merge_conflicts_helper.go | 4 ++-- pkg/gui/controllers/helpers/refs_helper.go | 4 ++-- pkg/gui/controllers/helpers/search_helper.go | 4 ++-- pkg/gui/controllers/helpers/staging_helper.go | 2 +- pkg/gui/controllers/helpers/sub_commits_helper.go | 2 +- .../controllers/jump_to_side_window_controller.go | 2 +- pkg/gui/controllers/list_controller.go | 2 +- pkg/gui/controllers/quit_actions.go | 2 +- pkg/gui/controllers/remotes_controller.go | 2 +- pkg/gui/controllers/side_window_controller.go | 4 ++-- pkg/gui/controllers/snake_controller.go | 2 +- pkg/gui/controllers/staging_controller.go | 2 +- pkg/gui/controllers/stash_controller.go | 4 ++-- pkg/gui/controllers/status_controller.go | 2 +- pkg/gui/controllers/submodules_controller.go | 2 +- .../controllers/switch_to_diff_files_controller.go | 2 +- pkg/gui/controllers/tags_controller.go | 2 +- pkg/gui/extras_panel.go | 2 +- pkg/gui/gui.go | 2 +- pkg/gui/menu_panel.go | 2 +- pkg/gui/types/context.go | 2 +- pkg/gui/view_helpers.go | 2 +- 29 files changed, 36 insertions(+), 46 deletions(-) diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 36f4e9dda..ca5727d38 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -55,17 +55,7 @@ func (self *ContextMgr) Replace(c types.Context) { self.Activate(c, types.OnFocusOpts{}) } -func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) { - if len(opts) > 1 { - panic("cannot pass multiple opts to Push") - } - - singleOpts := types.OnFocusOpts{} - if len(opts) > 0 { - // using triple dot but you should only ever pass one of these opt structs - singleOpts = opts[0] - } - +func (self *ContextMgr) Push(c types.Context, opts types.OnFocusOpts) { if !c.IsFocusable() { return } @@ -77,7 +67,7 @@ func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) { } if contextToActivate != nil { - self.Activate(contextToActivate, singleOpts) + self.Activate(contextToActivate, opts) } } diff --git a/pkg/gui/controllers/custom_patch_options_menu_action.go b/pkg/gui/controllers/custom_patch_options_menu_action.go index 04895ed6b..ced98b072 100644 --- a/pkg/gui/controllers/custom_patch_options_menu_action.go +++ b/pkg/gui/controllers/custom_patch_options_menu_action.go @@ -213,7 +213,7 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error { if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil { return err } - self.c.Context().Push(self.c.Contexts().LocalCommits) + self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{}) return nil }) }, diff --git a/pkg/gui/controllers/filtering_menu_action.go b/pkg/gui/controllers/filtering_menu_action.go index 0f0f9ceec..f509e607a 100644 --- a/pkg/gui/controllers/filtering_menu_action.go +++ b/pkg/gui/controllers/filtering_menu_action.go @@ -120,7 +120,7 @@ func (self *FilteringMenuAction) setFiltering() error { repoState.SetScreenMode(types.SCREEN_HALF) } - self.c.Context().Push(self.c.Contexts().LocalCommits) + self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{}) return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() error { self.c.Contexts().LocalCommits.SetSelection(0) diff --git a/pkg/gui/controllers/helpers/commits_helper.go b/pkg/gui/controllers/helpers/commits_helper.go index 9c89da706..27aafd7fc 100644 --- a/pkg/gui/controllers/helpers/commits_helper.go +++ b/pkg/gui/controllers/helpers/commits_helper.go @@ -150,7 +150,7 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp self.UpdateCommitPanelView(opts.InitialMessage) - self.c.Context().Push(self.c.Contexts().CommitMessage) + self.c.Context().Push(self.c.Contexts().CommitMessage, types.OnFocusOpts{}) } func (self *CommitsHelper) OnCommitSuccess() { diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index 6e45087c0..20b224f4d 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -177,7 +177,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ self.c.State().GetRepoState().SetCurrentPopupOpts(&opts) - self.c.Context().Push(self.c.Contexts().Confirmation) + self.c.Context().Push(self.c.Contexts().Confirmation, types.OnFocusOpts{}) } func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) { diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index 4d4709cf8..2c320ef53 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) - self.c.Context().Push(self.c.Contexts().LocalCommits) + self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index 04592519b..fba0b9014 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -206,7 +206,7 @@ func (self *MergeAndRebaseHelper) PromptForConflictHandling() error { { Label: self.c.Tr.ViewConflictsMenuItem, OnPress: func() error { - self.c.Context().Push(self.c.Contexts().Files) + self.c.Context().Push(self.c.Contexts().Files, types.OnFocusOpts{}) return nil }, }, @@ -357,7 +357,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error { if err = self.ResetMarkedBaseCommit(); err != nil { return err } - self.c.Context().Push(self.c.Contexts().LocalCommits) + self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{}) return nil }, }, diff --git a/pkg/gui/controllers/helpers/merge_conflicts_helper.go b/pkg/gui/controllers/helpers/merge_conflicts_helper.go index d1f705be9..6e6a01531 100644 --- a/pkg/gui/controllers/helpers/merge_conflicts_helper.go +++ b/pkg/gui/controllers/helpers/merge_conflicts_helper.go @@ -62,7 +62,7 @@ func (self *MergeConflictsHelper) EscapeMerge() error { // files context over it. // So long as both places call OnUIThread, we're fine. if self.c.Context().IsCurrent(self.c.Contexts().MergeConflicts) { - self.c.Context().Push(self.c.Contexts().Files) + self.c.Context().Push(self.c.Contexts().Files, types.OnFocusOpts{}) } return nil }) @@ -93,7 +93,7 @@ func (self *MergeConflictsHelper) SwitchToMerge(path string) error { } } - self.c.Context().Push(self.c.Contexts().MergeConflicts) + self.c.Context().Push(self.c.Contexts().MergeConflicts, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index 02af116b5..fe78c09bd 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -118,7 +118,7 @@ func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchN // Switch to the branches context _before_ starting to check out the // branch, so that we see the inline status if self.c.Context().Current() != self.c.Contexts().Branches { - self.c.Context().Push(self.c.Contexts().Branches) + self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{}) } return self.CheckoutRef(branchName, types.CheckoutRefOptions{}) } @@ -334,7 +334,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest refresh := func() error { if self.c.Context().Current() != self.c.Contexts().Branches { - self.c.Context().Push(self.c.Contexts().Branches) + self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{}) } self.c.Contexts().LocalCommits.SetSelection(0) diff --git a/pkg/gui/controllers/helpers/search_helper.go b/pkg/gui/controllers/helpers/search_helper.go index e685df34a..cc9f22b22 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() - self.c.Context().Push(self.c.Contexts().Search) + self.c.Context().Push(self.c.Contexts().Search, types.OnFocusOpts{}) return self.c.ResetKeybindings() } @@ -58,7 +58,7 @@ func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) err promptView.ClearTextArea() promptView.RenderTextArea() - self.c.Context().Push(self.c.Contexts().Search) + self.c.Context().Push(self.c.Contexts().Search, types.OnFocusOpts{}) return self.c.ResetKeybindings() } diff --git a/pkg/gui/controllers/helpers/staging_helper.go b/pkg/gui/controllers/helpers/staging_helper.go index 69760a193..3d9762541 100644 --- a/pkg/gui/controllers/helpers/staging_helper.go +++ b/pkg/gui/controllers/helpers/staging_helper.go @@ -114,7 +114,7 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) { } func (self *StagingHelper) handleStagingEscape() { - self.c.Context().Push(self.c.Contexts().Files) + self.c.Context().Push(self.c.Contexts().Files, types.OnFocusOpts{}) } func (self *StagingHelper) secondaryStagingFocused() bool { diff --git a/pkg/gui/controllers/helpers/sub_commits_helper.go b/pkg/gui/controllers/helpers/sub_commits_helper.go index a38acd2a7..3e8f88b7d 100644 --- a/pkg/gui/controllers/helpers/sub_commits_helper.go +++ b/pkg/gui/controllers/helpers/sub_commits_helper.go @@ -69,6 +69,6 @@ func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error { self.c.PostRefreshUpdate(self.c.Contexts().SubCommits) - self.c.Context().Push(self.c.Contexts().SubCommits) + self.c.Context().Push(self.c.Contexts().SubCommits, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/controllers/jump_to_side_window_controller.go b/pkg/gui/controllers/jump_to_side_window_controller.go index 0cbbc6c85..c0ef2faec 100644 --- a/pkg/gui/controllers/jump_to_side_window_controller.go +++ b/pkg/gui/controllers/jump_to_side_window_controller.go @@ -56,7 +56,7 @@ func (self *JumpToSideWindowController) goToSideWindow(window string) func() err context := self.c.Helpers().Window.GetContextForWindow(window) - self.c.Context().Push(context) + self.c.Context().Push(context, types.OnFocusOpts{}) return nil } } diff --git a/pkg/gui/controllers/list_controller.go b/pkg/gui/controllers/list_controller.go index 388f805f1..c7a589af4 100644 --- a/pkg/gui/controllers/list_controller.go +++ b/pkg/gui/controllers/list_controller.go @@ -179,7 +179,7 @@ func (self *ListController) HandleClick(opts gocui.ViewMouseBindingOpts) error { func (self *ListController) pushContextIfNotFocused() error { if !self.isFocused() { - self.c.Context().Push(self.context) + self.c.Context().Push(self.context, types.OnFocusOpts{}) } return nil diff --git a/pkg/gui/controllers/quit_actions.go b/pkg/gui/controllers/quit_actions.go index 000fe1792..8d5b0c9ca 100644 --- a/pkg/gui/controllers/quit_actions.go +++ b/pkg/gui/controllers/quit_actions.go @@ -79,7 +79,7 @@ func (self *QuitActions) Escape() error { parentContext := currentContext.GetParentContext() if parentContext != nil { // TODO: think about whether this should be marked as a return rather than adding to the stack - self.c.Context().Push(parentContext) + self.c.Context().Push(parentContext, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go index d8a467eb0..3f4b5a604 100644 --- a/pkg/gui/controllers/remotes_controller.go +++ b/pkg/gui/controllers/remotes_controller.go @@ -129,7 +129,7 @@ func (self *RemotesController) enter(remote *models.Remote) error { self.c.PostRefreshUpdate(remoteBranchesContext) - self.c.Context().Push(remoteBranchesContext) + self.c.Context().Push(remoteBranchesContext, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/controllers/side_window_controller.go b/pkg/gui/controllers/side_window_controller.go index 799c87c2e..2cd421e0e 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) - self.c.Context().Push(context) + self.c.Context().Push(context, types.OnFocusOpts{}) return nil } @@ -93,6 +93,6 @@ func (self *SideWindowController) nextSideWindow() error { context := self.c.Helpers().Window.GetContextForWindow(newWindow) - self.c.Context().Push(context) + self.c.Context().Push(context, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/controllers/snake_controller.go b/pkg/gui/controllers/snake_controller.go index 08dddf1be..a2a2030b7 100644 --- a/pkg/gui/controllers/snake_controller.go +++ b/pkg/gui/controllers/snake_controller.go @@ -73,6 +73,6 @@ func (self *SnakeController) SetDirection(direction snake.Direction) func() erro } func (self *SnakeController) Escape() error { - self.c.Context().Push(self.c.Contexts().Submodules) + self.c.Context().Push(self.c.Contexts().Submodules, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/controllers/staging_controller.go b/pkg/gui/controllers/staging_controller.go index f353cc215..93696a6ec 100644 --- a/pkg/gui/controllers/staging_controller.go +++ b/pkg/gui/controllers/staging_controller.go @@ -180,7 +180,7 @@ func (self *StagingController) Escape() error { func (self *StagingController) TogglePanel() error { if self.otherContext.GetState() != nil { - self.c.Context().Push(self.otherContext) + self.c.Context().Push(self.otherContext, types.OnFocusOpts{}) } return nil diff --git a/pkg/gui/controllers/stash_controller.go b/pkg/gui/controllers/stash_controller.go index 6b88e6849..84dbc456c 100644 --- a/pkg/gui/controllers/stash_controller.go +++ b/pkg/gui/controllers/stash_controller.go @@ -112,7 +112,7 @@ func (self *StashController) handleStashApply(stashEntry *models.StashEntry) err return err } if self.c.UserConfig().Gui.SwitchToFilesAfterStashApply { - self.c.Context().Push(self.c.Contexts().Files) + self.c.Context().Push(self.c.Contexts().Files, types.OnFocusOpts{}) } return nil } @@ -141,7 +141,7 @@ func (self *StashController) handleStashPop(stashEntry *models.StashEntry) error return err } if self.c.UserConfig().Gui.SwitchToFilesAfterStashPop { - self.c.Context().Push(self.c.Contexts().Files) + self.c.Context().Push(self.c.Contexts().Files, types.OnFocusOpts{}) } return nil } diff --git a/pkg/gui/controllers/status_controller.go b/pkg/gui/controllers/status_controller.go index 68028302f..d517b870c 100644 --- a/pkg/gui/controllers/status_controller.go +++ b/pkg/gui/controllers/status_controller.go @@ -104,7 +104,7 @@ func (self *StatusController) onClick(opts gocui.ViewMouseBindingOpts) error { return nil } - self.c.Context().Push(self.Context()) + self.c.Context().Push(self.Context(), types.OnFocusOpts{}) upstreamStatus := utils.Decolorise(presentation.BranchStatus(currentBranch, types.ItemOperationNone, self.c.Tr, time.Now(), self.c.UserConfig())) repoName := self.c.Git().RepoPaths.RepoName() diff --git a/pkg/gui/controllers/submodules_controller.go b/pkg/gui/controllers/submodules_controller.go index eb98c1656..aaeb75251 100644 --- a/pkg/gui/controllers/submodules_controller.go +++ b/pkg/gui/controllers/submodules_controller.go @@ -309,7 +309,7 @@ func (self *SubmodulesController) remove(submodule *models.SubmoduleConfig) erro } func (self *SubmodulesController) easterEgg() error { - self.c.Context().Push(self.c.Contexts().Snake) + self.c.Context().Push(self.c.Contexts().Snake, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index 3580e9227..fc764ca7e 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -91,7 +91,7 @@ func (self *SwitchToDiffFilesController) enter() error { return err } - self.c.Context().Push(commitFilesContext) + self.c.Context().Push(commitFilesContext, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go index 75db8a6a6..664a0f279 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 } - self.c.Context().Push(self.c.Contexts().Branches) + self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/extras_panel.go b/pkg/gui/extras_panel.go index 2319c813a..96fa225d3 100644 --- a/pkg/gui/extras_panel.go +++ b/pkg/gui/extras_panel.go @@ -38,7 +38,7 @@ 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.Context().CurrentSide()) - gui.c.Context().Push(gui.State.Contexts.CommandLog) + gui.c.Context().Push(gui.State.Contexts.CommandLog, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index ff6b68748..42922611a 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -394,7 +394,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context } } - gui.c.Context().Push(contextToPush) + gui.c.Context().Push(contextToPush, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index c9783db69..75fd6700d 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -60,6 +60,6 @@ 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 - gui.c.Context().Push(gui.State.Contexts.Menu) + gui.c.Context().Push(gui.State.Contexts.Menu, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index 5ad8ff3bb..eea207360 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -286,7 +286,7 @@ type ListItem interface { } type IContextMgr interface { - Push(context Context, opts ...OnFocusOpts) + Push(context Context, opts OnFocusOpts) Pop() Replace(context Context) Activate(context Context, opts OnFocusOpts) diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 9b066db4f..624d6e25f 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -72,7 +72,7 @@ func (gui *Gui) onViewTabClick(windowName string, tabIndex int) error { return nil } - gui.c.Context().Push(context) + gui.c.Context().Push(context, types.OnFocusOpts{}) return nil }