mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-15 11:56:37 +02:00
move getModel functions into contexts
This commit is contained in:
parent
47b91f1ef5
commit
0e5a4c7a36
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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{
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
func NewWorkingTreeContext(c *types.HelperCommon) *WorkingTreeContext {
|
||||
viewModel := filetree.NewFileTreeViewModel(
|
||||
func() []*models.File { return c.Model().Files },
|
||||
c.Log,
|
||||
c.UserConfig.Gui.ShowFileTree,
|
||||
)
|
||||
|
||||
c *types.HelperCommon,
|
||||
) *WorkingTreeContext {
|
||||
viewModel := filetree.NewFileTreeViewModel(getModel, 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,
|
||||
|
@ -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)
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user