diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-03-23 12:35:07 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-04-30 13:19:53 +1000 |
commit | 43251e727596cca2538548976769e47a1bfc5593 (patch) | |
tree | 280e4f0609ca58bbbaeb80446fa0d14a7e58a993 /pkg | |
parent | f08135894344583394240f240377015ea874b03b (diff) |
split context common from helper common
Diffstat (limited to 'pkg')
55 files changed, 156 insertions, 133 deletions
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.gi |