1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-06 03:53:59 +02:00
lazygit/pkg/gui/context/reflog_commits_context.go

95 lines
2.2 KiB
Go
Raw Normal View History

2022-02-05 08:04:10 +02:00
package context
import (
"time"
2022-02-05 08:04:10 +02:00
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
2022-02-05 08:04:10 +02:00
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
type ReflogCommitsContext struct {
*FilteredListViewModel[*models.Commit]
2022-02-05 08:04:10 +02:00
*ListContextTrait
}
var (
_ types.IListContext = (*ReflogCommitsContext)(nil)
_ types.DiffableContext = (*ReflogCommitsContext)(nil)
)
2022-02-05 08:04:10 +02:00
func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext {
viewModel := NewFilteredListViewModel(
func() []*models.Commit { return c.Model().FilteredReflogCommits },
func(commit *models.Commit) []string {
return []string{commit.ShortSha(), commit.Name}
},
)
2022-02-05 08:04:10 +02:00
getDisplayStrings := func(_ int, _ int) [][]string {
return presentation.GetReflogCommitListDisplayStrings(
viewModel.GetItems(),
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
c.Modes().CherryPicking.SelectedShaSet(),
c.Modes().Diffing.Ref,
time.Now(),
c.UserConfig.Gui.TimeFormat,
c.UserConfig.Gui.ShortTimeFormat,
c.UserConfig.Git.ParseEmoji,
)
}
2022-02-05 08:04:10 +02:00
return &ReflogCommitsContext{
FilteredListViewModel: viewModel,
2022-02-05 08:04:10 +02:00
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
2023-03-21 12:06:39 +02:00
View: c.Views().ReflogCommits,
2022-02-05 08:04:10 +02:00
WindowName: "commits",
Key: REFLOG_COMMITS_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
Focusable: true,
2023-03-21 12:01:58 +02:00
})),
ListRenderer: ListRenderer{
list: viewModel,
getDisplayStrings: getDisplayStrings,
},
c: c,
2022-02-05 08:04:10 +02:00
},
}
}
func (self *ReflogCommitsContext) GetSelectedItemId() string {
item := self.GetSelected()
if item == nil {
return ""
}
return item.ID()
}
2022-02-13 08:54:36 +02:00
func (self *ReflogCommitsContext) CanRebase() bool {
return false
}
2022-03-26 15:18:08 +02:00
func (self *ReflogCommitsContext) GetSelectedRef() types.Ref {
commit := self.GetSelected()
if commit == nil {
return nil
}
return commit
2022-02-13 09:26:44 +02:00
}
func (self *ReflogCommitsContext) GetCommits() []*models.Commit {
return self.getModel()
}
func (self *ReflogCommitsContext) GetDiffTerminals() []string {
itemId := self.GetSelectedItemId()
return []string{itemId}
}
func (self *ReflogCommitsContext) ShowBranchHeadsInSubCommits() bool {
return false
}