mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-31 23:19:40 +02:00
no more indirection
This commit is contained in:
parent
2a1e3faa0c
commit
2db4636815
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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})
|
||||
},
|
||||
|
@ -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(newSelectedLine)
|
||||
|
||||
return self.c.PushContext(self.getContexts().RemoteBranches)
|
||||
return self.c.PushContext(self.contexts.RemoteBranches)
|
||||
}
|
||||
|
||||
func (self *RemotesController) add() error {
|
||||
@ -191,5 +191,5 @@ func (self *RemotesController) checkSelected(callback func(*models.Remote) error
|
||||
}
|
||||
|
||||
func (self *RemotesController) Context() types.Context {
|
||||
return self.getContext()
|
||||
return self.context
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ import (
|
||||
)
|
||||
|
||||
type TagsController struct {
|
||||
c *types.ControllerCommon
|
||||
getContext func() *context.TagsContext
|
||||
git *commands.GitCommand
|
||||
getContexts func() context.ContextTree
|
||||
tagsHelper *TagsHelper
|
||||
c *types.ControllerCommon
|
||||
context *context.TagsContext
|
||||
git *commands.GitCommand
|
||||
contexts *context.ContextTree
|
||||
tagsHelper *TagsHelper
|
||||
|
||||
refsHelper IRefsHelper
|
||||
suggestionsHelper ISuggestionsHelper
|
||||
@ -26,9 +26,9 @@ var _ types.IController = &TagsController{}
|
||||
|
||||
func NewTagsController(
|
||||
c *types.ControllerCommon,
|
||||
getContext func() *context.TagsContext,
|
||||
context *context.TagsContext,
|
||||
git *commands.GitCommand,
|
||||
getContexts func() context.ContextTree,
|
||||
contexts *context.ContextTree,
|
||||
tagsHelper *TagsHelper,
|
||||
refsHelper IRefsHelper,
|
||||
suggestionsHelper ISuggestionsHelper,
|
||||
@ -37,9 +37,9 @@ func NewTagsController(
|
||||
) *TagsController {
|
||||
return &TagsController{
|
||||
c: c,
|
||||
getContext: getContext,
|
||||
context: context,
|
||||
git: git,
|
||||
getContexts: getContexts,
|
||||
contexts: contexts,
|
||||
tagsHelper: tagsHelper,
|
||||
refsHelper: refsHelper,
|
||||
suggestionsHelper: suggestionsHelper,
|
||||
@ -83,7 +83,7 @@ func (self *TagsController) Keybindings(getKey func(key string) interface{}, con
|
||||
},
|
||||
}
|
||||
|
||||
return append(bindings, self.getContext().Keybindings(getKey, config, guards)...)
|
||||
return append(bindings, self.context.Keybindings(getKey, config, guards)...)
|
||||
}
|
||||
|
||||
func (self *TagsController) checkout(tag *models.Tag) error {
|
||||
@ -91,7 +91,7 @@ func (self *TagsController) checkout(tag *models.Tag) error {
|
||||
if err := self.refsHelper.CheckoutRef(tag.Name, types.CheckoutRefOptions{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return self.c.PushContext(self.getContexts().Branches)
|
||||
return self.c.PushContext(self.contexts.Branches)
|
||||
}
|
||||
|
||||
func (self *TagsController) enter(tag *models.Tag) error {
|
||||
@ -151,12 +151,12 @@ func (self *TagsController) createResetMenu(tag *models.Tag) error {
|
||||
|
||||
func (self *TagsController) create() error {
|
||||
// leaving commit SHA blank so that we're just creating the tag for the current commit
|
||||
return self.tagsHelper.CreateTagMenu("", func() { self.getContext().GetPanelState().SetSelectedLineIdx(0) })
|
||||
return self.tagsHelper.CreateTagMenu("", func() { self.context.GetPanelState().SetSelectedLineIdx(0) })
|
||||
}
|
||||
|
||||
func (self *TagsController) withSelectedTag(f func(tag *models.Tag) error) func() error {
|
||||
return func() error {
|
||||
tag := self.getContext().GetSelectedTag()
|
||||
tag := self.context.GetSelectedTag()
|
||||
if tag == nil {
|
||||
return nil
|
||||
}
|
||||
@ -166,5 +166,5 @@ func (self *TagsController) withSelectedTag(f func(tag *models.Tag) error) func(
|
||||
}
|
||||
|
||||
func (self *TagsController) Context() types.Context {
|
||||
return self.getContext()
|
||||
return self.context
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ type GuiRepoState struct {
|
||||
|
||||
MainContext types.ContextKey // used to keep the main and secondary views' contexts in sync
|
||||
ContextManager ContextManager
|
||||
Contexts context.ContextTree
|
||||
Contexts *context.ContextTree
|
||||
ViewContextMap map[string]types.Context
|
||||
ViewTabContextMap map[string][]context.TabContext
|
||||
|
||||
@ -548,14 +548,13 @@ func NewGui(
|
||||
func (gui *Gui) resetControllers() {
|
||||
controllerCommon := gui.c
|
||||
osCommand := gui.OSCommand
|
||||
getContexts := func() context.ContextTree { return gui.State.Contexts }
|
||||
rebaseHelper := controllers.NewRebaseHelper(controllerCommon, getContexts, gui.git, gui.takeOverMergeConflictScrolling)
|
||||
rebaseHelper := controllers.NewRebaseHelper(controllerCommon, gui.State.Contexts, gui.git, gui.takeOverMergeConflictScrolling)
|
||||
model := gui.State.Model
|
||||
gui.helpers = &Helpers{
|
||||
Refs: controllers.NewRefsHelper(
|
||||
controllerCommon,
|
||||
gui.git,
|
||||
getContexts,
|
||||
gui.State.Contexts,
|
||||
func() { gui.State.Panels.Commits.LimitCommits = true },
|
||||
),
|
||||
Bisect: controllers.NewBisectHelper(controllerCommon, gui.git),
|
||||
@ -567,7 +566,7 @@ func (gui *Gui) resetControllers() {
|
||||
CherryPick: controllers.NewCherryPickHelper(
|
||||
controllerCommon,
|
||||
gui.git,
|
||||
getContexts,
|
||||
gui.State.Contexts,
|
||||
func() *cherrypicking.CherryPicking { return gui.State.Modes.CherryPicking },
|
||||
rebaseHelper,
|
||||
),
|
||||
@ -592,18 +591,17 @@ func (gui *Gui) resetControllers() {
|
||||
),
|
||||
Files: controllers.NewFilesController(
|
||||
controllerCommon,
|
||||
func() *context.WorkingTreeContext { return gui.State.Contexts.Files },
|
||||
func() []*models.File { return gui.State.Model.Files },
|
||||
gui.State.Contexts.Files,
|
||||
model,
|
||||
gui.git,
|
||||
osCommand,
|
||||
gui.getSelectedFileNode,
|
||||
getContexts,
|
||||
gui.State.Contexts,
|
||||
gui.enterSubmodule,
|
||||
func() []*models.SubmoduleConfig { return gui.State.Model.Submodules },
|
||||
gui.getSetTextareaTextFn(func() *gocui.View { return gui.Views.CommitMessage }),
|
||||
gui.withGpgHandling,
|
||||
func() string { return gui.State.failedCommitMessage },
|
||||
func() []*models.Commit { return gui.State.Model.Commits },
|
||||
gui.getSelectedPath,
|
||||
gui.switchToMerge,
|
||||
gui.helpers.Suggestions,
|
||||
@ -613,9 +611,9 @@ func (gui *Gui) resetControllers() {
|
||||
),
|
||||
Tags: controllers.NewTagsController(
|
||||
controllerCommon,
|
||||
func() *context.TagsContext { return gui.State.Contexts.Tags },
|
||||
gui.State.Contexts.Tags,
|
||||
gui.git,
|
||||
getContexts,
|
||||
gui.State.Contexts,
|
||||
gui.helpers.Tags,
|
||||
gui.helpers.Refs,
|
||||
gui.helpers.Suggestions,
|
||||
@ -623,7 +621,7 @@ func (gui *Gui) resetControllers() {
|
||||
),
|
||||
LocalCommits: controllers.NewLocalCommitsController(
|
||||
controllerCommon,
|
||||
func() types.IListContext { return gui.State.Contexts.BranchCommits },
|
||||
gui.State.Contexts.BranchCommits,
|
||||
osCommand,
|
||||
gui.git,
|
||||
gui.helpers.Tags,
|
||||
@ -631,7 +629,7 @@ func (gui *Gui) resetControllers() {
|
||||
gui.helpers.CherryPick,
|
||||
gui.helpers.Rebase,
|
||||
gui.getSelectedLocalCommit,
|
||||
func() []*models.Commit { return gui.State.Model.Commits },
|
||||
model,
|
||||
func() int { return gui.State.Panels.Commits.SelectedLineIdx },
|
||||
gui.helpers.Rebase.CheckMergeOrRebase,
|
||||
syncController.HandlePull,
|
||||
@ -644,20 +642,20 @@ func (gui *Gui) resetControllers() {
|
||||
),
|
||||
Remotes: controllers.NewRemotesController(
|
||||
controllerCommon,
|
||||
func() types.IListContext { return gui.State.Contexts.Remotes },
|
||||
gui.State.Contexts.Remotes,
|
||||
gui.git,
|
||||
getContexts,
|
||||
gui.State.Contexts,
|
||||
gui.getSelectedRemote,
|
||||
func(branches []*models.RemoteBranch) { gui.State.Model.RemoteBranches = branches },
|
||||
),
|
||||
Menu: controllers.NewMenuController(
|
||||
controllerCommon,
|
||||
func() types.IListContext { return gui.State.Contexts.Menu },
|
||||
gui.State.Contexts.Menu,
|
||||
gui.getSelectedMenuItem,
|
||||
),
|
||||
Bisect: controllers.NewBisectController(
|
||||
controllerCommon,
|
||||
func() types.IListContext { return gui.State.Contexts.BranchCommits },
|
||||
gui.State.Contexts.BranchCommits,
|
||||
gui.git,
|
||||
gui.helpers.Bisect,
|
||||
gui.getSelectedLocalCommit,
|
||||
|
Loading…
x
Reference in New Issue
Block a user