1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-24 05:36:19 +02:00

move views into contexts

This commit is contained in:
Jesse Duffield 2023-03-21 21:06:39 +11:00
parent e2db6a1732
commit 47b91f1ef5
14 changed files with 12 additions and 49 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -107,7 +107,6 @@ func (gui *Gui) contextTree() *context.ContextTree {
}),
),
MergeConflicts: context.NewMergeConflictsContext(
gui.Views.MergeConflicts,
gui.c,
),
Confirmation: context.NewConfirmationContext(gui.c),

View File

@ -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)
},