Skip to content

Commit b3215a7

Browse files
committed
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.
1 parent 9c98fd8 commit b3215a7

29 files changed

+36
-46
lines changed

pkg/gui/context.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,7 @@ func (self *ContextMgr) Replace(c types.Context) {
5555
self.Activate(c, types.OnFocusOpts{})
5656
}
5757

58-
func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) {
59-
if len(opts) > 1 {
60-
panic("cannot pass multiple opts to Push")
61-
}
62-
63-
singleOpts := types.OnFocusOpts{}
64-
if len(opts) > 0 {
65-
// using triple dot but you should only ever pass one of these opt structs
66-
singleOpts = opts[0]
67-
}
68-
58+
func (self *ContextMgr) Push(c types.Context, opts types.OnFocusOpts) {
6959
if !c.IsFocusable() {
7060
return
7161
}
@@ -77,7 +67,7 @@ func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) {
7767
}
7868

7969
if contextToActivate != nil {
80-
self.Activate(contextToActivate, singleOpts)
70+
self.Activate(contextToActivate, opts)
8171
}
8272
}
8373

pkg/gui/controllers/custom_patch_options_menu_action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
213213
if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil {
214214
return err
215215
}
216-
self.c.Context().Push(self.c.Contexts().LocalCommits)
216+
self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{})
217217
return nil
218218
})
219219
},

pkg/gui/controllers/filtering_menu_action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (self *FilteringMenuAction) setFiltering() error {
120120
repoState.SetScreenMode(types.SCREEN_HALF)
121121
}
122122

123-
self.c.Context().Push(self.c.Contexts().LocalCommits)
123+
self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{})
124124

125125
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() error {
126126
self.c.Contexts().LocalCommits.SetSelection(0)

pkg/gui/controllers/helpers/commits_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp
150150

151151
self.UpdateCommitPanelView(opts.InitialMessage)
152152

153-
self.c.Context().Push(self.c.Contexts().CommitMessage)
153+
self.c.Context().Push(self.c.Contexts().CommitMessage, types.OnFocusOpts{})
154154
}
155155

156156
func (self *CommitsHelper) OnCommitSuccess() {

pkg/gui/controllers/helpers/confirmation_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ
177177

178178
self.c.State().GetRepoState().SetCurrentPopupOpts(&opts)
179179

180-
self.c.Context().Push(self.c.Contexts().Confirmation)
180+
self.c.Context().Push(self.c.Contexts().Confirmation, types.OnFocusOpts{})
181181
}
182182

183183
func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) {

pkg/gui/controllers/helpers/fixup_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
137137
}
138138

139139
self.c.Contexts().LocalCommits.SetSelection(index)
140-
self.c.Context().Push(self.c.Contexts().LocalCommits)
140+
self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{})
141141
return nil
142142
}
143143

pkg/gui/controllers/helpers/merge_and_rebase_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func (self *MergeAndRebaseHelper) PromptForConflictHandling() error {
206206
{
207207
Label: self.c.Tr.ViewConflictsMenuItem,
208208
OnPress: func() error {
209-
self.c.Context().Push(self.c.Contexts().Files)
209+
self.c.Context().Push(self.c.Contexts().Files, types.OnFocusOpts{})
210210
return nil
211211
},
212212
},
@@ -357,7 +357,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
357357
if err = self.ResetMarkedBaseCommit(); err != nil {
358358
return err
359359
}
360-
self.c.Context().Push(self.c.Contexts().LocalCommits)
360+
self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{})
361361
return nil
362362
},
363363
},

pkg/gui/controllers/helpers/merge_conflicts_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (self *MergeConflictsHelper) EscapeMerge() error {
6262
// files context over it.
6363
// So long as both places call OnUIThread, we're fine.
6464
if self.c.Context().IsCurrent(self.c.Contexts().MergeConflicts) {
65-
self.c.Context().Push(self.c.Contexts().Files)
65+
self.c.Context().Push(self.c.Contexts().Files, types.OnFocusOpts{})
6666
}
6767
return nil
6868
})
@@ -93,7 +93,7 @@ func (self *MergeConflictsHelper) SwitchToMerge(path string) error {
9393
}
9494
}
9595

96-
self.c.Context().Push(self.c.Contexts().MergeConflicts)
96+
self.c.Context().Push(self.c.Contexts().MergeConflicts, types.OnFocusOpts{})
9797
return nil
9898
}
9999

pkg/gui/controllers/helpers/refs_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchN
118118
// Switch to the branches context _before_ starting to check out the
119119
// branch, so that we see the inline status
120120
if self.c.Context().Current() != self.c.Contexts().Branches {
121-
self.c.Context().Push(self.c.Contexts().Branches)
121+
self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{})
122122
}
123123
return self.CheckoutRef(branchName, types.CheckoutRefOptions{})
124124
}
@@ -334,7 +334,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
334334

335335
refresh := func() error {
336336
if self.c.Context().Current() != self.c.Contexts().Branches {
337-
self.c.Context().Push(self.c.Contexts().Branches)
337+
self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{})
338338
}
339339

340340
self.c.Contexts().LocalCommits.SetSelection(0)

pkg/gui/controllers/helpers/search_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (self *SearchHelper) OpenFilterPrompt(context types.IFilterableContext) err
4141
self.OnPromptContentChanged("")
4242
promptView.RenderTextArea()
4343

44-
self.c.Context().Push(self.c.Contexts().Search)
44+
self.c.Context().Push(self.c.Contexts().Search, types.OnFocusOpts{})
4545

4646
return self.c.ResetKeybindings()
4747
}
@@ -58,7 +58,7 @@ func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) err
5858
promptView.ClearTextArea()
5959
promptView.RenderTextArea()
6060

61-
self.c.Context().Push(self.c.Contexts().Search)
61+
self.c.Context().Push(self.c.Contexts().Search, types.OnFocusOpts{})
6262

6363
return self.c.ResetKeybindings()
6464
}

0 commit comments

Comments
 (0)