1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/context/local_commits_context.go

114 lines
2.7 KiB
Go
Raw Normal View History

2022-02-05 08:04:10 +02:00
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)
_ types.DiffableContext = (*LocalCommitsContext)(nil)
)
2022-02-05 08:04:10 +02:00
func NewLocalCommitsContext(
getModel func() []*models.Commit,
view *gocui.View,
getDisplayStrings func(startIdx int, length int) [][]string,
2022-02-06 06:54:26 +02:00
c *types.HelperCommon,
2022-02-05 08:04:10 +02:00
) *LocalCommitsContext {
viewModel := NewLocalCommitsViewModel(getModel, c)
2022-02-05 08:04:10 +02:00
return &LocalCommitsContext{
LocalCommitsViewModel: viewModel,
ViewportListContextTrait: &ViewportListContextTrait{
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
View: view,
2022-02-05 08:04:10 +02:00
WindowName: "commits",
2022-02-13 08:01:53 +02:00
Key: LOCAL_COMMITS_CONTEXT_KEY,
2022-02-05 08:04:10 +02:00
Kind: types.SIDE_CONTEXT,
Focusable: true,
2023-03-21 12:01:58 +02:00
})),
2022-02-05 08:04:10 +02:00
list: viewModel,
getDisplayStrings: getDisplayStrings,
c: c,
2022-03-19 00:38:49 +02:00
},
},
2022-02-05 08:04:10 +02:00
}
}
func (self *LocalCommitsContext) GetSelectedItemId() string {
item := self.GetSelected()
if item == nil {
return ""
}
return item.ID()
}
type LocalCommitsViewModel struct {
2022-03-19 00:31:52 +02:00
*BasicViewModel[*models.Commit]
2022-02-06 06:54:26 +02:00
// 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.
2022-02-06 05:37:16 +02:00
limitCommits bool
2022-02-06 06:54:26 +02:00
// If this is true we'll use git log --all when fetching the commits.
showWholeGitGraph bool
2022-02-05 08:04:10 +02:00
}
func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *types.HelperCommon) *LocalCommitsViewModel {
2022-02-05 08:04:10 +02:00
self := &LocalCommitsViewModel{
2022-05-30 17:19:48 +02:00
BasicViewModel: NewBasicViewModel(getModel),
limitCommits: true,
showWholeGitGraph: c.UserConfig.Git.Log.ShowWholeGraph,
2022-02-05 08:04:10 +02:00
}
return self
}
2022-02-13 08:54:36 +02:00
func (self *LocalCommitsContext) CanRebase() bool {
return true
}
2022-03-26 15:18:08 +02:00
func (self *LocalCommitsContext) GetSelectedRef() types.Ref {
commit := self.GetSelected()
if commit == nil {
return nil
}
return commit
2022-03-26 05:44:30 +02:00
}
func (self *LocalCommitsContext) GetDiffTerminals() []string {
itemId := self.GetSelectedItemId()
return []string{itemId}
}
2022-02-06 05:37:16 +02:00
func (self *LocalCommitsViewModel) SetLimitCommits(value bool) {
self.limitCommits = value
}
func (self *LocalCommitsViewModel) GetLimitCommits() bool {
return self.limitCommits
}
2022-02-06 06:54:26 +02:00
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()
}