From 47b91f1ef5c1bf08e56c4ed170e671d985280932 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 21 Mar 2023 21:06:39 +1100 Subject: [PATCH] move views into contexts --- pkg/gui/context/branches_context.go | 4 +--- pkg/gui/context/commit_files_context.go | 4 +--- pkg/gui/context/local_commits_context.go | 4 +--- pkg/gui/context/merge_conflicts_context.go | 5 +---- pkg/gui/context/reflog_commits_context.go | 4 +--- pkg/gui/context/remote_branches_context.go | 4 +--- pkg/gui/context/remotes_context.go | 4 +--- pkg/gui/context/stash_context.go | 4 +--- pkg/gui/context/sub_commits_context.go | 4 +--- pkg/gui/context/submodules_context.go | 4 +--- pkg/gui/context/tags_context.go | 4 +--- pkg/gui/context/working_tree_context.go | 4 +--- pkg/gui/context_config.go | 1 - pkg/gui/list_context_config.go | 11 ----------- 14 files changed, 12 insertions(+), 49 deletions(-) diff --git a/pkg/gui/context/branches_context.go b/pkg/gui/context/branches_context.go index 05feed145..f891d3117 100644 --- a/pkg/gui/context/branches_context.go +++ b/pkg/gui/context/branches_context.go @@ -1,7 +1,6 @@ package context import ( - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -18,7 +17,6 @@ var ( func NewBranchesContext( getModel func() []*models.Branch, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -29,7 +27,7 @@ func NewBranchesContext( BasicViewModel: viewModel, ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().Branches, WindowName: "branches", Key: LOCAL_BRANCHES_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go index 92ff153b3..eb5f41074 100644 --- a/pkg/gui/context/commit_files_context.go +++ b/pkg/gui/context/commit_files_context.go @@ -1,7 +1,6 @@ package context import ( - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/filetree" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -20,7 +19,6 @@ var ( func NewCommitFilesContext( getModel func() []*models.CommitFile, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -33,7 +31,7 @@ func NewCommitFilesContext( ListContextTrait: &ListContextTrait{ Context: NewSimpleContext( NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().CommitFiles, WindowName: "commits", Key: COMMIT_FILES_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index b700a39af..fdadeb4a3 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -1,7 +1,6 @@ package context import ( - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -18,7 +17,6 @@ var ( func NewLocalCommitsContext( getModel func() []*models.Commit, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -30,7 +28,7 @@ func NewLocalCommitsContext( ViewportListContextTrait: &ViewportListContextTrait{ ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().Commits, WindowName: "commits", Key: LOCAL_COMMITS_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context/merge_conflicts_context.go b/pkg/gui/context/merge_conflicts_context.go index 72dc7761e..97024eedb 100644 --- a/pkg/gui/context/merge_conflicts_context.go +++ b/pkg/gui/context/merge_conflicts_context.go @@ -3,7 +3,6 @@ package context import ( "math" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/sasha-s/go-deadlock" @@ -25,8 +24,6 @@ type ConflictsViewModel struct { } func NewMergeConflictsContext( - view *gocui.View, - c *types.HelperCommon, ) *MergeConflictsContext { viewModel := &ConflictsViewModel{ @@ -40,7 +37,7 @@ func NewMergeConflictsContext( Context: NewSimpleContext( NewBaseContext(NewBaseContextOpts{ Kind: types.MAIN_CONTEXT, - View: view, + View: c.Views().MergeConflicts, WindowName: "main", Key: MERGE_CONFLICTS_CONTEXT_KEY, Focusable: true, diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go index 920699d21..157845079 100644 --- a/pkg/gui/context/reflog_commits_context.go +++ b/pkg/gui/context/reflog_commits_context.go @@ -1,7 +1,6 @@ package context import ( - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -18,7 +17,6 @@ var ( func NewReflogCommitsContext( getModel func() []*models.Commit, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -29,7 +27,7 @@ func NewReflogCommitsContext( BasicViewModel: viewModel, ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().ReflogCommits, WindowName: "commits", Key: REFLOG_COMMITS_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context/remote_branches_context.go b/pkg/gui/context/remote_branches_context.go index fc185c953..4f6f173d6 100644 --- a/pkg/gui/context/remote_branches_context.go +++ b/pkg/gui/context/remote_branches_context.go @@ -1,7 +1,6 @@ package context import ( - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -19,7 +18,6 @@ var ( func NewRemoteBranchesContext( getModel func() []*models.RemoteBranch, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -31,7 +29,7 @@ func NewRemoteBranchesContext( DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.RemoteBranchesDynamicTitle), ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().RemoteBranches, WindowName: "branches", Key: REMOTE_BRANCHES_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context/remotes_context.go b/pkg/gui/context/remotes_context.go index cb3476a4e..a3593e672 100644 --- a/pkg/gui/context/remotes_context.go +++ b/pkg/gui/context/remotes_context.go @@ -1,7 +1,6 @@ package context import ( - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -18,7 +17,6 @@ var ( func NewRemotesContext( getModel func() []*models.Remote, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -29,7 +27,7 @@ func NewRemotesContext( BasicViewModel: viewModel, ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().Remotes, WindowName: "branches", Key: REMOTES_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context/stash_context.go b/pkg/gui/context/stash_context.go index 7d5891be8..81540fecb 100644 --- a/pkg/gui/context/stash_context.go +++ b/pkg/gui/context/stash_context.go @@ -1,7 +1,6 @@ package context import ( - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -18,7 +17,6 @@ var ( func NewStashContext( getModel func() []*models.StashEntry, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -29,7 +27,7 @@ func NewStashContext( BasicViewModel: viewModel, ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().Stash, WindowName: "stash", Key: STASH_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index f4bf2360f..868dbf920 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -3,7 +3,6 @@ package context import ( "fmt" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" @@ -22,7 +21,6 @@ var ( func NewSubCommitsContext( getModel func() []*models.Commit, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -39,7 +37,7 @@ func NewSubCommitsContext( ViewportListContextTrait: &ViewportListContextTrait{ ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().SubCommits, WindowName: "branches", Key: SUB_COMMITS_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context/submodules_context.go b/pkg/gui/context/submodules_context.go index acc1d6ef0..ed074e016 100644 --- a/pkg/gui/context/submodules_context.go +++ b/pkg/gui/context/submodules_context.go @@ -1,7 +1,6 @@ package context import ( - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -15,7 +14,6 @@ var _ types.IListContext = (*SubmodulesContext)(nil) func NewSubmodulesContext( getModel func() []*models.SubmoduleConfig, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -26,7 +24,7 @@ func NewSubmodulesContext( BasicViewModel: viewModel, ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().Submodules, WindowName: "files", Key: SUBMODULES_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go index b276516eb..a16a2e653 100644 --- a/pkg/gui/context/tags_context.go +++ b/pkg/gui/context/tags_context.go @@ -1,7 +1,6 @@ package context import ( - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -18,7 +17,6 @@ var ( func NewTagsContext( getModel func() []*models.Tag, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -29,7 +27,7 @@ func NewTagsContext( BasicViewModel: viewModel, ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().Tags, WindowName: "branches", Key: TAGS_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context/working_tree_context.go b/pkg/gui/context/working_tree_context.go index 29b255cd3..3dd6c8279 100644 --- a/pkg/gui/context/working_tree_context.go +++ b/pkg/gui/context/working_tree_context.go @@ -1,7 +1,6 @@ package context import ( - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/filetree" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -16,7 +15,6 @@ var _ types.IListContext = (*WorkingTreeContext)(nil) func NewWorkingTreeContext( getModel func() []*models.File, - view *gocui.View, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, @@ -27,7 +25,7 @@ func NewWorkingTreeContext( FileTreeViewModel: viewModel, ListContextTrait: &ListContextTrait{ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, + View: c.Views().Files, WindowName: "files", Key: FILES_CONTEXT_KEY, Kind: types.SIDE_CONTEXT, diff --git a/pkg/gui/context_config.go b/pkg/gui/context_config.go index 4324df137..2c98478d9 100644 --- a/pkg/gui/context_config.go +++ b/pkg/gui/context_config.go @@ -107,7 +107,6 @@ func (gui *Gui) contextTree() *context.ContextTree { }), ), MergeConflicts: context.NewMergeConflictsContext( - gui.Views.MergeConflicts, gui.c, ), Confirmation: context.NewConfirmationContext(gui.c), diff --git a/pkg/gui/list_context_config.go b/pkg/gui/list_context_config.go index 9ce638897..c5c56a1ac 100644 --- a/pkg/gui/list_context_config.go +++ b/pkg/gui/list_context_config.go @@ -20,7 +20,6 @@ func (gui *Gui) menuListContext() *context.MenuContext { func (gui *Gui) filesListContext() *context.WorkingTreeContext { return context.NewWorkingTreeContext( func() []*models.File { return gui.State.Model.Files }, - gui.Views.Files, func(startIdx int, length int) [][]string { lines := presentation.RenderFileTree(gui.State.Contexts.Files.FileTreeViewModel, gui.State.Modes.Diffing.Ref, gui.State.Model.Submodules) return slices.Map(lines, func(line string) []string { @@ -34,7 +33,6 @@ func (gui *Gui) filesListContext() *context.WorkingTreeContext { func (gui *Gui) branchesListContext() *context.BranchesContext { return context.NewBranchesContext( func() []*models.Branch { return gui.State.Model.Branches }, - gui.Views.Branches, func(startIdx int, length int) [][]string { return presentation.GetBranchListDisplayStrings(gui.State.Model.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Modes.Diffing.Ref, gui.Tr) }, @@ -45,7 +43,6 @@ func (gui *Gui) branchesListContext() *context.BranchesContext { func (gui *Gui) remotesListContext() *context.RemotesContext { return context.NewRemotesContext( func() []*models.Remote { return gui.State.Model.Remotes }, - gui.Views.Remotes, func(startIdx int, length int) [][]string { return presentation.GetRemoteListDisplayStrings(gui.State.Model.Remotes, gui.State.Modes.Diffing.Ref) }, @@ -56,7 +53,6 @@ func (gui *Gui) remotesListContext() *context.RemotesContext { func (gui *Gui) remoteBranchesListContext() *context.RemoteBranchesContext { return context.NewRemoteBranchesContext( func() []*models.RemoteBranch { return gui.State.Model.RemoteBranches }, - gui.Views.RemoteBranches, func(startIdx int, length int) [][]string { return presentation.GetRemoteBranchListDisplayStrings(gui.State.Model.RemoteBranches, gui.State.Modes.Diffing.Ref) }, @@ -77,7 +73,6 @@ func (gui *Gui) withDiffModeCheck(f func() error) func() error { func (gui *Gui) tagsListContext() *context.TagsContext { return context.NewTagsContext( func() []*models.Tag { return gui.State.Model.Tags }, - gui.Views.Tags, func(startIdx int, length int) [][]string { return presentation.GetTagListDisplayStrings(gui.State.Model.Tags, gui.State.Modes.Diffing.Ref) }, @@ -88,7 +83,6 @@ func (gui *Gui) tagsListContext() *context.TagsContext { func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext { return context.NewLocalCommitsContext( func() []*models.Commit { return gui.State.Model.Commits }, - gui.Views.Commits, func(startIdx int, length int) [][]string { selectedCommitSha := "" if gui.c.CurrentContext().GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY { @@ -123,7 +117,6 @@ func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext { func (gui *Gui) subCommitsListContext() *context.SubCommitsContext { return context.NewSubCommitsContext( func() []*models.Commit { return gui.State.Model.SubCommits }, - gui.Views.SubCommits, func(startIdx int, length int) [][]string { selectedCommitSha := "" if gui.c.CurrentContext().GetKey() == context.SUB_COMMITS_CONTEXT_KEY { @@ -174,7 +167,6 @@ func (gui *Gui) shouldShowGraph() bool { func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext { return context.NewReflogCommitsContext( func() []*models.Commit { return gui.State.Model.FilteredReflogCommits }, - gui.Views.ReflogCommits, func(startIdx int, length int) [][]string { return presentation.GetReflogCommitListDisplayStrings( gui.State.Model.FilteredReflogCommits, @@ -192,7 +184,6 @@ func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext { func (gui *Gui) stashListContext() *context.StashContext { return context.NewStashContext( func() []*models.StashEntry { return gui.State.Model.StashEntries }, - gui.Views.Stash, func(startIdx int, length int) [][]string { return presentation.GetStashEntryListDisplayStrings(gui.State.Model.StashEntries, gui.State.Modes.Diffing.Ref) }, @@ -203,7 +194,6 @@ func (gui *Gui) stashListContext() *context.StashContext { func (gui *Gui) commitFilesListContext() *context.CommitFilesContext { return context.NewCommitFilesContext( func() []*models.CommitFile { return gui.State.Model.CommitFiles }, - gui.Views.CommitFiles, func(startIdx int, length int) [][]string { if gui.State.Contexts.CommitFiles.CommitFileTreeViewModel.Len() == 0 { return [][]string{{style.FgRed.Sprint("(none)")}} @@ -221,7 +211,6 @@ func (gui *Gui) commitFilesListContext() *context.CommitFilesContext { func (gui *Gui) submodulesListContext() *context.SubmodulesContext { return context.NewSubmodulesContext( func() []*models.SubmoduleConfig { return gui.State.Model.Submodules }, - gui.Views.Submodules, func(startIdx int, length int) [][]string { return presentation.GetSubmoduleListDisplayStrings(gui.State.Model.Submodules) },