summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-03-21 21:16:30 +1100
committerJesse Duffield <jessedduffield@gmail.com>2023-04-30 13:19:53 +1000
commit0e5a4c7a3629b3fcbb029f7398ebb2666ffe4a54 (patch)
treec9df88d6a7bf4a46854fd8b5ff5e99eea90a273f /pkg/gui/context
parent47b91f1ef5c1bf08e56c4ed170e671d985280932 (diff)
move getModel functions into contexts
Diffstat (limited to 'pkg/gui/context')
-rw-r--r--pkg/gui/context/branches_context.go3
-rw-r--r--pkg/gui/context/commit_files_context.go7
-rw-r--r--pkg/gui/context/local_commits_context.go6
-rw-r--r--pkg/gui/context/reflog_commits_context.go3
-rw-r--r--pkg/gui/context/remote_branches_context.go3
-rw-r--r--pkg/gui/context/remotes_context.go3
-rw-r--r--pkg/gui/context/stash_context.go3
-rw-r--r--pkg/gui/context/sub_commits_context.go9
-rw-r--r--pkg/gui/context/submodules_context.go3
-rw-r--r--pkg/gui/context/tags_context.go3
-rw-r--r--pkg/gui/context/working_tree_context.go22
11 files changed, 36 insertions, 29 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,