support viewing commits of reflog entry and show better view title

This commit is contained in:
Jesse Duffield
2022-03-24 22:07:30 +11:00
parent e039429885
commit 13b90ac37f
21 changed files with 177 additions and 54 deletions

View File

@@ -17,6 +17,7 @@ type BaseContext struct {
onClickFn func() error
focusable bool
transient bool
*ParentContextMgr
}
@@ -29,6 +30,7 @@ type NewBaseContextOpts struct {
ViewName string
WindowName string
Focusable bool
Transient bool
OnGetOptionsMap func() map[string]string
}
@@ -41,6 +43,7 @@ func NewBaseContext(opts NewBaseContextOpts) *BaseContext {
windowName: opts.WindowName,
onGetOptionsMap: opts.OnGetOptionsMap,
focusable: opts.Focusable,
transient: opts.Transient,
ParentContextMgr: &ParentContextMgr{},
}
}
@@ -115,3 +118,11 @@ func (self *BaseContext) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocu
func (self *BaseContext) IsFocusable() bool {
return self.focusable
}
func (self *BaseContext) IsTransient() bool {
return self.transient
}
func (self *BaseContext) Title() string {
return ""
}

View File

@@ -1,10 +1,13 @@
package context
import (
"fmt"
"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"
"github.com/jesseduffield/lazygit/pkg/utils"
)
type CommitFilesContext struct {
@@ -37,6 +40,7 @@ func NewCommitFilesContext(
Key: COMMIT_FILES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
Focusable: true,
Transient: true,
}),
ContextCallbackOpts{
OnFocus: onFocus,
@@ -59,3 +63,7 @@ func (self *CommitFilesContext) GetSelectedItemId() string {
return item.ID()
}
func (self *CommitFilesContext) Title() string {
return fmt.Sprintf(self.c.Tr.CommitFilesDynamicTitle, utils.TruncateWithEllipsis(self.GetRefName(), 50))
}

View File

@@ -1,13 +1,16 @@
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"
)
type SubCommitsContext struct {
*BasicViewModel[*models.Commit]
*SubCommitsViewModel
*ViewportListContextTrait
}
@@ -24,18 +27,22 @@ func NewSubCommitsContext(
c *types.HelperCommon,
) *SubCommitsContext {
viewModel := NewBasicViewModel(getModel)
viewModel := &SubCommitsViewModel{
BasicViewModel: NewBasicViewModel(getModel),
refName: "",
}
return &SubCommitsContext{
BasicViewModel: viewModel,
SubCommitsViewModel: viewModel,
ViewportListContextTrait: &ViewportListContextTrait{
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
ViewName: "branches",
ViewName: "subCommits",
WindowName: "branches",
Key: SUB_COMMITS_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
Focusable: true,
Transient: true,
}), ContextCallbackOpts{
OnFocus: onFocus,
OnFocusLost: onFocusLost,
@@ -50,6 +57,16 @@ func NewSubCommitsContext(
}
}
type SubCommitsViewModel struct {
// name of the ref that the sub-commits are shown for
refName string
*BasicViewModel[*models.Commit]
}
func (self *SubCommitsViewModel) SetRefName(refName string) {
self.refName = refName
}
func (self *SubCommitsContext) GetSelectedItemId() string {
item := self.GetSelected()
if item == nil {
@@ -63,6 +80,8 @@ func (self *SubCommitsContext) CanRebase() bool {
return false
}
// not to be confused with the refName in the view model. This is the ref name of
// the selected commit
func (self *SubCommitsContext) GetSelectedRefName() string {
item := self.GetSelected()
@@ -76,3 +95,7 @@ func (self *SubCommitsContext) GetSelectedRefName() string {
func (self *SubCommitsContext) GetCommits() []*models.Commit {
return self.getModel()
}
func (self *SubCommitsContext) Title() string {
return fmt.Sprintf(self.c.Tr.SubCommitsDynamicTitle, utils.TruncateWithEllipsis(self.refName, 50))
}