diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-31 22:20:28 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-17 19:13:40 +1100 |
commit | 2db463681564e8db945cd6811fc633545ee9fd83 (patch) | |
tree | 40edb17e174fcd8c20429ba8a7559ccc716fcd22 | |
parent | 2a1e3faa0c61cc8c2418310089485dbab268228f (diff) |
no more indirection
-rw-r--r-- | pkg/gui/context_config.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/bisect_controller.go | 12 | ||||
-rw-r--r-- | pkg/gui/controllers/cherry_pick_helper.go | 14 | ||||
-rw-r--r-- | pkg/gui/controllers/files_controller.go | 65 | ||||
-rw-r--r-- | pkg/gui/controllers/local_commits_controller.go | 60 | ||||
-rw-r--r-- | pkg/gui/controllers/menu_controller.go | 14 | ||||
-rw-r--r-- | pkg/gui/controllers/rebase_helper.go | 8 | ||||
-rw-r--r-- | pkg/gui/controllers/refs_helper.go | 26 | ||||
-rw-r--r-- | pkg/gui/controllers/remotes_controller.go | 26 | ||||
-rw-r--r-- | pkg/gui/controllers/tags_controller.go | 28 | ||||
-rw-r--r-- | pkg/gui/gui.go | 32 |
11 files changed, 142 insertions, 147 deletions
diff --git a/pkg/gui/context_config.go b/pkg/gui/context_config.go index c5c2bf544..eec6cdd69 100644 --- a/pkg/gui/context_config.go +++ b/pkg/gui/context_config.go @@ -32,8 +32,8 @@ func (gui *Gui) allContexts() []types.Context { } } -func (gui *Gui) contextTree() context.ContextTree { - return context.ContextTree{ +func (gui *Gui) contextTree() *context.ContextTree { + return &context.ContextTree{ Status: NewSimpleContext( context.NewBaseContext(context.NewBaseContextOpts{ Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index 6befce84c..bb7ba642d 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -13,7 +13,7 @@ import ( type BisectController struct { c *types.ControllerCommon - getContext func() types.IListContext + context types.IListContext git *commands.GitCommand bisectHelper *BisectHelper @@ -25,7 +25,7 @@ var _ types.IController = &BisectController{} func NewBisectController( c *types.ControllerCommon, - getContext func() types.IListContext, + context types.IListContext, git *commands.GitCommand, bisectHelper *BisectHelper, @@ -34,7 +34,7 @@ func NewBisectController( ) *BisectController { return &BisectController{ c: c, - getContext: getContext, + context: context, git: git, bisectHelper: bisectHelper, @@ -232,8 +232,8 @@ func (self *BisectController) selectCurrentBisectCommit() { // find index of commit with that sha, move cursor to that. for i, commit := range self.getCommits() { if commit.Sha == info.GetCurrentSha() { - self.getContext().GetPanelState().SetSelectedLineIdx(i) - _ = self.getContext().HandleFocus() + self.context.GetPanelState().SetSelectedLineIdx(i) + _ = self.context.HandleFocus() break } } @@ -252,5 +252,5 @@ func (self *BisectController) checkSelected(callback func(*models.Commit) error) } func (self *BisectController) Context() types.Context { - return self.getContext() + return self.context } diff --git a/pkg/gui/controllers/cherry_pick_helper.go b/pkg/gui/controllers/cherry_pick_helper.go index 3bce03132..1f6665224 100644 --- a/pkg/gui/controllers/cherry_pick_helper.go +++ b/pkg/gui/controllers/cherry_pick_helper.go @@ -13,8 +13,8 @@ type CherryPickHelper struct { git *commands.GitCommand - getContexts func() context.ContextTree - getData func() *cherrypicking.CherryPicking + contexts *context.ContextTree + getData func() *cherrypicking.CherryPicking rebaseHelper *RebaseHelper } @@ -25,14 +25,14 @@ type CherryPickHelper struct { func NewCherryPickHelper( c *types.ControllerCommon, git *commands.GitCommand, - getContexts func() context.ContextTree, + contexts *context.ContextTree, getData func() *cherrypicking.CherryPicking, rebaseHelper *RebaseHelper, ) *CherryPickHelper { return &CherryPickHelper{ c: c, git: git, - getContexts: getContexts, + contexts: contexts, getData: getData, rebaseHelper: rebaseHelper, } @@ -143,9 +143,9 @@ func (self *CherryPickHelper) resetIfNecessary(context types.Context) error { func (self *CherryPickHelper) rerender() error { for _, context := range []types.Context{ - self.getContexts().BranchCommits, - self.getContexts().ReflogCommits, - self.getContexts().SubCommits, + self.contexts.BranchCommits, + self.contexts.ReflogCommits, + self.contexts.SubCommits, } { if err := self.c.PostRefreshUpdate(context); err != nil { return err diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 57df2e84e..a7c4ff374 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -21,21 +21,20 @@ type FilesController struct { // case I would actually prefer a _zero_ letter variable name in the form of // struct embedding, but Go does not allow hiding public fields in an embedded struct // to the client - c *types.ControllerCommon - getContext func() *context.WorkingTreeContext - getFiles func() []*models.File - git *commands.GitCommand - os *oscommands.OSCommand + c *types.ControllerCommon + context *context.WorkingTreeContext + model *types.Model + git *commands.GitCommand + os *oscommands.OSCommand getSelectedFileNode func() *filetree.FileNode - getContexts func() context.ContextTree + contexts *context.ContextTree enterSubmodule func(submodule *models.SubmoduleConfig) error getSubmodules func() []*models.SubmoduleConfig setCommitMessage func(message string) getCheckedOutBranch func() *models.Branch withGpgHandling func(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error getFailedCommitMessage func() string - getCommits func() []*models.Commit getSelectedPath func() string switchToMergeFn func(path string) error suggestionsHelper ISuggestionsHelper @@ -48,18 +47,17 @@ var _ types.IController = &FilesController{} func NewFilesController( c *types.ControllerCommon, - getContext func() *context.WorkingTreeContext, - getFiles func() []*models.File, + context *context.WorkingTreeContext, + model *types.Model, git *commands.GitCommand, os *oscommands.OSCommand, getSelectedFileNode func() *filetree.FileNode, - allContexts func() context.ContextTree, + allContexts *context.ContextTree, enterSubmodule func(submodule *models.SubmoduleConfig) error, getSubmodules func() []*models.SubmoduleConfig, setCommitMessage func(message string), withGpgHandling func(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error, getFailedCommitMessage func() string, - getCommits func() []*models.Commit, getSelectedPath func() string, switchToMergeFn func(path string) error, suggestionsHelper ISuggestionsHelper, @@ -69,18 +67,17 @@ func NewFilesController( ) *FilesController { return &FilesController{ c: c, - getContext: getContext, - getFiles: getFiles, + context: context, + model: model, git: git, os: os, getSelectedFileNode: getSelectedFileNode, - getContexts: allContexts, + contexts: allContexts, enterSubmodule: enterSubmodule, getSubmodules: getSubmodules, setCommitMessage: setCommitMessage, withGpgHandling: withGpgHandling, getFailedCommitMessage: getFailedCommitMessage, - getCommits: getCommits, getSelectedPath: getSelectedPath, switchToMergeFn: switchToMergeFn, suggestionsHelper: suggestionsHelper, @@ -99,7 +96,7 @@ func (self *FilesController) Keybindings(getKey func(key string) interface{}, co }, { Key: gocui.MouseLeft, - Handler: func() error { return self.getContext().HandleClick(self.checkSelectedFileNode(self.press)) }, + Handler: func() error { return self.context.HandleClick(self.checkSelectedFileNode(self.press)) }, }, { Key: getKey("<c-b>"), // TODO: softcode @@ -198,7 +195,7 @@ func (self *FilesController) Keybindings(getKey func(key string) interface{}, co }, } - return append(bindings, self.getContext().Keybindings(getKey, config, guards)...) + return append(bindings, self.context.Keybindings(getKey, config, guards)...) } func (self *FilesController) press(node *filetree.FileNode) error { @@ -206,7 +203,7 @@ func (self *FilesController) press(node *filetree.FileNode) error { file := node.File if file.HasInlineMergeConflicts { - return self.c.PushContext(self.getContexts().Merging) + return self.c.PushContext(self.contexts.Merging) } if file.HasUnstagedChanges { @@ -245,7 +242,7 @@ func (self *FilesController) press(node *filetree.FileNode) error { return err } - return self.getContext().HandleFocus() + return self.context.HandleFocus() } func (self *FilesController) checkSelectedFileNode(callback func(*filetree.FileNode) error) func() error { @@ -260,7 +257,7 @@ func (self *FilesController) checkSelectedFileNode(callback func(*filetree.FileN } func (self *FilesController) Context() types.Context { - return self.getContext() + return self.context } func (self *FilesController) getSelectedFile() *models.File { @@ -300,11 +297,11 @@ func (self *FilesController) EnterFile(opts types.OnFocusOpts) error { return self.c.ErrorMsg(self.c.Tr.FileStagingRequirements) } - return self.c.PushContext(self.getContexts().Staging, opts) + return self.c.PushContext(self.contexts.Staging, opts) } func (self *FilesController) allFilesStaged() bool { - for _, file := range self.getFiles() { + for _, file := range self.model.Files { if file.HasUnstagedChanges { return false } @@ -329,7 +326,7 @@ func (self *FilesController) stageAll() error { return err } - return self.getContexts().Files.HandleFocus() + return self.contexts.Files.HandleFocus() } func (self *FilesController) ignore(node *filetree.FileNode) error { @@ -434,7 +431,7 @@ func (self *FilesController) HandleCommitPress() error { return self.c.Error(err) } - if len(self.getFiles()) == 0 { + if len(self.model.Files) == 0 { return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle) } @@ -459,7 +456,7 @@ func (self *FilesController) HandleCommitPress() error { } } - if err := self.c.PushContext(self.getContexts().CommitMessage); err != nil { + if err := self.c.PushContext(self.contexts.CommitMessage); err != nil { return err } @@ -485,7 +482,7 @@ func (self *FilesController) promptToStageAllAndRetry(retry func() error) error } func (self *FilesController) handleAmendCommitPress() error { - if len(self.getFiles()) == 0 { + if len(self.model.Files) == 0 { return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle) } @@ -493,7 +490,7 @@ func (self *FilesController) handleAmendCommitPress() error { return self.promptToStageAllAndRetry(self.handleAmendCommitPress) } - if len(self.getCommits()) == 0 { + if len(self.model.Commits) == 0 { return self.c.ErrorMsg(self.c.Tr.NoCommitToAmend) } @@ -511,7 +508,7 @@ func (self *FilesController) handleAmendCommitPress() error { // HandleCommitEditorPress - handle when the user wants to commit changes via // their editor rather than via the popup panel func (self *FilesController) HandleCommitEditorPress() error { - if len(self.getFiles()) == 0 { + if len(self.model.Files) == 0 { return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle) } @@ -552,8 +549,8 @@ func (self *FilesController) handleStatusFilterPressed() error { } func (self *FilesController) setStatusFiltering(filter filetree.FileTreeDisplayFilter) error { - self.getContext().FileTreeViewModel.SetFilter(filter) - return self.c.PostRefreshUpdate(self.getContext()) + self.context.FileTreeViewModel.SetFilter(filter) + return self.c.PostRefreshUpdate(self.context) } func (self *FilesController) edit(node *filetree.FileNode) error { @@ -643,9 +640,9 @@ func (self *FilesController) handleToggleDirCollapsed() error { return nil } - self.getContext().FileTreeViewModel.ToggleCollapsed(node.GetPath()) + self.context.FileTreeViewModel.ToggleCollapsed(node.GetPath()) - if err := self.c.PostRefreshUpdate(self.getContexts().Files); err != nil { + if err := self.c.PostRefreshUpdate(self.contexts.Files); err != nil { self.c.Log.Error(err) } @@ -653,9 +650,9 @@ func (self *FilesController) handleToggleDirCollapsed() error { } func (self *FilesController) toggleTreeView() error { - self.getContext().FileTreeViewModel.ToggleShowTree() + self.context.FileTreeViewModel.ToggleShowTree() - return self.c.PostRefreshUpdate(self.getContext()) + return self.c.PostRefreshUpdate(self.context) } func (self *FilesController) OpenMergeTool() error { diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index bc25411bf..749199c1e 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -24,7 +24,7 @@ type ( type LocalCommitsController struct { c *types.ControllerCommon - getContext func() types.IListContext + context types.IListContext os *oscommands.OSCommand git *commands.GitCommand tagsHelper *TagsHelper @@ -33,7 +33,7 @@ type LocalCommitsController struct { rebaseHelper *RebaseHelper getSelectedLocalCommit func() *models.Commit - getCommits func() []*models.Commit + model *types.Model getSelectedLocalCommitIdx func() int CheckMergeOrRebase CheckMergeOrRebase pullFiles PullFilesFn @@ -49,7 +49,7 @@ var _ types.IController = &LocalCommitsController{} func NewLocalCommitsController( c *types.ControllerCommon, - getContext func() types.IListContext, + context types.IListContext, os *oscommands.OSCommand, git *commands.GitCommand, tagsHelper *TagsHelper, @@ -57,7 +57,7 @@ func NewLocalCommitsController( cherryPickHelper *CherryPickHelper, rebaseHelper *RebaseHelper, getSelectedLocalCommit func() *models.Commit, - getCommits func() []*models.Commit, + model *types.Model, getSelectedLocalCommitIdx func() int, CheckMergeOrRebase CheckMergeOrRebase, pullFiles PullFilesFn, @@ -70,7 +70,7 @@ func NewLocalCommitsController( ) *LocalCommitsController { return &LocalCommitsController{ c: c, - getContext: getContext, + context: context, os: os, git: git, tagsHelper: tagsHelper, @@ -78,7 +78,7 @@ func NewLocalCommitsController( cherryPickHelper: cherryPickHelper, rebaseHelper: rebaseHelper, getSelectedLocalCommit: getSelectedLocalCommit, - getCommits: getCommits, + model: model, getSelectedLocalCommitIdx: getSelectedLocalCommitIdx, CheckMergeOrRebase: CheckMergeOrRebase, pullFiles: pullFiles, @@ -199,7 +199,7 @@ func (self *LocalCommitsController) Keybindings( }, { Key: gocui.MouseLeft, - Handler: func() error { return self.getContext().HandleClick(self.checkSelected(self.enter)) }, + Handler: func() error { return self.context.HandleClick(self.checkSelected(self.enter)) }, }, } @@ -246,11 +246,11 @@ func (self *LocalCommitsController) Keybindings( }, }...) - return append(bindings, self.getContext().Keybindings(getKey, config, guards)...) + return append(bindings, self.context.Keybindings(getKey, config, guards)...) } func (self *LocalCommitsController) squashDown() error { - if len(self.getCommits()) <= 1 { + if len(self.model.Commits) <= 1 { return self.c.ErrorMsg(self.c.Tr.YouNoCommitsToSquash) } @@ -275,7 +275,7 @@ func (self *LocalCommitsController) squashDown() error { } func (self *LocalCommitsController) fixup() error { - if len(self.getCommits()) <= 1 { + if len(self.model.Commits) <= 1 { return self.c.ErrorMsg(self.c.Tr.YouNoCommitsToSquash) } @@ -319,7 +319,7 @@ func (self *LocalCommitsController) reword(commit *models.Commit) error { InitialContent: message, HandleConfirm: func(response string) error { self.c.LogAction(self.c.Tr.Actions.RewordCommit) - if err := self.git.Rebase.RewordCommit(self.getCommits(), self.getSelectedLocalCommitIdx(), response); err != nil { + if err := self.git.Rebase.RewordCommit(self.model.Commits, self.getSelectedLocalCommitIdx(), response); err != nil { return self.c.Error(err) } @@ -339,7 +339,7 @@ func (self *LocalCommitsController) rewordEditor() error { self.c.LogAction(self.c.Tr.Actions.RewordCommit) subProcess, err := self.git.Rebase.RewordCommitInEditor( - self.getCommits(), self.getSelectedLocalCommitIdx(), + self.model.Commits, self.getSelectedLocalCommitIdx(), ) if err != nil { return self.c.Error(err) @@ -402,7 +402,7 @@ func (self *LocalCommitsController) pick() error { } func (self *LocalCommitsController) interactiveRebase(action string) error { - err := self.git.Rebase.InteractiveRebase(self.getCommits(), self.getSelectedLocalCommitIdx(), action) + err := self.git.Rebase.InteractiveRebase(self.model.Commits, self.getSelectedLocalCommitIdx(), action) return self.CheckMergeOrRebase(err) } @@ -441,9 +441,9 @@ func (self *LocalCommitsController) handleMidRebaseCommand(action string) (bool, } func (self *LocalCommitsController) handleCommitMoveDown() error { - index := self.getContext().GetPanelState().GetSelectedLineIdx() - commits := self.getCommits() - selectedCommit := self.getCommits()[index] + index := self.context.GetPanelState().GetSelectedLineIdx() + commits := self.model.Commits + selectedCommit := self.model.Commits[index] if selectedCommit.Status == "rebasing" { if commits[index+1].Status != "rebasing" { return nil @@ -458,7 +458,7 @@ func (self *LocalCommitsController) handleCommitMoveDown() error { return self.c.Error(err) } // TODO: use MoveSelectedLine - _ = self.getContext().HandleNextLine() + _ = self.context.HandleNextLine() return self.c.Refresh(types.RefreshOptions{ Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS}, }) @@ -466,22 +466,22 @@ func (self *LocalCommitsController) handleCommitMoveDown() error { return self.c.WithWaitingStatus(self.c.Tr.MovingStatus, func() error { self.c.LogAction(self.c.Tr.Actions.MoveCommitDown) - err := self.git.Rebase.MoveCommitDown(self.getCommits(), index) + err := self.git.Rebase.MoveCommitDown(self.model.Commits, index) if err == nil { // TODO: use MoveSelectedLine - _ = self.getContext().HandleNextLine() + _ = self.context.HandleNextLine() } return self.CheckMergeOrRebase(err) }) } func (self *LocalCommitsController) handleCommitMoveUp() error { - index := self.getContext().GetPanelState().GetSelectedLineIdx() + index := self.context.GetPanelState().GetSelectedLineIdx() if index == 0 { return nil } - selectedCommit := self.getCommits()[index] + selectedCommit := self.model.Commits[index] if selectedCommit.Status == "rebasing" { // logging directly here because MoveTodoDown doesn't have enough information // to provide a useful log @@ -494,7 +494,7 @@ func (self *LocalCommitsController) handleCommitMoveUp() error { if err := self.git.Rebase.MoveTodoDown(index - 1); err != nil { return self.c.Error(err) } - _ = self.getContext().HandlePrevLine() + _ = self.context.HandlePrevLine() return self.c.Refresh(types.RefreshOptions{ Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS}, }) @@ -502,9 +502,9 @@ func (self *LocalCommitsController) handleCommitMoveUp() error { return self.c.WithWaitingStatus(self.c.Tr.MovingStatus, func() error { self.c.LogAction(self.c.Tr.Actions.MoveCommitUp) - err := self.git.Rebase.MoveCommitDown(self.getCommits(), index-1) + err := self.git.Rebase.MoveCommitDown(self.model.Commits, index-1) if err == nil { - _ = self.getContext().HandlePrevLine() + _ = self.context.HandlePrevLine() } return self.CheckMergeOrRebase(err) }) @@ -572,7 +572,7 @@ func (self *LocalCommitsController) createRevertMergeCommitMenu(commit *models.C } func (self *LocalCommitsController) afterRevertCommit() error { - _ = self.getContext().HandleNextLine() + _ = self.context.HandleNextLine() return self.c.Refresh(types.RefreshOptions{ Mode: types.BLOCK_UI, Scope: []types.RefreshableView{types.COMMITS, types.BRANCHES}, }) @@ -582,7 +582,7 @@ func (self *LocalCommitsController) enter(commit *models.Commit) error { return self.switchToCommitFilesContext(SwitchToCommitFilesContextOpts{ RefName: commit.Sha, CanRebase: true, - Context: self.getContext(), + Context: self.context, WindowName: "commits", }) } @@ -672,7 +672,7 @@ func (self *LocalCommitsController) gotoBottom() error { } } - _ = self.getContext().HandleGotoBottom() + _ = self.context.HandleGotoBottom() return nil } @@ -804,7 +804,7 @@ func (self *LocalCommitsController) checkSelected(callback func(*models.Commit) } func (self *LocalCommitsController) Context() types.Context { - return self.getContext() + return self.context } func (self *LocalCommitsController) newBranch(commit *models.Commit) error { @@ -812,11 +812,11 @@ func (self *LocalCommitsController) newBranch(commit *models.Commit) error { } func (self *LocalCommitsController) copy(commit *models.Commit) error { - return self.cherryPickHelper.Copy(commit, self.getCommits(), self.getContext()) + return self.cherryPickHelper.Copy(commit, self.model.Commits, self.context) } func (self *LocalCommitsController) copyRange(*models.Commit) error { - return self.cherryPickHelper.CopyRange(self.getContext().GetPanelState().GetSelectedLineIdx(), self.getCommits(), self.getContext()) + return self.cherryPickHelper.CopyRange(self.context.GetPanelState().GetSelectedLineIdx(), self.model.Commits, self.context) } func (self *LocalCommitsController) paste() error { diff --git a/pkg/gui/controllers/menu_controller.go b/pkg/gui/controllers/menu_controller.go index e03666ad5..7773a0148 100644 --- a/pkg/gui/controllers/menu_controller.go +++ b/pkg/gui/controllers/menu_controller.go @@ -7,8 +7,8 @@ import ( ) type MenuController struct { - c *types.ControllerCommon - getContext func() types.IListContext + c *types.ControllerCommon + context types.IListContext getSelectedMenuItem func() *types.MenuItem } @@ -17,12 +17,12 @@ var _ types.IController = &MenuController{} func NewMenuController( c *types.ControllerCommon, - getContext func() types.IListContext, + context types.IListContext, getSelectedMenuItem func() *types.MenuItem, ) *MenuController { return &MenuController{ c: c, - getContext: getContext, + context: context, getSelectedMenuItem: getSelectedMenuItem, } } @@ -43,11 +43,11 @@ func (self *MenuController) Keybindings(getKey func(key string) interface{}, con }, { Key: gocui.MouseLeft, - Handler: func() error { return self.getContext().HandleClick(self.press) }, + Handler: func() error { return self.context.HandleClick(self.press) }, }, } - return append(bindings, self.getContext().Keybindings(getKey, config, guards)...) + return append(bindings, self.context.Keybindings(getKey, config, guards)...) } func (self *MenuController) press() error { @@ -65,5 +65,5 @@ func (self *MenuController) press() error { } func (self *MenuController) Context() types.Context { - return self.getContext() + return self.context } diff --git a/pkg/gui/controllers/rebase_helper.go b/pkg/gui/controllers/rebase_helper.go index 6515895c1..036af31e0 100644 --- a/pkg/gui/controllers/rebase_helper.go +++ b/pkg/gui/controllers/rebase_helper.go @@ -12,20 +12,20 @@ import ( type RebaseHelper struct { c *types.ControllerCommon - getContexts func() context.ContextTree + contexts *context.ContextTree git *commands.GitCommand takeOverMergeConflictScrolling func() } func NewRebaseHelper( c *types.ControllerCommon, - getContexts func() context.ContextTree, + contexts *context.ContextTree, git *commands.GitCommand, takeOverMergeConflictScrolling func(), ) *RebaseHelper { return &RebaseHelper{ c: c, - getContexts: getContexts, + contexts: contexts, git: git, takeOverMergeConflictScrolling: takeOverMergeConflictScrolling, } @@ -139,7 +139,7 @@ func (self *RebaseHelper) CheckMergeOrRebase(result error) error { Prompt: self.c.Tr.FoundConflicts, HandlersManageFocus: true, HandleConfirm: func() error { - return self.c.PushContext(self.getContexts().Files) + return self.c.PushContext(self.contexts.Files) }, HandleClose: func() error { if err := self.c.PopContext(); err != nil { diff --git a/pkg/gui/controllers/refs_helper.go b/pkg/gui/controllers/refs_helper.go index 2bb1868e0..8d56ec0d7 100644 --- a/pkg/gui/controllers/refs_helper.go +++ b/pkg/gui/controllers/refs_helper.go @@ -22,20 +22,20 @@ type IRefsHelper interface { type RefsHelper struct { c *types.ControllerCommon git *commands.GitCommand - getContexts func() context.ContextTree + contexts *context.ContextTree limitCommits func() } func NewRefsHelper( c *types.ControllerCommon, git *commands.GitCommand, - getContexts func() context.ContextTree, + contexts *context.ContextTree, limitCommits func(), ) *RefsHelper { return &RefsHelper{ c: c, git: git, - getContexts: getContexts, + contexts: contexts, limitCommits: limitCommits, } } @@ -51,9 +51,9 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions cmdOptions := git_commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars} onSuccess := func() { - self.getContexts().Branches.GetPanelState().SetSelectedLineIdx(0) - self.getContexts().BranchCommits.GetPanelState().SetSelectedLineIdx(0) - self.getContexts().ReflogCommits.GetPanelState().SetSelectedLineIdx(0) + self.contexts.Branches.GetPanelState().SetSelectedLineIdx(0) + self.contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0) + self.contexts.ReflogCommits.GetPanelState().SetSelectedLineIdx(0) // loading a heap of commits is slow so we limit them whenever doing a reset self.limitCommits() } @@ -107,12 +107,12 @@ func (self *RefsHelper) ResetToRef(ref string, strength string, envVars []string return self.c.Error(err) } - self.getContexts().BranchCommits.GetPanelState().SetSelectedLineIdx(0) - self.getContexts().ReflogCommits.GetPanelState().SetSelectedLineIdx(0) + self.contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0) + self.contexts.ReflogCommits.GetPanelState().SetSelectedLineIdx(0) // loading a heap of commits is slow so we limit them whenever doing a reset self.limitCommits() - if err := self.c.PushContext(self.getContexts().BranchCommits); err != nil { + if err := self.c.PushContext(self.contexts.BranchCommits); err != nil { return err } @@ -163,14 +163,14 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest return err } - if self.c.CurrentContext() != self.getContexts().Branches { - if err := self.c.PushContext(self.getContexts().Branches); err != nil { + if self.c.CurrentContext() != self.contexts.Branches { + if err := self.c.PushContext(self.contexts.Branches); err != nil { return err } } - self.getContexts().BranchCommits.GetPanelState().SetSelectedLineIdx(0) - self.getContexts().Branches.GetPanelState().SetSelectedLineIdx(0) + self.contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0) + self.contexts.Branches.GetPanelState().SetSelectedLineIdx(0) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) }, diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go index bc91f40e7..d9812d213 100644 --- a/pkg/gui/controllers/remotes_controller.go +++ b/pkg/gui/controllers/remotes_controller.go @@ -11,30 +11,30 @@ import ( ) type RemotesController struct { - c *types.ControllerCommon - getContext func() types.IListContext - git *commands.GitCommand + c *types.ControllerCommon + context types.IListContext + git *commands.GitCommand getSelectedRemote func() *models.Remote setRemoteBranches func([]*models.RemoteBranch) - getContexts func() context.ContextTree + contexts *context.ContextTree } var _ types.IController = &RemotesController{} func NewRemotesController( c *types.ControllerCommon, - getContext func() types.IListContext, + context types.IListContext, git *commands.GitCommand, - getContexts func() context.ContextTree, + contexts *context.ContextTree, getSelectedRemote func() *models.Remote, setRemoteBranches func([]*models.RemoteBranch), ) *RemotesController { return &RemotesController{ c: c, git: git, - getContexts: getContexts, - getContext: getContext, + contexts: contexts, + context: context, getSelectedRemote: getSelectedRemote, setRemoteBranches: setRemoteBranches, } @@ -48,7 +48,7 @@ func (self *RemotesController) Keybindings(getKey func(key string) interface{}, }, { Key: gocui.MouseLeft, - Handler: func() error { return self.getContext().HandleClick(self.checkSelected(self.enter)) }, + Handler: func() error { return self.context.HandleClick(self.checkSelected(self.enter)) }, }, { Key: getKey(config.Branches.FetchRemote), @@ -72,7 +72,7 @@ func (self *RemotesController) Keybindings(getKey func(key string) interface{}, }, } - return append(bindings, self.getContext().Keybindings(getKey, config, guards)...) + return append(bindings, self.context.Keybindings(getKey, config, guards)...) } func (self *RemotesController) enter(remote *models.Remote) error { @@ -83,9 +83,9 @@ func (self *RemotesController) enter(remote *models.Remote) error { if len(remote.Branches) == 0 { newSelectedLine = -1 } - self.getContexts().RemoteBranches.GetPanelState().SetSelectedLineIdx(newSelectedLine) + self.contexts.RemoteBranches.GetPanelState().SetSelectedLineIdx(newSelectedLi |