diff options
Diffstat (limited to 'pkg/gui/controllers')
39 files changed, 520 insertions, 286 deletions
diff --git a/pkg/gui/controllers/basic_commits_controller.go b/pkg/gui/controllers/basic_commits_controller.go index 340b14c0b..f2c794abc 100644 --- a/pkg/gui/controllers/basic_commits_controller.go +++ b/pkg/gui/controllers/basic_commits_controller.go @@ -20,15 +20,15 @@ type ContainsCommits interface { type BasicCommitsController struct { baseController - *controllerCommon + c *ControllerCommon context ContainsCommits } -func NewBasicCommitsController(controllerCommon *controllerCommon, context ContainsCommits) *BasicCommitsController { +func NewBasicCommitsController(controllerCommon *ControllerCommon, context ContainsCommits) *BasicCommitsController { return &BasicCommitsController{ - baseController: baseController{}, - controllerCommon: controllerCommon, - context: context, + baseController: baseController{}, + c: controllerCommon, + context: context, } } @@ -73,7 +73,7 @@ func (self *BasicCommitsController) GetKeybindings(opts types.KeybindingsOpts) [ }, { Key: opts.GetKey(opts.Config.Commits.ResetCherryPick), - Handler: self.helpers.CherryPick.Reset, + Handler: self.c.Helpers().CherryPick.Reset, Description: self.c.Tr.LcResetCherryPick, }, } @@ -150,7 +150,7 @@ func (self *BasicCommitsController) copyCommitSHAToClipboard(commit *models.Comm } func (self *BasicCommitsController) copyCommitURLToClipboard(commit *models.Commit) error { - url, err := self.helpers.Host.GetCommitURL(commit.Sha) + url, err := self.c.Helpers().Host.GetCommitURL(commit.Sha) if err != nil { return err } @@ -212,7 +212,7 @@ func (self *BasicCommitsController) copyCommitMessageToClipboard(commit *models. } func (self *BasicCommitsController) openInBrowser(commit *models.Commit) error { - url, err := self.helpers.Host.GetCommitURL(commit.Sha) + url, err := self.c.Helpers().Host.GetCommitURL(commit.Sha) if err != nil { return self.c.Error(err) } @@ -226,11 +226,11 @@ func (self *BasicCommitsController) openInBrowser(commit *models.Commit) error { } func (self *BasicCommitsController) newBranch(commit *models.Commit) error { - return self.helpers.Refs.NewBranch(commit.RefName(), commit.Description(), "") + return self.c.Helpers().Refs.NewBranch(commit.RefName(), commit.Description(), "") } func (self *BasicCommitsController) createResetMenu(commit *models.Commit) error { - return self.helpers.Refs.CreateGitResetMenu(commit.Sha) + return self.c.Helpers().Refs.CreateGitResetMenu(commit.Sha) } func (self *BasicCommitsController) checkout(commit *models.Commit) error { @@ -239,15 +239,15 @@ func (self *BasicCommitsController) checkout(commit *models.Commit) error { Prompt: self.c.Tr.SureCheckoutThisCommit, HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.CheckoutCommit) - return self.helpers.Refs.CheckoutRef(commit.Sha, types.CheckoutRefOptions{}) + return self.c.Helpers().Refs.CheckoutRef(commit.Sha, types.CheckoutRefOptions{}) }, }) } func (self *BasicCommitsController) copy(commit *models.Commit) error { - return self.helpers.CherryPick.Copy(commit, self.context.GetCommits(), self.context) + return self.c.Helpers().CherryPick.Copy(commit, self.context.GetCommits(), self.context) } func (self *BasicCommitsController) copyRange(*models.Commit) error { - return self.helpers.CherryPick.CopyRange(self.context.GetSelectedLineIdx(), self.context.GetCommits(), self.context) + return self.c.Helpers().CherryPick.CopyRange(self.context.GetSelectedLineIdx(), self.context.GetCommits(), self.context) } diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index 6531b1409..9aab43ee7 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -12,17 +12,17 @@ import ( type BisectController struct { baseController - *controllerCommon + c *ControllerCommon } var _ types.IController = &BisectController{} func NewBisectController( - common *controllerCommon, + common *ControllerCommon, ) *BisectController { return &BisectController{ - baseController: baseController{}, - controllerCommon: common, + baseController: baseController{}, + c: common, } } @@ -105,7 +105,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c { Label: self.c.Tr.Bisect.ResetOption, OnPress: func() error { - return self.helpers.Bisect.Reset() + return self.c.Helpers().Bisect.Reset() }, Key: 'r', }, @@ -133,7 +133,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo, return self.c.Error(err) } - return self.helpers.Bisect.PostBisectCommandRefresh() + return self.c.Helpers().Bisect.PostBisectCommandRefresh() }, Key: 'b', }, @@ -149,7 +149,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo, return self.c.Error(err) } - return self.helpers.Bisect.PostBisectCommandRefresh() + return self.c.Helpers().Bisect.PostBisectCommandRefresh() }, Key: 'g', }, @@ -177,7 +177,7 @@ func (self *BisectController) showBisectCompleteMessage(candidateShas []string) return self.c.Error(err) } - return self.helpers.Bisect.PostBisectCommandRefresh() + return self.c.Helpers().Bisect.PostBisectCommandRefresh() }, }) } @@ -211,7 +211,7 @@ func (self *BisectController) afterBisectMarkRefresh(selectCurrent bool, waitToR } else { selectFn() - return self.helpers.Bisect.PostBisectCommandRefresh() + return self.c.Helpers().Bisect.PostBisectCommandRefresh() } } diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 03e088368..a39fe18e2 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -14,17 +14,17 @@ import ( type BranchesController struct { baseController - *controllerCommon + c *ControllerCommon } var _ types.IController = &BranchesController{} func NewBranchesController( - common *controllerCommon, + common *ControllerCommon, ) *BranchesController { return &BranchesController{ - baseController: baseController{}, - controllerCommon: common, + baseController: baseController{}, + c: common, } } @@ -113,7 +113,7 @@ func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*ty func (self *BranchesController) GetOnRenderToMain() func() error { return func() error { - return self.helpers.Diff.WithDiffModeCheck(func() error { + return self.c.Helpers().Diff.WithDiffModeCheck(func() error { var task types.UpdateTask branch := self.context().GetSelected() if branch == nil { @@ -161,8 +161,8 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error { LabelColumns: []string{self.c.Tr.LcSetUpstream}, OnPress: func() error { - return self.helpers.Upstream.PromptForUpstreamWithoutInitialContent(selectedBranch, func(upstream string) error { - upstreamRemote, upstreamBranch, err := self.helpers.Upstream.ParseUpstream(upstream) + return self.c.Helpers().Upstream.PromptForUpstreamWithoutInitialContent(selectedBranch, func(upstream string) error { + upstreamRemote, upstreamBranch, err := self.c.Helpers().Upstream.ParseUpstream(upstream) if err != nil { return self.c.Error(err) } @@ -197,12 +197,12 @@ func (self *BranchesController) context() *context.BranchesContext { } func (self *BranchesController) press(selectedBranch *models.Branch) error { - if selectedBranch == self.helpers.Refs.GetCheckedOutRef() { + if selectedBranch == self.c.Helpers().Refs.GetCheckedOutRef() { return self.c.ErrorMsg(self.c.Tr.AlreadyCheckedOutBranch) } self.c.LogAction(self.c.Tr.Actions.CheckoutBranch) - return self.helpers.Refs.CheckoutRef(selectedBranch.Name, types.CheckoutRefOptions{}) + return self.c.Helpers().Refs.CheckoutRef(selectedBranch.Name, types.CheckoutRefOptions{}) } func (self *BranchesController) handleCreatePullRequest(selectedBranch *models.Branch) error { @@ -210,7 +210,7 @@ func (self *BranchesController) handleCreatePullRequest(selectedBranch *models.B } func (self *BranchesController) handleCreatePullRequestMenu(selectedBranch *models.Branch) error { - checkedOutBranch := self.helpers.Refs.GetCheckedOutRef() + checkedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef() return self.createPullRequestMenu(selectedBranch, checkedOutBranch) } @@ -224,7 +224,7 @@ func (self *BranchesController) copyPullRequestURL() error { return self.c.Error(errors.New(self.c.Tr.NoBranchOnRemote)) } - url, err := self.helpers.Host.GetPullRequestURL(branch.Name, "") + url, err := self.c.Helpers().Host.GetPullRequestURL(branch.Name, "") if err != nil { return self.c.Error(err) } @@ -259,10 +259,10 @@ func (self *BranchesController) forceCheckout() error { func (self *BranchesController) checkoutByName() error { return self.c.Prompt(types.PromptOpts{ Title: self.c.Tr.BranchName + ":", - FindSuggestionsFunc: self.helpers.Suggestions.GetRefsSuggestionsFunc(), + FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRefsSuggestionsFunc(), HandleConfirm: func(response string) error { self.c.LogAction("Checkout branch") - return self.helpers.Refs.CheckoutRef(response, types.CheckoutRefOptions{ + return self.c.Helpers().Refs.CheckoutRef(response, types.CheckoutRefOptions{ OnRefNotFound: func(ref string) error { return self.c.Confirm(types.ConfirmOpts{ Title: self.c.Tr.BranchNotFoundTitle, @@ -293,7 +293,7 @@ func (self *BranchesController) createNewBranchWithName(newBranchName string) er } func (self *BranchesController) delete(branch *models.Branch) error { - checkedOutBranch := self.helpers.Refs.GetCheckedOutRef() + checkedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef() if checkedOutBranch.Name == branch.Name { return self.c.ErrorMsg(self.c.Tr.CantDeleteCheckOutBranch) } @@ -334,12 +334,12 @@ func (self *BranchesController) deleteWithForce(selectedBranch *models.Branch, f func (self *BranchesController) merge() error { selectedBranchName := self.context().GetSelected().Name - return self.helpers.MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranchName) + return self.c.Helpers().MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranchName) } func (self *BranchesController) rebase() error { selectedBranchName := self.context().GetSelected().Name - return self.helpers.MergeAndRebase.RebaseOntoRef(selectedBranchName) + return self.c.Helpers().MergeAndRebase.RebaseOntoRef(selectedBranchName) } func (self *BranchesController) fastForward(branch *models.Branch) error { @@ -364,7 +364,7 @@ func (self *BranchesController) fastForward(branch *models.Branch) error { ) return self.c.WithLoaderPanel(message, func() error { - if branch == self.helpers.Refs.GetCheckedOutRef() { + if branch == self.c.Helpers().Refs.GetCheckedOutRef() { self.c.LogAction(action) err := self.c.Git().Sync.Pull( @@ -393,11 +393,11 @@ func (self *BranchesController) fastForward(branch *models.Branch) error { } func (self *BranchesController) createTag(branch *models.Branch) error { - return self.helpers.Tags.CreateTagMenu(branch.FullRefName(), func() {}) + return self.c.Helpers().Tags.CreateTagMenu(branch.FullRefName(), func() {}) } func (self *BranchesController) createResetMenu(selectedBranch *models.Branch) error { - return self.helpers.Refs.CreateGitResetMenu(selectedBranch.Name) + return self.c.Helpers().Refs.CreateGitResetMenu(selectedBranch.Name) } func (self *BranchesController) rename(branch *models.Branch) error { @@ -444,7 +444,7 @@ func (self *BranchesController) rename(branch *models.Branch) error { } func (self *BranchesController) newBranch(selectedBranch *models.Branch) error { - return self.helpers.Refs.NewBranch(selectedBranch.FullRefName(), selectedBranch.RefName(), "") + return self.c.Helpers().Refs.NewBranch(selectedBranch.FullRefName(), selectedBranch.RefName(), "") } func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Branch, checkedOutBranch *models.Branch) error { @@ -467,7 +467,7 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra OnPress: func() error { return self.c.Prompt(types.PromptOpts{ Title: branch.Name + " →", - FindSuggestionsFunc: self.helpers.Suggestions.GetBranchNameSuggestionsFunc(), + FindSuggestionsFunc: self.c.Helpers().Suggestions.GetBranchNameSuggestionsFunc(), HandleConfirm: func(targetBranchName string) error { return self.createPullRequest(branch.Name, targetBranchName) }, @@ -495,7 +495,7 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra } func (self *BranchesController) createPullRequest(from string, to string) error { - url, err := self.helpers.Host.GetPullRequestURL(from, to) + url, err := self.c.Helpers().Host.GetPullRequestURL(from, to) if err != nil { return self.c.Error(err) } diff --git a/pkg/gui/controllers/command_log_controller.go b/pkg/gui/controllers/command_log_controller.go index 3e6e7c11a..0c3479914 100644 --- a/pkg/gui/controllers/command_log_controller.go +++ b/pkg/gui/controllers/command_log_controller.go @@ -6,17 +6,17 @@ import ( type CommandLogController struct { baseController - *controllerCommon + c *ControllerCommon } var _ types.IController = &CommandLogController{} func NewCommandLogController( - common *controllerCommon, + common *ControllerCommon, ) *CommandLogController { return &CommandLogController{ - baseController: baseController{}, - controllerCommon: common, + baseController: baseController{}, + c: common, } } diff --git a/pkg/gui/controllers/commit_message_controller.go b/pkg/gui/controllers/commit_message_controller.go index 1b28ec887..481d65c4c 100644 --- a/pkg/gui/controllers/commit_message_controller.go +++ b/pkg/gui/controllers/commit_message_controller.go @@ -7,7 +7,7 @@ import ( type CommitMessageController struct { baseController - *controllerCommon + c *ControllerCommon getCommitMessage func() string onCommitAttempt func(message string) @@ -17,14 +17,14 @@ type CommitMessageController struct { var _ types.IController = &CommitMessageController{} func NewCommitMessageController( - common *controllerCommon, + common *ControllerCommon, getCommitMessage func() string, onCommitAttempt func(message string), onCommitSuccess func(), ) *CommitMessageController { return &CommitMessageController{ - baseController: baseController{}, - controllerCommon: common, + baseController: baseController{}, + c: common, getCommitMessage: getCommitMessage, onCommitAttempt: onCommitAttempt, @@ -80,7 +80,7 @@ func (self *CommitMessageController) confirm() error { self.c.LogAction(self.c.Tr.Actions.Commit) _ = self.c.PopContext() - return self.helpers.GPG.WithGpgHandling(cmdObj, self.c.Tr.CommittingStatus, func() error { + return self.c.Helpers().GPG.WithGpgHandling(cmdObj, self.c.Tr.CommittingStatus, func() error { self.onCommitSuccess() return nil }) diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 34e859211..8ef5f2c57 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -11,17 +11,17 @@ import ( type CommitFilesController struct { baseController - *controllerCommon + c *ControllerCommon } var _ types.IController = &CommitFilesController{} func NewCommitFilesController( - common *controllerCommon, + common *ControllerCommon, ) *CommitFilesController { return &CommitFilesController{ - baseController: baseController{}, - controllerCommon: common, + baseController: baseController{}, + c: common, } } @@ -120,7 +120,7 @@ func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error } func (self *CommitFilesController) discard(node *filetree.CommitFileNode) error { - if ok, err := self.helpers.PatchBuilding.ValidateNormalWorkingTreeState(); !ok { + if ok, err := self.c.Helpers().PatchBuilding.ValidateNormalWorkingTreeState(); !ok { return err } @@ -131,7 +131,7 @@ func (self *CommitFilesController) discard(node *filetree.CommitFileNode) error return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error { self.c.LogAction(self.c.Tr.Actions.DiscardOldFileChange) if err := self.c.Git().Rebase.DiscardOldFileChanges(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx(), node.GetPath()); err != nil { - if err := self.helpers.MergeAndRebase.CheckMergeOrRebase(err); err != nil { + if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil { return err } } @@ -143,7 +143,7 @@ func (self *CommitFilesController) discard(node *filetree.CommitFileNode) error } func (self *CommitFilesController) open(node *filetree.CommitFileNode) error { - return self.helpers.Files.OpenFile(node.GetPath()) + return self.c.Helpers().Files.OpenFile(node.GetPath()) } func (self *CommitFilesController) edit(node *filetree.CommitFileNode) error { @@ -151,7 +151,7 @@ func (self *CommitFilesController) edit(node *filetree.CommitFileNode) error { return self.c.ErrorMsg(self.c.Tr.ErrCannotEditDirectory) } - return self.helpers.Files.EditFile(node.GetPath()) + return self.c.Helpers().Files.EditFile(node.GetPath()) } func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) error { diff --git a/pkg/gui/controllers/common.go b/pkg/gui/controllers/common.go index 1c14b7f4e..3498ad59d 100644 --- a/pkg/gui/controllers/common.go +++ b/pkg/gui/controllers/common.go @@ -4,17 +4,21 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" ) -type controllerCommon struct { - c *helpers.HelperCommon - helpers *helpers.Helpers +type ControllerCommon struct { + *helpers.HelperCommon + IGetHelpers +} + +type IGetHelpers interface { + Helpers() *helpers.Helpers } func NewControllerCommon( c *helpers.HelperCommon, - helpers *helpers.Helpers, -) *controllerCommon { - return &controllerCommon{ - c: c, - helpers: helpers, + IGetHelpers IGetHelpers, +) *ControllerCommon { + return &ControllerCommon{ + HelperCommon: c, + IGetHelpers: IGetHelpers, } } diff --git a/pkg/gui/controllers/confirmation_controller.go b/pkg/gui/controllers/confirmation_controller.go index 09496f721..09af35586 100644 --- a/pkg/gui/controllers/confirmation_controller.go +++ b/pkg/gui/controllers/confirmation_controller.go @@ -7,17 +7,17 @@ import ( type ConfirmationController struct { baseController - *controllerCommon + c *ControllerCommon } var _ types.IController = &ConfirmationController{} func NewConfirmationController( - common *controllerCommon, + common *ControllerCommon, ) *ConfirmationController { return &ConfirmationController{ - baseController: baseController{}, - controllerCommon: common, + baseController: baseController{}, + c: common, } } @@ -51,7 +51,7 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [ func (self *ConfirmationController) GetOnFocusLost() func(types.OnFocusLostOpts) error { return func(types.OnFocusLostOpts) error { - self.helpers.Confirmation.DeactivateConfirmationPrompt() + self.c.Helpers().Confirmation.DeactivateConfirmationPrompt() return nil } } diff --git a/pkg/gui/controllers/context_lines_controller.go b/pkg/gui/controllers/context_lines_controller.go index 913b763d0..5ec2d3167 100644 --- a/pkg/gui/controllers/context_lines_controller.go +++ b/pkg/gui/controllers/context_lines_controller.go @@ -24,17 +24,17 @@ var CONTEXT_KEYS_SHOWING_DIFFS = []types.ContextKey{ type ContextLinesController struct { baseController - *controllerCommon + c *ControllerCommon } var _ types.IController = &ContextLinesController{} func NewContextLinesController( - common *controllerCommon, + common *ControllerCommon, ) *ContextLinesController { return &ContextLinesController{ - baseController: baseController{}, - controllerCommon: common, + baseController: baseController{}, + c: common, } } diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 7d040704a..165878459 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -13,7 +13,7 @@ import ( type FilesController struct { baseController // nolint: unused - *controllerCommon + c *ControllerCommon setCommitMessage func(message string) getSavedCommitMessage func() string @@ -22,12 +22,12 @@ type FilesController struct { var _ types.IController = &FilesController{} func NewFilesController( - common *controllerCommon, + common *ControllerCommon, setCommitMessage func(message string), getSavedCommitMessage func() string, ) *FilesController { return &FilesController{ - controllerCommon: common, + c: common, setCommitMessage: setCommitMessage, getSavedCommitMessage: getSavedCommitMessage, } @@ -47,12 +47,12 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types }, { Key: opts.GetKey(opts.Config.Files.CommitChanges), - Handler: self.helpers.WorkingTree.HandleCommitPress, + Handler: self.c.Helpers().WorkingTree.HandleCommitPress, Description: self.c.Tr.CommitChanges, }, { Key: opts.GetKey(opts.Config.Files.CommitChangesWithoutHook), - Handler: self.helpers.WorkingTree.HandleWIPCommitPress, + Handler: self.c.Helpers().WorkingTree.HandleWIPCommitPress, Description: self.c.Tr.LcCommitChangesWithoutHook, }, { @@ -62,7 +62,7 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types }, { Key: opts.GetKey(opts.Config.Files.CommitChangesWithEditor), - Handler: self.helpers.WorkingTree.HandleCommitEditorPress, + Handler: self.c.Helpers().WorkingTree.HandleCommitEditorPress, Description: self.c.Tr.CommitChangesWithEditor, |