mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
125 lines
2.9 KiB
Go
125 lines
2.9 KiB
Go
package context
|
|
|
|
import (
|
|
"github.com/jesseduffield/gocui"
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
type LocalCommitsContext struct {
|
|
*LocalCommitsViewModel
|
|
*ViewportListContextTrait
|
|
}
|
|
|
|
var _ types.IListContext = (*LocalCommitsContext)(nil)
|
|
|
|
func NewLocalCommitsContext(
|
|
getModel func() []*models.Commit,
|
|
view *gocui.View,
|
|
getDisplayStrings func(startIdx int, length int) [][]string,
|
|
|
|
onFocus func(...types.OnFocusOpts) error,
|
|
onRenderToMain func(...types.OnFocusOpts) error,
|
|
onFocusLost func() error,
|
|
|
|
c *types.HelperCommon,
|
|
) *LocalCommitsContext {
|
|
viewModel := NewLocalCommitsViewModel(getModel)
|
|
|
|
return &LocalCommitsContext{
|
|
LocalCommitsViewModel: viewModel,
|
|
ViewportListContextTrait: &ViewportListContextTrait{
|
|
ListContextTrait: &ListContextTrait{
|
|
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
|
|
ViewName: "commits",
|
|
WindowName: "commits",
|
|
Key: LOCAL_COMMITS_CONTEXT_KEY,
|
|
Kind: types.SIDE_CONTEXT,
|
|
Focusable: true,
|
|
}), ContextCallbackOpts{
|
|
OnFocus: onFocus,
|
|
OnFocusLost: onFocusLost,
|
|
OnRenderToMain: onRenderToMain,
|
|
}),
|
|
list: viewModel,
|
|
viewTrait: NewViewTrait(view),
|
|
getDisplayStrings: getDisplayStrings,
|
|
c: c,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (self *LocalCommitsContext) GetSelectedItemId() string {
|
|
item := self.GetSelected()
|
|
if item == nil {
|
|
return ""
|
|
}
|
|
|
|
return item.ID()
|
|
}
|
|
|
|
type LocalCommitsViewModel struct {
|
|
*BasicViewModel[*models.Commit]
|
|
|
|
// If this is true we limit the amount of commits we load, for the sake of keeping things fast.
|
|
// If the user attempts to scroll past the end of the list, we will load more commits.
|
|
limitCommits bool
|
|
|
|
// If this is true we'll use git log --all when fetching the commits.
|
|
showWholeGitGraph bool
|
|
}
|
|
|
|
func NewLocalCommitsViewModel(getModel func() []*models.Commit) *LocalCommitsViewModel {
|
|
self := &LocalCommitsViewModel{
|
|
BasicViewModel: NewBasicViewModel(getModel),
|
|
limitCommits: true,
|
|
}
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *LocalCommitsContext) CanRebase() bool {
|
|
return true
|
|
}
|
|
|
|
func (self *LocalCommitsContext) GetSelectedRefName() string {
|
|
item := self.GetSelected()
|
|
|
|
if item == nil {
|
|
return ""
|
|
}
|
|
|
|
return item.RefName()
|
|
}
|
|
|
|
func (self *LocalCommitsViewModel) GetSelectedDescription() string {
|
|
item := self.GetSelected()
|
|
|
|
if item == nil {
|
|
return ""
|
|
}
|
|
|
|
return item.Description()
|
|
}
|
|
|
|
func (self *LocalCommitsViewModel) SetLimitCommits(value bool) {
|
|
self.limitCommits = value
|
|
}
|
|
|
|
func (self *LocalCommitsViewModel) GetLimitCommits() bool {
|
|
return self.limitCommits
|
|
}
|
|
|
|
func (self *LocalCommitsViewModel) SetShowWholeGitGraph(value bool) {
|
|
self.showWholeGitGraph = value
|
|
}
|
|
|
|
func (self *LocalCommitsViewModel) GetShowWholeGitGraph() bool {
|
|
return self.showWholeGitGraph
|
|
}
|
|
|
|
func (self *LocalCommitsViewModel) GetCommits() []*models.Commit {
|
|
return self.getModel()
|
|
}
|