From 43251e727596cca2538548976769e47a1bfc5593 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Thu, 23 Mar 2023 12:35:07 +1100 Subject: [PATCH] split context common from helper common --- pkg/gui/context/branches_context.go | 2 +- pkg/gui/context/commit_files_context.go | 4 +-- pkg/gui/context/commit_message_context.go | 4 +-- pkg/gui/context/confirmation_context.go | 4 +-- pkg/gui/context/context_common.go | 11 ++++++++ pkg/gui/context/list_context_trait.go | 2 +- pkg/gui/context/local_commits_context.go | 6 ++--- pkg/gui/context/menu_context.go | 2 +- pkg/gui/context/merge_conflicts_context.go | 4 +-- pkg/gui/context/patch_explorer_context.go | 4 +-- pkg/gui/context/reflog_commits_context.go | 2 +- pkg/gui/context/remote_branches_context.go | 2 +- pkg/gui/context/remotes_context.go | 2 +- pkg/gui/context/stash_context.go | 2 +- pkg/gui/context/sub_commits_context.go | 2 +- pkg/gui/context/submodules_context.go | 2 +- pkg/gui/context/suggestions_context.go | 2 +- pkg/gui/context/tags_context.go | 2 +- pkg/gui/context/working_tree_context.go | 2 +- pkg/gui/context_config.go | 12 ++++----- pkg/gui/controllers.go | 5 ++-- pkg/gui/controllers/common.go | 4 +-- pkg/gui/controllers/helpers/bisect_helper.go | 16 +++--------- .../controllers/helpers/cherry_pick_helper.go | 11 +++----- .../helpers/confirmation_helper.go | 4 +-- .../controllers/helpers/credentials_helper.go | 4 +-- pkg/gui/controllers/helpers/diff_helper.go | 4 +-- pkg/gui/controllers/helpers/files_helper.go | 5 ++-- pkg/gui/controllers/helpers/gpg_helper.go | 4 +-- pkg/gui/controllers/helpers/helpers.go | 16 ++++++++++++ pkg/gui/controllers/helpers/host_helper.go | 5 ++-- .../helpers/merge_and_rebase_helper.go | 4 +-- .../helpers/merge_conflicts_helper.go | 4 +-- .../helpers/patch_building_helper.go | 4 +-- .../helpers/record_directory_helper.go | 6 ++--- pkg/gui/controllers/helpers/refresh_helper.go | 4 +-- pkg/gui/controllers/helpers/refs_helper.go | 4 +-- pkg/gui/controllers/helpers/repos_helper.go | 4 +-- pkg/gui/controllers/helpers/snake_helper.go | 5 ++-- pkg/gui/controllers/helpers/staging_helper.go | 4 +-- .../controllers/helpers/suggestions_helper.go | 4 +-- pkg/gui/controllers/helpers/tags_helper.go | 4 +-- pkg/gui/controllers/helpers/update_helper.go | 4 +-- .../controllers/helpers/upstream_helper.go | 4 +-- pkg/gui/controllers/helpers/view_helper.go | 4 +-- pkg/gui/controllers/helpers/window_helper.go | 4 +-- .../helpers/working_tree_helper.go | 4 +-- pkg/gui/controllers/list_controller.go | 14 +++++----- .../controllers/local_commits_controller.go | 3 ++- pkg/gui/gui.go | 14 +++++++--- pkg/gui/list_context_config.go | 26 +++++++++---------- pkg/gui/options_map.go | 3 ++- pkg/gui/services/custom_commands/client.go | 2 +- .../custom_commands/handler_creator.go | 5 ++-- pkg/gui/types/common.go | 4 +++ 55 files changed, 156 insertions(+), 133 deletions(-) create mode 100644 pkg/gui/context/context_common.go diff --git a/pkg/gui/context/branches_context.go b/pkg/gui/context/branches_context.go index 81b289cec..1d6453c13 100644 --- a/pkg/gui/context/branches_context.go +++ b/pkg/gui/context/branches_context.go @@ -16,7 +16,7 @@ var ( _ types.DiffableContext = (*BranchesContext)(nil) ) -func NewBranchesContext(c *types.HelperCommon) *BranchesContext { +func NewBranchesContext(c *ContextCommon) *BranchesContext { viewModel := NewBasicViewModel(func() []*models.Branch { return c.Model().Branches }) getDisplayStrings := func(startIdx int, length int) [][]string { diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go index 80e3c52d0..0b884a7cd 100644 --- a/pkg/gui/context/commit_files_context.go +++ b/pkg/gui/context/commit_files_context.go @@ -20,7 +20,7 @@ var ( _ types.DiffableContext = (*CommitFilesContext)(nil) ) -func NewCommitFilesContext(c *types.HelperCommon) *CommitFilesContext { +func NewCommitFilesContext(c *ContextCommon) *CommitFilesContext { viewModel := filetree.NewCommitFileTreeViewModel( func() []*models.CommitFile { return c.Model().CommitFiles }, c.Log, @@ -102,7 +102,7 @@ func (self *CommitFilesContext) renderToMain() error { }) } -func secondaryPatchPanelUpdateOpts(c *types.HelperCommon) *types.ViewUpdateOpts { +func secondaryPatchPanelUpdateOpts(c *ContextCommon) *types.ViewUpdateOpts { if c.Git().Patch.PatchBuilder.Active() { patch := c.Git().Patch.PatchBuilder.RenderAggregatedPatch(false) diff --git a/pkg/gui/context/commit_message_context.go b/pkg/gui/context/commit_message_context.go index b7224341d..96c6c4f73 100644 --- a/pkg/gui/context/commit_message_context.go +++ b/pkg/gui/context/commit_message_context.go @@ -10,13 +10,13 @@ import ( type CommitMessageContext struct { *SimpleContext - c *types.HelperCommon + c *ContextCommon } var _ types.Context = (*CommitMessageContext)(nil) func NewCommitMessageContext( - c *types.HelperCommon, + c *ContextCommon, ) *CommitMessageContext { return &CommitMessageContext{ c: c, diff --git a/pkg/gui/context/confirmation_context.go b/pkg/gui/context/confirmation_context.go index 34ec3ce6f..69c498e49 100644 --- a/pkg/gui/context/confirmation_context.go +++ b/pkg/gui/context/confirmation_context.go @@ -6,7 +6,7 @@ import ( type ConfirmationContext struct { *SimpleContext - c *types.HelperCommon + c *ContextCommon State ConfirmationContextState } @@ -19,7 +19,7 @@ type ConfirmationContextState struct { var _ types.Context = (*ConfirmationContext)(nil) func NewConfirmationContext( - c *types.HelperCommon, + c *ContextCommon, ) *ConfirmationContext { return &ConfirmationContext{ c: c, diff --git a/pkg/gui/context/context_common.go b/pkg/gui/context/context_common.go new file mode 100644 index 000000000..9425280a4 --- /dev/null +++ b/pkg/gui/context/context_common.go @@ -0,0 +1,11 @@ +package context + +import ( + "github.com/jesseduffield/lazygit/pkg/common" + "github.com/jesseduffield/lazygit/pkg/gui/types" +) + +type ContextCommon struct { + *common.Common + types.IGuiCommon +} diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go index df5bbc0af..d47a15c9c 100644 --- a/pkg/gui/context/list_context_trait.go +++ b/pkg/gui/context/list_context_trait.go @@ -10,7 +10,7 @@ import ( type ListContextTrait struct { types.Context - c *types.HelperCommon + c *ContextCommon list types.IList getDisplayStrings func(startIdx int, length int) [][]string } diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index 277e567ff..e8ae0b6c5 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -19,7 +19,7 @@ var ( _ types.DiffableContext = (*LocalCommitsContext)(nil) ) -func NewLocalCommitsContext(c *types.HelperCommon) *LocalCommitsContext { +func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext { viewModel := NewLocalCommitsViewModel( func() []*models.Commit { return c.Model().Commits }, c, @@ -93,7 +93,7 @@ type LocalCommitsViewModel struct { showWholeGitGraph bool } -func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *types.HelperCommon) *LocalCommitsViewModel { +func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *ContextCommon) *LocalCommitsViewModel { self := &LocalCommitsViewModel{ BasicViewModel: NewBasicViewModel(getModel), limitCommits: true, @@ -141,7 +141,7 @@ func (self *LocalCommitsViewModel) GetCommits() []*models.Commit { return self.getModel() } -func shouldShowGraph(c *types.HelperCommon) bool { +func shouldShowGraph(c *ContextCommon) bool { if c.Modes().Filtering.Active() { return false } diff --git a/pkg/gui/context/menu_context.go b/pkg/gui/context/menu_context.go index 288016f8d..b2685b2e4 100644 --- a/pkg/gui/context/menu_context.go +++ b/pkg/gui/context/menu_context.go @@ -15,7 +15,7 @@ type MenuContext struct { var _ types.IListContext = (*MenuContext)(nil) func NewMenuContext( - c *types.HelperCommon, + c *ContextCommon, ) *MenuContext { viewModel := NewMenuViewModel() diff --git a/pkg/gui/context/merge_conflicts_context.go b/pkg/gui/context/merge_conflicts_context.go index 97024eedb..60aac6e3a 100644 --- a/pkg/gui/context/merge_conflicts_context.go +++ b/pkg/gui/context/merge_conflicts_context.go @@ -11,7 +11,7 @@ import ( type MergeConflictsContext struct { types.Context viewModel *ConflictsViewModel - c *types.HelperCommon + c *ContextCommon mutex *deadlock.Mutex } @@ -24,7 +24,7 @@ type ConflictsViewModel struct { } func NewMergeConflictsContext( - c *types.HelperCommon, + c *ContextCommon, ) *MergeConflictsContext { viewModel := &ConflictsViewModel{ state: mergeconflicts.NewState(), diff --git a/pkg/gui/context/patch_explorer_context.go b/pkg/gui/context/patch_explorer_context.go index 216381dcd..ccffb4f7e 100644 --- a/pkg/gui/context/patch_explorer_context.go +++ b/pkg/gui/context/patch_explorer_context.go @@ -13,7 +13,7 @@ type PatchExplorerContext struct { state *patch_exploring.State viewTrait *ViewTrait getIncludedLineIndices func() []int - c *types.HelperCommon + c *ContextCommon mutex *deadlock.Mutex } @@ -26,7 +26,7 @@ func NewPatchExplorerContext( getIncludedLineIndices func() []int, - c *types.HelperCommon, + c *ContextCommon, ) *PatchExplorerContext { return &PatchExplorerContext{ state: nil, diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go index bb13038ec..40111beea 100644 --- a/pkg/gui/context/reflog_commits_context.go +++ b/pkg/gui/context/reflog_commits_context.go @@ -16,7 +16,7 @@ var ( _ types.DiffableContext = (*ReflogCommitsContext)(nil) ) -func NewReflogCommitsContext(c *types.HelperCommon) *ReflogCommitsContext { +func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext { viewModel := NewBasicViewModel(func() []*models.Commit { return c.Model().FilteredReflogCommits }) getDisplayStrings := func(startIdx int, length int) [][]string { diff --git a/pkg/gui/context/remote_branches_context.go b/pkg/gui/context/remote_branches_context.go index 474adb2a9..a085c18cc 100644 --- a/pkg/gui/context/remote_branches_context.go +++ b/pkg/gui/context/remote_branches_context.go @@ -18,7 +18,7 @@ var ( ) func NewRemoteBranchesContext( - c *types.HelperCommon, + c *ContextCommon, ) *RemoteBranchesContext { viewModel := NewBasicViewModel(func() []*models.RemoteBranch { return c.Model().RemoteBranches }) diff --git a/pkg/gui/context/remotes_context.go b/pkg/gui/context/remotes_context.go index a194baec8..d1082ab52 100644 --- a/pkg/gui/context/remotes_context.go +++ b/pkg/gui/context/remotes_context.go @@ -16,7 +16,7 @@ var ( _ types.DiffableContext = (*RemotesContext)(nil) ) -func NewRemotesContext(c *types.HelperCommon) *RemotesContext { +func NewRemotesContext(c *ContextCommon) *RemotesContext { viewModel := NewBasicViewModel(func() []*models.Remote { return c.Model().Remotes }) getDisplayStrings := func(startIdx int, length int) [][]string { diff --git a/pkg/gui/context/stash_context.go b/pkg/gui/context/stash_context.go index f56abc561..386292c00 100644 --- a/pkg/gui/context/stash_context.go +++ b/pkg/gui/context/stash_context.go @@ -17,7 +17,7 @@ var ( ) func NewStashContext( - c *types.HelperCommon, + c *ContextCommon, ) *StashContext { viewModel := NewBasicViewModel(func() []*models.StashEntry { return c.Model().StashEntries }) diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index 0b75b37c2..16712f982 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -22,7 +22,7 @@ var ( ) func NewSubCommitsContext( - c *types.HelperCommon, + c *ContextCommon, ) *SubCommitsContext { viewModel := &SubCommitsViewModel{ BasicViewModel: NewBasicViewModel( diff --git a/pkg/gui/context/submodules_context.go b/pkg/gui/context/submodules_context.go index 5cd942284..675e01cd1 100644 --- a/pkg/gui/context/submodules_context.go +++ b/pkg/gui/context/submodules_context.go @@ -13,7 +13,7 @@ type SubmodulesContext struct { var _ types.IListContext = (*SubmodulesContext)(nil) -func NewSubmodulesContext(c *types.HelperCommon) *SubmodulesContext { +func NewSubmodulesContext(c *ContextCommon) *SubmodulesContext { viewModel := NewBasicViewModel(func() []*models.SubmoduleConfig { return c.Model().Submodules }) getDisplayStrings := func(startIdx int, length int) [][]string { diff --git a/pkg/gui/context/suggestions_context.go b/pkg/gui/context/suggestions_context.go index 744219843..022e96daf 100644 --- a/pkg/gui/context/suggestions_context.go +++ b/pkg/gui/context/suggestions_context.go @@ -27,7 +27,7 @@ type SuggestionsContextState struct { var _ types.IListContext = (*SuggestionsContext)(nil) func NewSuggestionsContext( - c *types.HelperCommon, + c *ContextCommon, ) *SuggestionsContext { state := &SuggestionsContextState{ AsyncHandler: tasks.NewAsyncHandler(), diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go index 9722ece48..e49cdad9b 100644 --- a/pkg/gui/context/tags_context.go +++ b/pkg/gui/context/tags_context.go @@ -17,7 +17,7 @@ var ( ) func NewTagsContext( - c *types.HelperCommon, + c *ContextCommon, ) *TagsContext { viewModel := NewBasicViewModel(func() []*models.Tag { return c.Model().Tags }) diff --git a/pkg/gui/context/working_tree_context.go b/pkg/gui/context/working_tree_context.go index 5cb73ad13..45502eb60 100644 --- a/pkg/gui/context/working_tree_context.go +++ b/pkg/gui/context/working_tree_context.go @@ -15,7 +15,7 @@ type WorkingTreeContext struct { var _ types.IListContext = (*WorkingTreeContext)(nil) -func NewWorkingTreeContext(c *types.HelperCommon) *WorkingTreeContext { +func NewWorkingTreeContext(c *ContextCommon) *WorkingTreeContext { viewModel := filetree.NewFileTreeViewModel( func() []*models.File { return c.Model().Files }, c.Log, diff --git a/pkg/gui/context_config.go b/pkg/gui/context_config.go index 2c98478d9..8e59732c8 100644 --- a/pkg/gui/context_config.go +++ b/pkg/gui/context_config.go @@ -72,14 +72,14 @@ func (gui *Gui) contextTree() *context.ContextTree { "main", context.STAGING_MAIN_CONTEXT_KEY, func() []int { return nil }, - gui.c, + gui.contextCommon, ), StagingSecondary: context.NewPatchExplorerContext( gui.Views.StagingSecondary, "secondary", context.STAGING_SECONDARY_CONTEXT_KEY, func() []int { return nil }, - gui.c, + gui.contextCommon, ), CustomPatchBuilder: context.NewPatchExplorerContext( gui.Views.PatchBuilding, @@ -95,7 +95,7 @@ func (gui *Gui) contextTree() *context.ContextTree { return includedLineIndices }, - gui.c, + gui.contextCommon, ), CustomPatchBuilderSecondary: context.NewSimpleContext( context.NewBaseContext(context.NewBaseContextOpts{ @@ -107,10 +107,10 @@ func (gui *Gui) contextTree() *context.ContextTree { }), ), MergeConflicts: context.NewMergeConflictsContext( - gui.c, + gui.contextCommon, ), - Confirmation: context.NewConfirmationContext(gui.c), - CommitMessage: context.NewCommitMessageContext(gui.c), + Confirmation: context.NewConfirmationContext(gui.contextCommon), + CommitMessage: context.NewCommitMessageContext(gui.contextCommon), Search: context.NewSimpleContext( context.NewBaseContext(context.NewBaseContextOpts{ Kind: types.PERSISTENT_POPUP, diff --git a/pkg/gui/controllers.go b/pkg/gui/controllers.go index f64710a70..b0520c975 100644 --- a/pkg/gui/controllers.go +++ b/pkg/gui/controllers.go @@ -40,7 +40,7 @@ func (gui *Gui) resetControllers() { Host: helpers.NewHostHelper(helperCommon, gui.git), PatchBuilding: patchBuildingHelper, Staging: stagingHelper, - Bisect: helpers.NewBisectHelper(helperCommon, gui.git), + Bisect: helpers.NewBisectHelper(helperCommon), Suggestions: suggestionsHelper, Files: helpers.NewFilesHelper(helperCommon, gui.git, osCommand), WorkingTree: helpers.NewWorkingTreeHelper(helperCommon, gui.git, gui.State.Contexts, refsHelper, model, setCommitMessage, getSavedCommitMessage), @@ -50,7 +50,6 @@ func (gui *Gui) resetControllers() { MergeConflicts: mergeConflictsHelper, CherryPick: helpers.NewCherryPickHelper( helperCommon, - gui.git, gui.State.Contexts, rebaseHelper, ), @@ -305,7 +304,7 @@ func (gui *Gui) resetControllers() { ) // this must come last so that we've got our click handlers defined against the context - listControllerFactory := controllers.NewListControllerFactory(gui.c) + listControllerFactory := controllers.NewListControllerFactory(common) for _, context := range gui.getListContexts() { controllers.AttachControllers(context, listControllerFactory.Create(context)) } diff --git a/pkg/gui/controllers/common.go b/pkg/gui/controllers/common.go index f3b3011d3..e1af81732 100644 --- a/pkg/gui/controllers/common.go +++ b/pkg/gui/controllers/common.go @@ -9,7 +9,7 @@ import ( ) type controllerCommon struct { - c *types.HelperCommon + c *helpers.HelperCommon helpers *helpers.Helpers contexts *context.ContextTree @@ -26,7 +26,7 @@ type controllerCommon struct { } func NewControllerCommon( - c *types.HelperCommon, + c *helpers.HelperCommon, os *oscommands.OSCommand, git *commands.GitCommand, helpers *helpers.Helpers, diff --git a/pkg/gui/controllers/helpers/bisect_helper.go b/pkg/gui/controllers/helpers/bisect_helper.go index 65fb781d4..7d0fadf8a 100644 --- a/pkg/gui/controllers/helpers/bisect_helper.go +++ b/pkg/gui/controllers/helpers/bisect_helper.go @@ -1,23 +1,15 @@ package helpers import ( - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/gui/types" ) type BisectHelper struct { - c *types.HelperCommon - git *commands.GitCommand + c *HelperCommon } -func NewBisectHelper( - c *types.HelperCommon, - git *commands.GitCommand, -) *BisectHelper { - return &BisectHelper{ - c: c, - git: git, - } +func NewBisectHelper(c *HelperCommon) *BisectHelper { + return &BisectHelper{c: c} } func (self *BisectHelper) Reset() error { @@ -26,7 +18,7 @@ func (self *BisectHelper) Reset() error { Prompt: self.c.Tr.Bisect.ResetPrompt, HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.ResetBisect) - if err := self.git.Bisect.Reset(); err != nil { + if err := self.c.Git().Bisect.Reset(); err != nil { return self.c.Error(err) } diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index 84b77a299..695a726ae 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -1,7 +1,6 @@ package helpers import ( - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking" @@ -9,9 +8,7 @@ import ( ) type CherryPickHelper struct { - c *types.HelperCommon - - git *commands.GitCommand + c *HelperCommon contexts *context.ContextTree @@ -22,14 +19,12 @@ type CherryPickHelper struct { // even if in truth we're running git cherry-pick func NewCherryPickHelper( - c *types.HelperCommon, - git *commands.GitCommand, + c *HelperCommon, contexts *context.ContextTree, rebaseHelper *MergeAndRebaseHelper, ) *CherryPickHelper { return &CherryPickHelper{ c: c, - git: git, contexts: contexts, rebaseHelper: rebaseHelper, } @@ -87,7 +82,7 @@ func (self *CherryPickHelper) Paste() error { HandleConfirm: func() error { return self.c.WithWaitingStatus(self.c.Tr.CherryPickingStatus, func() error { self.c.LogAction(self.c.Tr.Actions.CherryPick) - err := self.git.Rebase.CherryPickCommits(self.getData().CherryPickedCommits) + err := self.c.Git().Rebase.CherryPickCommits(self.getData().CherryPickedCommits) return self.rebaseHelper.CheckMergeOrRebase(err) }) }, diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index 04211b7ac..d7ccb151a 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -15,12 +15,12 @@ import ( ) type ConfirmationHelper struct { - c *types.HelperCommon + c *HelperCommon contexts *context.ContextTree } func NewConfirmationHelper( - c *types.HelperCommon, + c *HelperCommon, contexts *context.ContextTree, ) *ConfirmationHelper { return &ConfirmationHelper{ diff --git a/pkg/gui/controllers/helpers/credentials_helper.go b/pkg/gui/controllers/helpers/credentials_helper.go index 10679d7a4..0aed34110 100644 --- a/pkg/gui/controllers/helpers/credentials_helper.go +++ b/pkg/gui/controllers/helpers/credentials_helper.go @@ -8,11 +8,11 @@ import ( ) type CredentialsHelper struct { - c *types.HelperCommon + c *HelperCommon } func NewCredentialsHelper( - c *types.HelperCommon, + c *HelperCommon, ) *CredentialsHelper { return &CredentialsHelper{ c: c, diff --git a/pkg/gui/controllers/helpers/diff_helper.go b/pkg/gui/controllers/helpers/diff_helper.go index 952104f81..701df93cd 100644 --- a/pkg/gui/controllers/helpers/diff_helper.go +++ b/pkg/gui/controllers/helpers/diff_helper.go @@ -10,10 +10,10 @@ import ( ) type DiffHelper struct { - c *types.HelperCommon + c *HelperCommon } -func NewDiffHelper(c *types.HelperCommon) *DiffHelper { +func NewDiffHelper(c *HelperCommon) *DiffHelper { return &DiffHelper{ c: c, } diff --git a/pkg/gui/controllers/helpers/files_helper.go b/pkg/gui/controllers/helpers/files_helper.go index a0d2d4e8c..9893123cb 100644 --- a/pkg/gui/controllers/helpers/files_helper.go +++ b/pkg/gui/controllers/helpers/files_helper.go @@ -3,7 +3,6 @@ package helpers import ( "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" - "github.com/jesseduffield/lazygit/pkg/gui/types" ) type IFilesHelper interface { @@ -13,13 +12,13 @@ type IFilesHelper interface { } type FilesHelper struct { - c *types.HelperCommon + c *HelperCommon git *commands.GitCommand os *oscommands.OSCommand } func NewFilesHelper( - c *types.HelperCommon, + c *HelperCommon, git *commands.GitCommand, os *oscommands.OSCommand, ) *FilesHelper { diff --git a/pkg/gui/controllers/helpers/gpg_helper.go b/pkg/gui/controllers/helpers/gpg_helper.go index 2e287c2b4..0249c560f 100644 --- a/pkg/gui/controllers/helpers/gpg_helper.go +++ b/pkg/gui/controllers/helpers/gpg_helper.go @@ -9,13 +9,13 @@ import ( ) type GpgHelper struct { - c *types.HelperCommon + c *HelperCommon os *oscommands.OSCommand git *commands.GitCommand } func NewGpgHelper( - c *types.HelperCommon, + c *HelperCommon, os *oscommands.OSCommand, git *commands.GitCommand, ) *GpgHelper { diff --git a/pkg/gui/controllers/helpers/helpers.go b/pkg/gui/controllers/helpers/helpers.go index 8c676f4de..c250a09b5 100644 --- a/pkg/gui/controllers/helpers/helpers.go +++ b/pkg/gui/controllers/helpers/helpers.go @@ -1,5 +1,21 @@ package helpers +import ( + "github.com/jesseduffield/lazygit/pkg/common" + "github.com/jesseduffield/lazygit/pkg/gui/context" + "github.com/jesseduffield/lazygit/pkg/gui/types" +) + +type HelperCommon struct { + *common.Common + types.IGuiCommon + IGetContexts +} + +type IGetContexts interface { + Contexts() *context.ContextTree +} + type Helpers struct { Refs *RefsHelper Bisect *BisectHelper diff --git a/pkg/gui/controllers/helpers/host_helper.go b/pkg/gui/controllers/helpers/host_helper.go index edc0bc7ba..b11bc32c2 100644 --- a/pkg/gui/controllers/helpers/host_helper.go +++ b/pkg/gui/controllers/helpers/host_helper.go @@ -3,7 +3,6 @@ package helpers import ( "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/hosting_service" - "github.com/jesseduffield/lazygit/pkg/gui/types" ) // this helper just wraps our hosting_service package @@ -14,12 +13,12 @@ type IHostHelper interface { } type HostHelper struct { - c *types.HelperCommon + c *HelperCommon git *commands.GitCommand } func NewHostHelper( - c *types.HelperCommon, + c *HelperCommon, git *commands.GitCommand, ) *HostHelper { return &HostHelper{ diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index 981b85a0d..56154e6ad 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -14,14 +14,14 @@ import ( ) type MergeAndRebaseHelper struct { - c *types.HelperCommon + c *HelperCommon contexts *context.ContextTree git *commands.GitCommand refsHelper *RefsHelper } func NewMergeAndRebaseHelper( - c *types.HelperCommon, + c *HelperCommon, contexts *context.ContextTree, git *commands.GitCommand, refsHelper *RefsHelper, diff --git a/pkg/gui/controllers/helpers/merge_conflicts_helper.go b/pkg/gui/controllers/helpers/merge_conflicts_helper.go index b099a69cd..c84cf4540 100644 --- a/pkg/gui/controllers/helpers/merge_conflicts_helper.go +++ b/pkg/gui/controllers/helpers/merge_conflicts_helper.go @@ -7,13 +7,13 @@ import ( ) type MergeConflictsHelper struct { - c *types.HelperCommon + c *HelperCommon contexts *context.ContextTree git *commands.GitCommand } func NewMergeConflictsHelper( - c *types.HelperCommon, + c *HelperCommon, contexts *context.ContextTree, git *commands.GitCommand, ) *MergeConflictsHelper { diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go index b58812733..08bb8122d 100644 --- a/pkg/gui/controllers/helpers/patch_building_helper.go +++ b/pkg/gui/controllers/helpers/patch_building_helper.go @@ -13,13 +13,13 @@ type IPatchBuildingHelper interface { } type PatchBuildingHelper struct { - c *types.HelperCommon + c *HelperCommon git *commands.GitCommand contexts *context.ContextTree } func NewPatchBuildingHelper( - c *types.HelperCommon, + c *HelperCommon, git *commands.GitCommand, contexts *context.ContextTree, ) *PatchBuildingHelper { diff --git a/pkg/gui/controllers/helpers/record_directory_helper.go b/pkg/gui/controllers/helpers/record_directory_helper.go index 4877a6b46..377e3b94a 100644 --- a/pkg/gui/controllers/helpers/record_directory_helper.go +++ b/pkg/gui/controllers/helpers/record_directory_helper.go @@ -2,15 +2,13 @@ package helpers import ( "os" - - "github.com/jesseduffield/lazygit/pkg/gui/types" ) type RecordDirectoryHelper struct { - c *types.HelperCommon + c *HelperCommon } -func NewRecordDirectoryHelper(c *types.HelperCommon) *RecordDirectoryHelper { +func NewRecordDirectoryHelper(c *HelperCommon) *RecordDirectoryHelper { return &RecordDirectoryHelper{ c: c, } diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 9a1089de3..132c65545 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -21,7 +21,7 @@ import ( ) type RefreshHelper struct { - c *types.HelperCommon + c *HelperCommon contexts *context.ContextTree git *commands.GitCommand refsHelper *RefsHelper @@ -33,7 +33,7 @@ type RefreshHelper struct { } func NewRefreshHelper( - c *types.HelperCommon, + c *HelperCommon, contexts *context.ContextTree, git *commands.GitCommand, refsHelper *RefsHelper, diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index c03a2b24c..ad295e59c 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -23,14 +23,14 @@ type IRefsHelper interface { } type RefsHelper struct { - c *types.HelperCommon + c *HelperCommon git *commands.GitCommand contexts *context.ContextTree model *types.Model } func NewRefsHelper( - c *types.HelperCommon, + c *HelperCommon, git *commands.GitCommand, contexts *context.ContextTree, model *types.Model, diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go index ef983e856..060724a0a 100644 --- a/pkg/gui/controllers/helpers/repos_helper.go +++ b/pkg/gui/controllers/helpers/repos_helper.go @@ -22,13 +22,13 @@ type onNewRepoFn func(startArgs appTypes.StartArgs, reuseState bool) error // helps switch back and forth between repos type ReposHelper struct { - c *types.HelperCommon + c *HelperCommon recordDirectoryHelper *RecordDirectoryHelper onNewRepo onNewRepoFn } func NewRecentReposHelper( - c *types.HelperCommon, + c *HelperCommon, recordDirectoryHelper *RecordDirectoryHelper, onNewRepo onNewRepoFn, ) *ReposHelper { diff --git a/pkg/gui/controllers/helpers/snake_helper.go b/pkg/gui/controllers/helpers/snake_helper.go index 5f53273cf..fb4d67bb4 100644 --- a/pkg/gui/controllers/helpers/snake_helper.go +++ b/pkg/gui/controllers/helpers/snake_helper.go @@ -5,16 +5,15 @@ import ( "strings" "github.com/jesseduffield/lazygit/pkg/gui/style" - "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/snake" ) type SnakeHelper struct { - c *types.HelperCommon + c *HelperCommon game *snake.Game } -func NewSnakeHelper(c *types.HelperCommon) *SnakeHelper { +func NewSnakeHelper(c *HelperCommon) *SnakeHelper { return &SnakeHelper{ c: c, } diff --git a/pkg/gui/controllers/helpers/staging_helper.go b/pkg/gui/controllers/helpers/staging_helper.go index 4b4eb2626..dee6a0fa1 100644 --- a/pkg/gui/controllers/helpers/staging_helper.go +++ b/pkg/gui/controllers/helpers/staging_helper.go @@ -9,13 +9,13 @@ import ( ) type StagingHelper struct { - c *types.HelperCommon + c *HelperCommon git *commands.GitCommand contexts *context.ContextTree } func NewStagingHelper( - c *types.HelperCommon, + c *HelperCommon, git *commands.GitCommand, contexts *context.ContextTree, ) *StagingHelper { diff --git a/pkg/gui/controllers/helpers/suggestions_helper.go b/pkg/gui/controllers/helpers/suggestions_helper.go index 53a076f66..206fd371a 100644 --- a/pkg/gui/controllers/helpers/suggestions_helper.go +++ b/pkg/gui/controllers/helpers/suggestions_helper.go @@ -34,7 +34,7 @@ type ISuggestionsHelper interface { } type SuggestionsHelper struct { - c *types.HelperCommon + c *HelperCommon model *types.Model contexts *context.ContextTree @@ -43,7 +43,7 @@ type SuggestionsHelper struct { var _ ISuggestionsHelper = &SuggestionsHelper{} func NewSuggestionsHelper( - c *types.HelperCommon, + c *HelperCommon, model *types.Model, contexts *context.ContextTree, ) *SuggestionsHelper { diff --git a/pkg/gui/controllers/helpers/tags_helper.go b/pkg/gui/controllers/helpers/tags_helper.go index a2f2e9c77..7f17be222 100644 --- a/pkg/gui/controllers/helpers/tags_helper.go +++ b/pkg/gui/controllers/helpers/tags_helper.go @@ -10,11 +10,11 @@ import ( // and the commits context. type TagsHelper struct { - c *types.HelperCommon + c *HelperCommon git *commands.GitCommand } -func NewTagsHelper(c *types.HelperCommon, git *commands.GitCommand) *TagsHelper { +func NewTagsHelper(c *HelperCommon, git *commands.GitCommand) *TagsHelper { return &TagsHelper{ c: c, git: git, diff --git a/pkg/gui/controllers/helpers/update_helper.go b/pkg/gui/controllers/helpers/update_helper.go index 21bf2ad83..a9a49f0f4 100644 --- a/pkg/gui/controllers/helpers/update_helper.go +++ b/pkg/gui/controllers/helpers/update_helper.go @@ -7,11 +7,11 @@ import ( ) type UpdateHelper struct { - c *types.HelperCommon + c *HelperCommon updater *updates.Updater } -func NewUpdateHelper(c *types.HelperCommon, updater *updates.Updater) *UpdateHelper { +func NewUpdateHelper(c *HelperCommon, updater *updates.Updater) *UpdateHelper { return &UpdateHelper{ c: c, updater: updater, diff --git a/pkg/gui/controllers/helpers/upstream_helper.go b/pkg/gui/controllers/helpers/upstream_helper.go index a2d8e8ae2..b4825ffaa 100644 --- a/pkg/gui/controllers/helpers/upstream_helper.go +++ b/pkg/gui/controllers/helpers/upstream_helper.go @@ -9,7 +9,7 @@ import ( ) type UpstreamHelper struct { - c *types.HelperCommon + c *HelperCommon model *types.Model getRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion @@ -25,7 +25,7 @@ type IUpstreamHelper interface { var _ IUpstreamHelper = &UpstreamHelper{} func NewUpstreamHelper( - c *types.HelperCommon, + c *HelperCommon, model *types.Model, getRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion, ) *UpstreamHelper { diff --git a/pkg/gui/controllers/helpers/view_helper.go b/pkg/gui/controllers/helpers/view_helper.go index bbe7742cf..e1d837da5 100644 --- a/pkg/gui/controllers/helpers/view_helper.go +++ b/pkg/gui/controllers/helpers/view_helper.go @@ -6,11 +6,11 @@ import ( ) type ViewHelper struct { - c *types.HelperCommon + c *HelperCommon contexts *context.ContextTree } -func NewViewHelper(c *types.HelperCommon, contexts *context.ContextTree) *ViewHelper { +func NewViewHelper(c *HelperCommon, contexts *context.ContextTree) *ViewHelper { return &ViewHelper{ c: c, contexts: contexts, diff --git a/pkg/gui/controllers/helpers/window_helper.go b/pkg/gui/controllers/helpers/window_helper.go index 3b180ad80..8754cc41d 100644 --- a/pkg/gui/controllers/helpers/window_helper.go +++ b/pkg/gui/controllers/helpers/window_helper.go @@ -11,12 +11,12 @@ import ( ) type WindowHelper struct { - c *types.HelperCommon + c *HelperCommon viewHelper *ViewHelper contexts *context.ContextTree } -func NewWindowHelper(c *types.HelperCommon, viewHelper *ViewHelper, contexts *context.ContextTree) *WindowHelper { +func NewWindowHelper(c *HelperCommon, viewHelper *ViewHelper, contexts *context.ContextTree) *WindowHelper { return &WindowHelper{ c: c, viewHelper: viewHelper, diff --git a/pkg/gui/controllers/helpers/working_tree_helper.go b/pkg/gui/controllers/helpers/working_tree_helper.go index 17850b994..1e3c211b0 100644 --- a/pkg/gui/controllers/helpers/working_tree_helper.go +++ b/pkg/gui/controllers/helpers/working_tree_helper.go @@ -20,7 +20,7 @@ type IWorkingTreeHelper interface { } type WorkingTreeHelper struct { - c *types.HelperCommon + c *HelperCommon git *commands.GitCommand contexts *context.ContextTree refHelper *RefsHelper @@ -30,7 +30,7 @@ type WorkingTreeHelper struct { } func NewWorkingTreeHelper( - c *types.HelperCommon, + c *HelperCommon, git *commands.GitCommand, contexts *context.ContextTree, refHelper *RefsHelper, diff --git a/pkg/gui/controllers/list_controller.go b/pkg/gui/controllers/list_controller.go index c74d87244..0afb45d18 100644 --- a/pkg/gui/controllers/list_controller.go +++ b/pkg/gui/controllers/list_controller.go @@ -6,26 +6,26 @@ import ( ) type ListControllerFactory struct { - c *types.HelperCommon + *controllerCommon } -func NewListControllerFactory(c *types.HelperCommon) *ListControllerFactory { +func NewListControllerFactory(c *controllerCommon) *ListControllerFactory { return &ListControllerFactory{ - c: c, + controllerCommon: c, } } func (self *ListControllerFactory) Create(context types.IListContext) *ListController { return &ListController{ - baseController: baseController{}, - c: self.c, - context: context, + baseController: baseController{}, + controllerCommon: self.controllerCommon, + context: context, } } type ListController struct { baseController - c *types.HelperCommon + *controllerCommon context types.IListContext } diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index d3fdc4e50..85c1ff494 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -7,6 +7,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/gui/context" + "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" @@ -184,7 +185,7 @@ func (self *LocalCommitsController) GetOnRenderToMain() func() error { } } -func secondaryPatchPanelUpdateOpts(c *types.HelperCommon) *types.ViewUpdateOpts { +func secondaryPatchPanelUpdateOpts(c *helpers.HelperCommon) *types.ViewUpdateOpts { if c.Git().Patch.PatchBuilder.Active() { patch := c.Git().Patch.PatchBuilder.RenderAggregatedPatch(false) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 1b2918759..0ab45b526 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -127,8 +127,9 @@ type Gui struct { Updating bool - c *types.HelperCommon - helpers *helpers.Helpers + c *helpers.HelperCommon + contextCommon *context.ContextCommon + helpers *helpers.Helpers } type StateAccessor struct { @@ -385,6 +386,10 @@ func initialContext(contextTree *context.ContextTree, startArgs appTypes.StartAr return initialContext } +func (gui *Gui) Contexts() *context.ContextTree { + return gui.State.Contexts +} + // for now the split view will always be on // NewGui builds a new gui handler func NewGui( @@ -442,7 +447,8 @@ func NewGui( ) guiCommon := &guiCommon{gui: gui, IPopupHandler: gui.PopupHandler} - helperCommon := &types.HelperCommon{IGuiCommon: guiCommon, Common: cmn} + helperCommon := &helpers.HelperCommon{IGuiCommon: guiCommon, Common: cmn, IGetContexts: gui} + contextCommon := &context.ContextCommon{IGuiCommon: guiCommon, Common: cmn} credentialsHelper := helpers.NewCredentialsHelper(helperCommon) @@ -461,6 +467,8 @@ func NewGui( // TODO: reset these controllers upon changing repos due to state changing gui.c = helperCommon + gui.contextCommon = contextCommon + authors.SetCustomAuthors(gui.UserConfig.Gui.AuthorColors) icons.SetIconEnabled(gui.UserConfig.Gui.ShowIcons) presentation.SetCustomBranches(gui.UserConfig.Gui.BranchColors) diff --git a/pkg/gui/list_context_config.go b/pkg/gui/list_context_config.go index dda2d2379..a0fd1a751 100644 --- a/pkg/gui/list_context_config.go +++ b/pkg/gui/list_context_config.go @@ -6,55 +6,55 @@ import ( ) func (gui *Gui) menuListContext() *context.MenuContext { - return context.NewMenuContext(gui.c) + return context.NewMenuContext(gui.contextCommon) } func (gui *Gui) filesListContext() *context.WorkingTreeContext { - return context.NewWorkingTreeContext(gui.c) + return context.NewWorkingTreeContext(gui.contextCommon) } func (gui *Gui) branchesListContext() *context.BranchesContext { - return context.NewBranchesContext(gui.c) + return context.NewBranchesContext(gui.contextCommon) } func (gui *Gui) remotesListContext() *context.RemotesContext { - return context.NewRemotesContext(gui.c) + return context.NewRemotesContext(gui.contextCommon) } func (gui *Gui) remoteBranchesListContext() *context.RemoteBranchesContext { - return context.NewRemoteBranchesContext(gui.c) + return context.NewRemoteBranchesContext(gui.contextCommon) } func (gui *Gui) tagsListContext() *context.TagsContext { - return context.NewTagsContext(gui.c) + return context.NewTagsContext(gui.contextCommon) } func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext { - return context.NewLocalCommitsContext(gui.c) + return context.NewLocalCommitsContext(gui.contextCommon) } func (gui *Gui) subCommitsListContext() *context.SubCommitsContext { - return context.NewSubCommitsContext(gui.c) + return context.NewSubCommitsContext(gui.contextCommon) } func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext { - return context.NewReflogCommitsContext(gui.c) + return context.NewReflogCommitsContext(gui.contextCommon) } func (gui *Gui) stashListContext() *context.StashContext { - return context.NewStashContext(gui.c) + return context.NewStashContext(gui.contextCommon) } func (gui *Gui) commitFilesListContext() *context.CommitFilesContext { - return context.NewCommitFilesContext(gui.c) + return context.NewCommitFilesContext(gui.contextCommon) } func (gui *Gui) submodulesListContext() *context.SubmodulesContext { - return context.NewSubmodulesContext(gui.c) + return context.NewSubmodulesContext(gui.contextCommon) } func (gui *Gui) suggestionsListContext() *context.SuggestionsContext { - return context.NewSuggestionsContext(gui.c) + return context.NewSuggestionsContext(gui.contextCommon) } func (gui *Gui) getListContexts() []types.IListContext { diff --git a/pkg/gui/options_map.go b/pkg/gui/options_map.go index 617e80354..5f5c008dd 100644 --- a/pkg/gui/options_map.go +++ b/pkg/gui/options_map.go @@ -4,13 +4,14 @@ import ( "fmt" "strings" + "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/keybindings" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/samber/lo" ) type OptionsMapMgr struct { - c *types.HelperCommon + c *helpers.HelperCommon } func (gui *Gui) renderContextOptionsMap(c types.Context) { diff --git a/pkg/gui/services/custom_commands/client.go b/pkg/gui/services/custom_commands/client.go index aeaae084e..4db916a66 100644 --- a/pkg/gui/services/custom_commands/client.go +++ b/pkg/gui/services/custom_commands/client.go @@ -18,7 +18,7 @@ type Client struct { } func NewClient( - c *types.HelperCommon, + c *helpers.HelperCommon, os *oscommands.OSCommand, git *commands.GitCommand, contexts *context.ContextTree, diff --git a/pkg/gui/services/custom_commands/handler_creator.go b/pkg/gui/services/custom_commands/handler_creator.go index 4a81b08b5..2772d0c1a 100644 --- a/pkg/gui/services/custom_commands/handler_creator.go +++ b/pkg/gui/services/custom_commands/handler_creator.go @@ -8,6 +8,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/config" + "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" @@ -15,7 +16,7 @@ import ( // takes a custom command and returns a function that will be called when the corresponding user-defined keybinding is pressed type HandlerCreator struct { - c *types.HelperCommon + c *helpers.HelperCommon os *oscommands.OSCommand git *commands.GitCommand sessionStateLoader *SessionStateLoader @@ -24,7 +25,7 @@ type HandlerCreator struct { } func NewHandlerCreator( - c *types.HelperCommon, + c *helpers.HelperCommon, os *oscommands.OSCommand, git *commands.GitCommand, sessionStateLoader *SessionStateLoader, diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index e1d73bef7..81c2cb385 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -15,6 +15,10 @@ import ( ) type HelperCommon struct { + *ContextCommon +} + +type ContextCommon struct { *common.Common IGuiCommon }