diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-03-21 21:16:30 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-04-30 13:19:53 +1000 |
commit | 0e5a4c7a3629b3fcbb029f7398ebb2666ffe4a54 (patch) | |
tree | c9df88d6a7bf4a46854fd8b5ff5e99eea90a273f /pkg | |
parent | 47b91f1ef5c1bf08e56c4ed170e671d985280932 (diff) |
move getModel functions into contexts
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/context/branches_context.go | 3 | ||||
-rw-r--r-- | pkg/gui/context/commit_files_context.go | 7 | ||||
-rw-r--r-- | pkg/gui/context/local_commits_context.go | 6 | ||||
-rw-r--r-- | pkg/gui/context/reflog_commits_context.go | 3 | ||||
-rw-r--r-- | pkg/gui/context/remote_branches_context.go | 3 | ||||
-rw-r--r-- | pkg/gui/context/remotes_context.go | 3 | ||||
-rw-r--r-- | pkg/gui/context/stash_context.go | 3 | ||||
-rw-r--r-- | pkg/gui/context/sub_commits_context.go | 9 | ||||
-rw-r--r-- | pkg/gui/context/submodules_context.go | 3 | ||||
-rw-r--r-- | pkg/gui/context/tags_context.go | 3 | ||||
-rw-r--r-- | pkg/gui/context/working_tree_context.go | 22 | ||||
-rw-r--r-- | pkg/gui/list_context_config.go | 22 |
12 files changed, 37 insertions, 50 deletions
diff --git a/pkg/gui/context/branches_context.go b/pkg/gui/context/branches_context.go index f891d3117..6b624ca57 100644 --- a/pkg/gui/context/branches_context.go +++ b/pkg/gui/context/branches_context.go @@ -16,12 +16,11 @@ var ( ) func NewBranchesContext( - getModel func() []*models.Branch, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, ) *BranchesContext { - viewModel := NewBasicViewModel(getModel) + viewModel := NewBasicViewModel(func() []*models.Branch { return c.Model().Branches }) self := &BranchesContext{ BasicViewModel: viewModel, diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go index eb5f41074..f7ee4a930 100644 --- a/pkg/gui/context/commit_files_context.go +++ b/pkg/gui/context/commit_files_context.go @@ -18,12 +18,15 @@ var ( ) func NewCommitFilesContext( - getModel func() []*models.CommitFile, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, ) *CommitFilesContext { - viewModel := filetree.NewCommitFileTreeViewModel(getModel, c.Log, c.UserConfig.Gui.ShowFileTree) + viewModel := filetree.NewCommitFileTreeViewModel( + func() []*models.CommitFile { return c.Model().CommitFiles }, + c.Log, + c.UserConfig.Gui.ShowFileTree, + ) return &CommitFilesContext{ CommitFileTreeViewModel: viewModel, diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index fdadeb4a3..4ce8f9c64 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -16,12 +16,14 @@ var ( ) func NewLocalCommitsContext( - getModel func() []*models.Commit, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, ) *LocalCommitsContext { - viewModel := NewLocalCommitsViewModel(getModel, c) + viewModel := NewLocalCommitsViewModel( + func() []*models.Commit { return c.Model().Commits }, + c, + ) return &LocalCommitsContext{ LocalCommitsViewModel: viewModel, diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go index 157845079..6a50ed422 100644 --- a/pkg/gui/context/reflog_commits_context.go +++ b/pkg/gui/context/reflog_commits_context.go @@ -16,12 +16,11 @@ var ( ) func NewReflogCommitsContext( - getModel func() []*models.Commit, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, ) *ReflogCommitsContext { - viewModel := NewBasicViewModel(getModel) + viewModel := NewBasicViewModel(func() []*models.Commit { return c.Model().FilteredReflogCommits }) return &ReflogCommitsContext{ BasicViewModel: viewModel, diff --git a/pkg/gui/context/remote_branches_context.go b/pkg/gui/context/remote_branches_context.go index 4f6f173d6..78a72001e 100644 --- a/pkg/gui/context/remote_branches_context.go +++ b/pkg/gui/context/remote_branches_context.go @@ -17,12 +17,11 @@ var ( ) func NewRemoteBranchesContext( - getModel func() []*models.RemoteBranch, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, ) *RemoteBranchesContext { - viewModel := NewBasicViewModel(getModel) + viewModel := NewBasicViewModel(func() []*models.RemoteBranch { return c.Model().RemoteBranches }) return &RemoteBranchesContext{ BasicViewModel: viewModel, diff --git a/pkg/gui/context/remotes_context.go b/pkg/gui/context/remotes_context.go index a3593e672..402c1bef4 100644 --- a/pkg/gui/context/remotes_context.go +++ b/pkg/gui/context/remotes_context.go @@ -16,12 +16,11 @@ var ( ) func NewRemotesContext( - getModel func() []*models.Remote, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, ) *RemotesContext { - viewModel := NewBasicViewModel(getModel) + viewModel := NewBasicViewModel(func() []*models.Remote { return c.Model().Remotes }) return &RemotesContext{ BasicViewModel: viewModel, diff --git a/pkg/gui/context/stash_context.go b/pkg/gui/context/stash_context.go index 81540fecb..f9ed354b9 100644 --- a/pkg/gui/context/stash_context.go +++ b/pkg/gui/context/stash_context.go @@ -16,12 +16,11 @@ var ( ) func NewStashContext( - getModel func() []*models.StashEntry, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, ) *StashContext { - viewModel := NewBasicViewModel(getModel) + viewModel := NewBasicViewModel(func() []*models.StashEntry { return c.Model().StashEntries }) return &StashContext{ BasicViewModel: viewModel, diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index 868dbf920..160d905e3 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -20,15 +20,16 @@ var ( ) func NewSubCommitsContext( - getModel func() []*models.Commit, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, ) *SubCommitsContext { viewModel := &SubCommitsViewModel{ - BasicViewModel: NewBasicViewModel(getModel), - ref: nil, - limitCommits: true, + BasicViewModel: NewBasicViewModel( + func() []*models.Commit { return c.Model().SubCommits }, + ), + ref: nil, + limitCommits: true, } return &SubCommitsContext{ diff --git a/pkg/gui/context/submodules_context.go b/pkg/gui/context/submodules_context.go index ed074e016..83564dfa5 100644 --- a/pkg/gui/context/submodules_context.go +++ b/pkg/gui/context/submodules_context.go @@ -13,12 +13,11 @@ type SubmodulesContext struct { var _ types.IListContext = (*SubmodulesContext)(nil) func NewSubmodulesContext( - getModel func() []*models.SubmoduleConfig, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, ) *SubmodulesContext { - viewModel := NewBasicViewModel(getModel) + viewModel := NewBasicViewModel(func() []*models.SubmoduleConfig { return c.Model().Submodules }) return &SubmodulesContext{ BasicViewModel: viewModel, diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go index a16a2e653..c71a6eef9 100644 --- a/pkg/gui/context/tags_context.go +++ b/pkg/gui/context/tags_context.go @@ -16,12 +16,11 @@ var ( ) func NewTagsContext( - getModel func() []*models.Tag, getDisplayStrings func(startIdx int, length int) [][]string, c *types.HelperCommon, ) *TagsContext { - viewModel := NewBasicViewModel(getModel) + viewModel := NewBasicViewModel(func() []*models.Tag { return c.Model().Tags }) return &TagsContext{ BasicViewModel: viewModel, diff --git a/pkg/gui/context/working_tree_context.go b/pkg/gui/context/working_tree_context.go index 3dd6c8279..5cb73ad13 100644 --- a/pkg/gui/context/working_tree_context.go +++ b/pkg/gui/context/working_tree_context.go @@ -1,8 +1,10 @@ package context import ( + "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/filetree" + "github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -13,13 +15,19 @@ type WorkingTreeContext struct { var _ types.IListContext = (*WorkingTreeContext)(nil) -func NewWorkingTreeContext( - getModel func() []*models.File, - getDisplayStrings func(startIdx int, length int) [][]string, - - c *types.HelperCommon, -) *WorkingTreeContext { - viewModel := filetree.NewFileTreeViewModel(getModel, c.Log, c.UserConfig.Gui.ShowFileTree) +func NewWorkingTreeContext(c *types.HelperCommon) *WorkingTreeContext { + viewModel := filetree.NewFileTreeViewModel( + func() []*models.File { return c.Model().Files }, + c.Log, + c.UserConfig.Gui.ShowFileTree, + ) + + getDisplayStrings := func(startIdx int, length int) [][]string { + lines := presentation.RenderFileTree(viewModel, c.Modes().Diffing.Ref, c.Model().Submodules) + return slices.Map(lines, func(line string) []string { + return []string{line} + }) + } return &WorkingTreeContext{ FileTreeViewModel: viewModel, diff --git a/pkg/gui/list_context_config.go b/pkg/gui/list_context_config.go index c5c56a1ac..4a05a1cd4 100644 --- a/pkg/gui/list_context_config.go +++ b/pkg/gui/list_context_config.go @@ -5,7 +5,6 @@ import ( "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" - "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/presentation" @@ -18,21 +17,11 @@ func (gui *Gui) menuListContext() *context.MenuContext { } func (gui *Gui) filesListContext() *context.WorkingTreeContext { - return context.NewWorkingTreeContext( - func() []*models.File { return gui.State.Model.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 { - return []string{line} - }) - }, - gui.c, - ) + return context.NewWorkingTreeContext(gui.c) } func (gui *Gui) branchesListContext() *context.BranchesContext { return context.NewBranchesContext( - func() []*models.Branch { return gui.State.Model.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) }, @@ -42,7 +31,6 @@ func (gui *Gui) branchesListContext() *context.BranchesContext { func (gui *Gui) remotesListContext() *context.RemotesContext { return context.NewRemotesContext( - func() []*models.Remote { return gui.State.Model.Remotes }, func(startIdx int, length int) [][]string { return presentation.GetRemoteListDisplayStrings(gui.State.Model.Remotes, gui.State.Modes.Diffing.Ref) }, @@ -52,7 +40,6 @@ func (gui *Gui) remotesListContext() *context.RemotesContext { func (gui *Gui) remoteBranchesListContext() *context.RemoteBranchesContext { return context.NewRemoteBranchesContext( - func() []*models.RemoteBranch { return gui.State.Model.RemoteBranches }, func(startIdx int, length int) [][]string { return presentation.GetRemoteBranchListDisplayStrings(gui.State.Model.RemoteBranches, gui.State.Modes.Diffing.Ref) }, @@ -72,7 +59,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 }, func(startIdx int, length int) [][]string { return presentation.GetTagListDisplayStrings(gui.State.Model.Tags, gui.State.Modes.Diffing.Ref) }, @@ -82,7 +68,6 @@ func (gui *Gui) tagsListContext() *context.TagsContext { func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext { return context.NewLocalCommitsContext( - func() []*models.Commit { return gui.State.Model.Commits }, func(startIdx int, length int) [][]string { selectedCommitSha := "" if gui.c.CurrentContext().GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY { @@ -116,7 +101,6 @@ func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext { func (gui *Gui) subCommitsListContext() *context.SubCommitsContext { return context.NewSubCommitsContext( - func() []*models.Commit { return gui.State.Model.SubCommits }, func(startIdx int, length int) [][]string { selectedCommitSha := "" if gui.c.CurrentContext().GetKey() == context.SUB_COMMITS_CONTEXT_KEY { @@ -166,7 +150,6 @@ func (gui *Gui) shouldShowGraph() bool { func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext { return context.NewReflogCommitsContext( - func() []*models.Commit { return gui.State.Model.FilteredReflogCommits }, func(startIdx int, length int) [][]string { return presentation.GetReflogCommitListDisplayStrings( gui.State.Model.FilteredReflogCommits, @@ -183,7 +166,6 @@ func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext { func (gui *Gui) stashListContext() *context.StashContext { return context.NewStashContext( - func() []*models.StashEntry { return gui.State.Model.StashEntries }, func(startIdx int, length int) [][]string { return presentation.GetStashEntryListDisplayStrings(gui.State.Model.StashEntries, gui.State.Modes.Diffing.Ref) }, @@ -193,7 +175,6 @@ func (gui *Gui) stashListContext() *context.StashContext { func (gui *Gui) commitFilesListContext() *context.CommitFilesContext { return context.NewCommitFilesContext( - func() []*models.CommitFile { return gui.State.Model.CommitFiles }, func(startIdx int, length int) [][]string { if gui.State.Contexts.CommitFiles.CommitFileTreeViewModel.Len() == 0 { return [][]string{{style.FgRed.Sprint("(none)")}} @@ -210,7 +191,6 @@ func (gui *Gui) commitFilesListContext() *context.CommitFilesContext { func (gui *Gui) submodulesListContext() *context.SubmodulesContext { return context.NewSubmodulesContext( - func() []*models.SubmoduleConfig { return gui.State.Model.Submodules }, func(startIdx int, length int) [][]string { return presentation.GetSubmoduleListDisplayStrings(gui.State.Model.Submodules) }, |