mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
move getModel functions into contexts
This commit is contained in:
@ -16,12 +16,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewBranchesContext(
|
func NewBranchesContext(
|
||||||
getModel func() []*models.Branch,
|
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
||||||
|
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
) *BranchesContext {
|
) *BranchesContext {
|
||||||
viewModel := NewBasicViewModel(getModel)
|
viewModel := NewBasicViewModel(func() []*models.Branch { return c.Model().Branches })
|
||||||
|
|
||||||
self := &BranchesContext{
|
self := &BranchesContext{
|
||||||
BasicViewModel: viewModel,
|
BasicViewModel: viewModel,
|
||||||
|
@ -18,12 +18,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewCommitFilesContext(
|
func NewCommitFilesContext(
|
||||||
getModel func() []*models.CommitFile,
|
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
||||||
|
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
) *CommitFilesContext {
|
) *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{
|
return &CommitFilesContext{
|
||||||
CommitFileTreeViewModel: viewModel,
|
CommitFileTreeViewModel: viewModel,
|
||||||
|
@ -16,12 +16,14 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewLocalCommitsContext(
|
func NewLocalCommitsContext(
|
||||||
getModel func() []*models.Commit,
|
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
||||||
|
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
) *LocalCommitsContext {
|
) *LocalCommitsContext {
|
||||||
viewModel := NewLocalCommitsViewModel(getModel, c)
|
viewModel := NewLocalCommitsViewModel(
|
||||||
|
func() []*models.Commit { return c.Model().Commits },
|
||||||
|
c,
|
||||||
|
)
|
||||||
|
|
||||||
return &LocalCommitsContext{
|
return &LocalCommitsContext{
|
||||||
LocalCommitsViewModel: viewModel,
|
LocalCommitsViewModel: viewModel,
|
||||||
|
@ -16,12 +16,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewReflogCommitsContext(
|
func NewReflogCommitsContext(
|
||||||
getModel func() []*models.Commit,
|
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
||||||
|
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
) *ReflogCommitsContext {
|
) *ReflogCommitsContext {
|
||||||
viewModel := NewBasicViewModel(getModel)
|
viewModel := NewBasicViewModel(func() []*models.Commit { return c.Model().FilteredReflogCommits })
|
||||||
|
|
||||||
return &ReflogCommitsContext{
|
return &ReflogCommitsContext{
|
||||||
BasicViewModel: viewModel,
|
BasicViewModel: viewModel,
|
||||||
|
@ -17,12 +17,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewRemoteBranchesContext(
|
func NewRemoteBranchesContext(
|
||||||
getModel func() []*models.RemoteBranch,
|
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
||||||
|
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
) *RemoteBranchesContext {
|
) *RemoteBranchesContext {
|
||||||
viewModel := NewBasicViewModel(getModel)
|
viewModel := NewBasicViewModel(func() []*models.RemoteBranch { return c.Model().RemoteBranches })
|
||||||
|
|
||||||
return &RemoteBranchesContext{
|
return &RemoteBranchesContext{
|
||||||
BasicViewModel: viewModel,
|
BasicViewModel: viewModel,
|
||||||
|
@ -16,12 +16,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewRemotesContext(
|
func NewRemotesContext(
|
||||||
getModel func() []*models.Remote,
|
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
||||||
|
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
) *RemotesContext {
|
) *RemotesContext {
|
||||||
viewModel := NewBasicViewModel(getModel)
|
viewModel := NewBasicViewModel(func() []*models.Remote { return c.Model().Remotes })
|
||||||
|
|
||||||
return &RemotesContext{
|
return &RemotesContext{
|
||||||
BasicViewModel: viewModel,
|
BasicViewModel: viewModel,
|
||||||
|
@ -16,12 +16,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewStashContext(
|
func NewStashContext(
|
||||||
getModel func() []*models.StashEntry,
|
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
||||||
|
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
) *StashContext {
|
) *StashContext {
|
||||||
viewModel := NewBasicViewModel(getModel)
|
viewModel := NewBasicViewModel(func() []*models.StashEntry { return c.Model().StashEntries })
|
||||||
|
|
||||||
return &StashContext{
|
return &StashContext{
|
||||||
BasicViewModel: viewModel,
|
BasicViewModel: viewModel,
|
||||||
|
@ -20,15 +20,16 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewSubCommitsContext(
|
func NewSubCommitsContext(
|
||||||
getModel func() []*models.Commit,
|
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
||||||
|
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
) *SubCommitsContext {
|
) *SubCommitsContext {
|
||||||
viewModel := &SubCommitsViewModel{
|
viewModel := &SubCommitsViewModel{
|
||||||
BasicViewModel: NewBasicViewModel(getModel),
|
BasicViewModel: NewBasicViewModel(
|
||||||
ref: nil,
|
func() []*models.Commit { return c.Model().SubCommits },
|
||||||
limitCommits: true,
|
),
|
||||||
|
ref: nil,
|
||||||
|
limitCommits: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &SubCommitsContext{
|
return &SubCommitsContext{
|
||||||
|
@ -13,12 +13,11 @@ type SubmodulesContext struct {
|
|||||||
var _ types.IListContext = (*SubmodulesContext)(nil)
|
var _ types.IListContext = (*SubmodulesContext)(nil)
|
||||||
|
|
||||||
func NewSubmodulesContext(
|
func NewSubmodulesContext(
|
||||||
getModel func() []*models.SubmoduleConfig,
|
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
||||||
|
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
) *SubmodulesContext {
|
) *SubmodulesContext {
|
||||||
viewModel := NewBasicViewModel(getModel)
|
viewModel := NewBasicViewModel(func() []*models.SubmoduleConfig { return c.Model().Submodules })
|
||||||
|
|
||||||
return &SubmodulesContext{
|
return &SubmodulesContext{
|
||||||
BasicViewModel: viewModel,
|
BasicViewModel: viewModel,
|
||||||
|
@ -16,12 +16,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewTagsContext(
|
func NewTagsContext(
|
||||||
getModel func() []*models.Tag,
|
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
||||||
|
|
||||||
c *types.HelperCommon,
|
c *types.HelperCommon,
|
||||||
) *TagsContext {
|
) *TagsContext {
|
||||||
viewModel := NewBasicViewModel(getModel)
|
viewModel := NewBasicViewModel(func() []*models.Tag { return c.Model().Tags })
|
||||||
|
|
||||||
return &TagsContext{
|
return &TagsContext{
|
||||||
BasicViewModel: viewModel,
|
BasicViewModel: viewModel,
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package context
|
package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
|
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,13 +15,19 @@ type WorkingTreeContext struct {
|
|||||||
|
|
||||||
var _ types.IListContext = (*WorkingTreeContext)(nil)
|
var _ types.IListContext = (*WorkingTreeContext)(nil)
|
||||||
|
|
||||||
func NewWorkingTreeContext(
|
func NewWorkingTreeContext(c *types.HelperCommon) *WorkingTreeContext {
|
||||||
getModel func() []*models.File,
|
viewModel := filetree.NewFileTreeViewModel(
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string,
|
func() []*models.File { return c.Model().Files },
|
||||||
|
c.Log,
|
||||||
|
c.UserConfig.Gui.ShowFileTree,
|
||||||
|
)
|
||||||
|
|
||||||
c *types.HelperCommon,
|
getDisplayStrings := func(startIdx int, length int) [][]string {
|
||||||
) *WorkingTreeContext {
|
lines := presentation.RenderFileTree(viewModel, c.Modes().Diffing.Ref, c.Model().Submodules)
|
||||||
viewModel := filetree.NewFileTreeViewModel(getModel, c.Log, c.UserConfig.Gui.ShowFileTree)
|
return slices.Map(lines, func(line string) []string {
|
||||||
|
return []string{line}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return &WorkingTreeContext{
|
return &WorkingTreeContext{
|
||||||
FileTreeViewModel: viewModel,
|
FileTreeViewModel: viewModel,
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"github.com/jesseduffield/generics/slices"
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
"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/commands/types/enums"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||||
@ -18,21 +17,11 @@ func (gui *Gui) menuListContext() *context.MenuContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) filesListContext() *context.WorkingTreeContext {
|
func (gui *Gui) filesListContext() *context.WorkingTreeContext {
|
||||||
return context.NewWorkingTreeContext(
|
return context.NewWorkingTreeContext(gui.c)
|
||||||
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,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) branchesListContext() *context.BranchesContext {
|
func (gui *Gui) branchesListContext() *context.BranchesContext {
|
||||||
return context.NewBranchesContext(
|
return context.NewBranchesContext(
|
||||||
func() []*models.Branch { return gui.State.Model.Branches },
|
|
||||||
func(startIdx int, length int) [][]string {
|
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)
|
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 {
|
func (gui *Gui) remotesListContext() *context.RemotesContext {
|
||||||
return context.NewRemotesContext(
|
return context.NewRemotesContext(
|
||||||
func() []*models.Remote { return gui.State.Model.Remotes },
|
|
||||||
func(startIdx int, length int) [][]string {
|
func(startIdx int, length int) [][]string {
|
||||||
return presentation.GetRemoteListDisplayStrings(gui.State.Model.Remotes, gui.State.Modes.Diffing.Ref)
|
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 {
|
func (gui *Gui) remoteBranchesListContext() *context.RemoteBranchesContext {
|
||||||
return context.NewRemoteBranchesContext(
|
return context.NewRemoteBranchesContext(
|
||||||
func() []*models.RemoteBranch { return gui.State.Model.RemoteBranches },
|
|
||||||
func(startIdx int, length int) [][]string {
|
func(startIdx int, length int) [][]string {
|
||||||
return presentation.GetRemoteBranchListDisplayStrings(gui.State.Model.RemoteBranches, gui.State.Modes.Diffing.Ref)
|
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 {
|
func (gui *Gui) tagsListContext() *context.TagsContext {
|
||||||
return context.NewTagsContext(
|
return context.NewTagsContext(
|
||||||
func() []*models.Tag { return gui.State.Model.Tags },
|
|
||||||
func(startIdx int, length int) [][]string {
|
func(startIdx int, length int) [][]string {
|
||||||
return presentation.GetTagListDisplayStrings(gui.State.Model.Tags, gui.State.Modes.Diffing.Ref)
|
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 {
|
func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext {
|
||||||
return context.NewLocalCommitsContext(
|
return context.NewLocalCommitsContext(
|
||||||
func() []*models.Commit { return gui.State.Model.Commits },
|
|
||||||
func(startIdx int, length int) [][]string {
|
func(startIdx int, length int) [][]string {
|
||||||
selectedCommitSha := ""
|
selectedCommitSha := ""
|
||||||
if gui.c.CurrentContext().GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
|
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 {
|
func (gui *Gui) subCommitsListContext() *context.SubCommitsContext {
|
||||||
return context.NewSubCommitsContext(
|
return context.NewSubCommitsContext(
|
||||||
func() []*models.Commit { return gui.State.Model.SubCommits },
|
|
||||||
func(startIdx int, length int) [][]string {
|
func(startIdx int, length int) [][]string {
|
||||||
selectedCommitSha := ""
|
selectedCommitSha := ""
|
||||||
if gui.c.CurrentContext().GetKey() == context.SUB_COMMITS_CONTEXT_KEY {
|
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 {
|
func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext {
|
||||||
return context.NewReflogCommitsContext(
|
return context.NewReflogCommitsContext(
|
||||||
func() []*models.Commit { return gui.State.Model.FilteredReflogCommits },
|
|
||||||
func(startIdx int, length int) [][]string {
|
func(startIdx int, length int) [][]string {
|
||||||
return presentation.GetReflogCommitListDisplayStrings(
|
return presentation.GetReflogCommitListDisplayStrings(
|
||||||
gui.State.Model.FilteredReflogCommits,
|
gui.State.Model.FilteredReflogCommits,
|
||||||
@ -183,7 +166,6 @@ func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext {
|
|||||||
|
|
||||||
func (gui *Gui) stashListContext() *context.StashContext {
|
func (gui *Gui) stashListContext() *context.StashContext {
|
||||||
return context.NewStashContext(
|
return context.NewStashContext(
|
||||||
func() []*models.StashEntry { return gui.State.Model.StashEntries },
|
|
||||||
func(startIdx int, length int) [][]string {
|
func(startIdx int, length int) [][]string {
|
||||||
return presentation.GetStashEntryListDisplayStrings(gui.State.Model.StashEntries, gui.State.Modes.Diffing.Ref)
|
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 {
|
func (gui *Gui) commitFilesListContext() *context.CommitFilesContext {
|
||||||
return context.NewCommitFilesContext(
|
return context.NewCommitFilesContext(
|
||||||
func() []*models.CommitFile { return gui.State.Model.CommitFiles },
|
|
||||||
func(startIdx int, length int) [][]string {
|
func(startIdx int, length int) [][]string {
|
||||||
if gui.State.Contexts.CommitFiles.CommitFileTreeViewModel.Len() == 0 {
|
if gui.State.Contexts.CommitFiles.CommitFileTreeViewModel.Len() == 0 {
|
||||||
return [][]string{{style.FgRed.Sprint("(none)")}}
|
return [][]string{{style.FgRed.Sprint("(none)")}}
|
||||||
@ -210,7 +191,6 @@ func (gui *Gui) commitFilesListContext() *context.CommitFilesContext {
|
|||||||
|
|
||||||
func (gui *Gui) submodulesListContext() *context.SubmodulesContext {
|
func (gui *Gui) submodulesListContext() *context.SubmodulesContext {
|
||||||
return context.NewSubmodulesContext(
|
return context.NewSubmodulesContext(
|
||||||
func() []*models.SubmoduleConfig { return gui.State.Model.Submodules },
|
|
||||||
func(startIdx int, length int) [][]string {
|
func(startIdx int, length int) [][]string {
|
||||||
return presentation.GetSubmoduleListDisplayStrings(gui.State.Model.Submodules)
|
return presentation.GetSubmoduleListDisplayStrings(gui.State.Model.Submodules)
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user