diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-24 22:07:30 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-26 18:00:46 +1100 |
commit | 13b90ac37f40baa648c25fab6d299ae0fa59118b (patch) | |
tree | 61dd23273a4b32c3c8d191759cc0ce3ae9d7c08a /pkg/gui/context | |
parent | e039429885996f1335430a856b846d8dc6279325 (diff) |
support viewing commits of reflog entry and show better view title
Diffstat (limited to 'pkg/gui/context')
-rw-r--r-- | pkg/gui/context/base_context.go | 11 | ||||
-rw-r--r-- | pkg/gui/context/commit_files_context.go | 8 | ||||
-rw-r--r-- | pkg/gui/context/sub_commits_context.go | 31 |
3 files changed, 46 insertions, 4 deletions
diff --git a/pkg/gui/context/base_context.go b/pkg/gui/context/base_context.go index 9b006662f..4e73aa0ff 100644 --- a/pkg/gui/context/base_context.go +++ b/pkg/gui/context/base_context.go @@ -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 "" +} diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go index 0576be102..5ad7144dc 100644 --- a/pkg/gui/context/commit_files_context.go +++ b/pkg/gui/context/commit_files_context.go @@ -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)) +} diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index 315093f8f..6c1d5910f 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -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)) +} |