split context common from helper common

This commit is contained in:
Jesse Duffield
2023-03-23 12:35:07 +11:00
parent f081358943
commit 43251e7275
55 changed files with 156 additions and 133 deletions

View File

@@ -16,7 +16,7 @@ var (
_ types.DiffableContext = (*BranchesContext)(nil)
)
func NewBranchesContext(c *types.HelperCommon) *BranchesContext {
func NewBranchesContext(c *ContextCommon) *BranchesContext {
viewModel := NewBasicViewModel(func() []*models.Branch { return c.Model().Branches })
getDisplayStrings := func(startIdx int, length int) [][]string {

View File

@@ -20,7 +20,7 @@ var (
_ types.DiffableContext = (*CommitFilesContext)(nil)
)
func NewCommitFilesContext(c *types.HelperCommon) *CommitFilesContext {
func NewCommitFilesContext(c *ContextCommon) *CommitFilesContext {
viewModel := filetree.NewCommitFileTreeViewModel(
func() []*models.CommitFile { return c.Model().CommitFiles },
c.Log,
@@ -102,7 +102,7 @@ func (self *CommitFilesContext) renderToMain() error {
})
}
func secondaryPatchPanelUpdateOpts(c *types.HelperCommon) *types.ViewUpdateOpts {
func secondaryPatchPanelUpdateOpts(c *ContextCommon) *types.ViewUpdateOpts {
if c.Git().Patch.PatchBuilder.Active() {
patch := c.Git().Patch.PatchBuilder.RenderAggregatedPatch(false)

View File

@@ -10,13 +10,13 @@ import (
type CommitMessageContext struct {
*SimpleContext
c *types.HelperCommon
c *ContextCommon
}
var _ types.Context = (*CommitMessageContext)(nil)
func NewCommitMessageContext(
c *types.HelperCommon,
c *ContextCommon,
) *CommitMessageContext {
return &CommitMessageContext{
c: c,

View File

@@ -6,7 +6,7 @@ import (
type ConfirmationContext struct {
*SimpleContext
c *types.HelperCommon
c *ContextCommon
State ConfirmationContextState
}
@@ -19,7 +19,7 @@ type ConfirmationContextState struct {
var _ types.Context = (*ConfirmationContext)(nil)
func NewConfirmationContext(
c *types.HelperCommon,
c *ContextCommon,
) *ConfirmationContext {
return &ConfirmationContext{
c: c,

View File

@@ -0,0 +1,11 @@
package context
import (
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
type ContextCommon struct {
*common.Common
types.IGuiCommon
}

View File

@@ -10,7 +10,7 @@ import (
type ListContextTrait struct {
types.Context
c *types.HelperCommon
c *ContextCommon
list types.IList
getDisplayStrings func(startIdx int, length int) [][]string
}

View File

@@ -19,7 +19,7 @@ var (
_ types.DiffableContext = (*LocalCommitsContext)(nil)
)
func NewLocalCommitsContext(c *types.HelperCommon) *LocalCommitsContext {
func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
viewModel := NewLocalCommitsViewModel(
func() []*models.Commit { return c.Model().Commits },
c,
@@ -93,7 +93,7 @@ type LocalCommitsViewModel struct {
showWholeGitGraph bool
}
func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *types.HelperCommon) *LocalCommitsViewModel {
func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *ContextCommon) *LocalCommitsViewModel {
self := &LocalCommitsViewModel{
BasicViewModel: NewBasicViewModel(getModel),
limitCommits: true,
@@ -141,7 +141,7 @@ func (self *LocalCommitsViewModel) GetCommits() []*models.Commit {
return self.getModel()
}
func shouldShowGraph(c *types.HelperCommon) bool {
func shouldShowGraph(c *ContextCommon) bool {
if c.Modes().Filtering.Active() {
return false
}

View File

@@ -15,7 +15,7 @@ type MenuContext struct {
var _ types.IListContext = (*MenuContext)(nil)
func NewMenuContext(
c *types.HelperCommon,
c *ContextCommon,
) *MenuContext {
viewModel := NewMenuViewModel()

View File

@@ -11,7 +11,7 @@ import (
type MergeConflictsContext struct {
types.Context
viewModel *ConflictsViewModel
c *types.HelperCommon
c *ContextCommon
mutex *deadlock.Mutex
}
@@ -24,7 +24,7 @@ type ConflictsViewModel struct {
}
func NewMergeConflictsContext(
c *types.HelperCommon,
c *ContextCommon,
) *MergeConflictsContext {
viewModel := &ConflictsViewModel{
state: mergeconflicts.NewState(),

View File

@@ -13,7 +13,7 @@ type PatchExplorerContext struct {
state *patch_exploring.State
viewTrait *ViewTrait
getIncludedLineIndices func() []int
c *types.HelperCommon
c *ContextCommon
mutex *deadlock.Mutex
}
@@ -26,7 +26,7 @@ func NewPatchExplorerContext(
getIncludedLineIndices func() []int,
c *types.HelperCommon,
c *ContextCommon,
) *PatchExplorerContext {
return &PatchExplorerContext{
state: nil,

View File

@@ -16,7 +16,7 @@ var (
_ types.DiffableContext = (*ReflogCommitsContext)(nil)
)
func NewReflogCommitsContext(c *types.HelperCommon) *ReflogCommitsContext {
func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext {
viewModel := NewBasicViewModel(func() []*models.Commit { return c.Model().FilteredReflogCommits })
getDisplayStrings := func(startIdx int, length int) [][]string {

View File

@@ -18,7 +18,7 @@ var (
)
func NewRemoteBranchesContext(
c *types.HelperCommon,
c *ContextCommon,
) *RemoteBranchesContext {
viewModel := NewBasicViewModel(func() []*models.RemoteBranch { return c.Model().RemoteBranches })

View File

@@ -16,7 +16,7 @@ var (
_ types.DiffableContext = (*RemotesContext)(nil)
)
func NewRemotesContext(c *types.HelperCommon) *RemotesContext {
func NewRemotesContext(c *ContextCommon) *RemotesContext {
viewModel := NewBasicViewModel(func() []*models.Remote { return c.Model().Remotes })
getDisplayStrings := func(startIdx int, length int) [][]string {

View File

@@ -17,7 +17,7 @@ var (
)
func NewStashContext(
c *types.HelperCommon,
c *ContextCommon,
) *StashContext {
viewModel := NewBasicViewModel(func() []*models.StashEntry { return c.Model().StashEntries })

View File

@@ -22,7 +22,7 @@ var (
)
func NewSubCommitsContext(
c *types.HelperCommon,
c *ContextCommon,
) *SubCommitsContext {
viewModel := &SubCommitsViewModel{
BasicViewModel: NewBasicViewModel(

View File

@@ -13,7 +13,7 @@ type SubmodulesContext struct {
var _ types.IListContext = (*SubmodulesContext)(nil)
func NewSubmodulesContext(c *types.HelperCommon) *SubmodulesContext {
func NewSubmodulesContext(c *ContextCommon) *SubmodulesContext {
viewModel := NewBasicViewModel(func() []*models.SubmoduleConfig { return c.Model().Submodules })
getDisplayStrings := func(startIdx int, length int) [][]string {

View File

@@ -27,7 +27,7 @@ type SuggestionsContextState struct {
var _ types.IListContext = (*SuggestionsContext)(nil)
func NewSuggestionsContext(
c *types.HelperCommon,
c *ContextCommon,
) *SuggestionsContext {
state := &SuggestionsContextState{
AsyncHandler: tasks.NewAsyncHandler(),

View File

@@ -17,7 +17,7 @@ var (
)
func NewTagsContext(
c *types.HelperCommon,
c *ContextCommon,
) *TagsContext {
viewModel := NewBasicViewModel(func() []*models.Tag { return c.Model().Tags })

View File

@@ -15,7 +15,7 @@ type WorkingTreeContext struct {
var _ types.IListContext = (*WorkingTreeContext)(nil)
func NewWorkingTreeContext(c *types.HelperCommon) *WorkingTreeContext {
func NewWorkingTreeContext(c *ContextCommon) *WorkingTreeContext {
viewModel := filetree.NewFileTreeViewModel(
func() []*models.File { return c.Model().Files },
c.Log,