summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-03-26 14:44:30 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-26 18:00:46 +1100
commitad7703df65e09d23bb7e709ca9b22251673ac272 (patch)
tree67733bcebb87d6504c1d14368cb67a15acc36ecc /pkg/gui/context
parent13b90ac37f40baa648c25fab6d299ae0fa59118b (diff)
show namesake for child views
Diffstat (limited to 'pkg/gui/context')
-rw-r--r--pkg/gui/context/branches_context.go10
-rw-r--r--pkg/gui/context/commit_files_context.go9
-rw-r--r--pkg/gui/context/context.go19
-rw-r--r--pkg/gui/context/dynamic_title_builder.go23
-rw-r--r--pkg/gui/context/local_commits_context.go10
-rw-r--r--pkg/gui/context/reflog_commits_context.go10
-rw-r--r--pkg/gui/context/remote_branches_context.go17
-rw-r--r--pkg/gui/context/stash_context.go10
-rw-r--r--pkg/gui/context/sub_commits_context.go12
-rw-r--r--pkg/gui/context/tags_context.go10
10 files changed, 108 insertions, 22 deletions
diff --git a/pkg/gui/context/branches_context.go b/pkg/gui/context/branches_context.go
index e5de639d9..302f0c1d9 100644
--- a/pkg/gui/context/branches_context.go
+++ b/pkg/gui/context/branches_context.go
@@ -65,3 +65,13 @@ func (self *BranchesContext) GetSelectedRefName() string {
return item.RefName()
}
+
+func (self *BranchesContext) GetSelectedDescription() string {
+ item := self.GetSelected()
+
+ if item == nil {
+ return ""
+ }
+
+ return item.Description()
+}
diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go
index 5ad7144dc..c95486cbf 100644
--- a/pkg/gui/context/commit_files_context.go
+++ b/pkg/gui/context/commit_files_context.go
@@ -1,18 +1,16 @@
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 {
*filetree.CommitFileTreeViewModel
*ListContextTrait
+ *DynamicTitleBuilder
}
var _ types.IListContext = (*CommitFilesContext)(nil)
@@ -32,6 +30,7 @@ func NewCommitFilesContext(
return &CommitFilesContext{
CommitFileTreeViewModel: viewModel,
+ DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.CommitFilesDynamicTitle),
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(
NewBaseContext(NewBaseContextOpts{
@@ -63,7 +62,3 @@ 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/context.go b/pkg/gui/context/context.go
index add336cfd..fb5a4bd64 100644
--- a/pkg/gui/context/context.go
+++ b/pkg/gui/context/context.go
@@ -152,11 +152,8 @@ func (tree ContextTree) InitialViewTabContextMap() map[string][]TabContext {
Contexts: []types.Context{tree.Branches},
},
{
- Tab: "Remotes",
- Contexts: []types.Context{
- tree.Remotes,
- tree.RemoteBranches,
- },
+ Tab: "Remotes",
+ Contexts: []types.Context{tree.Remotes},
},
{
Tab: "Tags",
@@ -169,10 +166,8 @@ func (tree ContextTree) InitialViewTabContextMap() map[string][]TabContext {
Contexts: []types.Context{tree.LocalCommits},
},
{
- Tab: "Reflog",
- Contexts: []types.Context{
- tree.ReflogCommits,
- },
+ Tab: "Reflog",
+ Contexts: []types.Context{tree.ReflogCommits},
},
},
"files": {
@@ -181,10 +176,8 @@ func (tree ContextTree) InitialViewTabContextMap() map[string][]TabContext {
Contexts: []types.Context{tree.Files},
},
{
- Tab: "Submodules",
- Contexts: []types.Context{
- tree.Submodules,
- },
+ Tab: "Submodules",
+ Contexts: []types.Context{tree.Submodules},
},
},
}
diff --git a/pkg/gui/context/dynamic_title_builder.go b/pkg/gui/context/dynamic_title_builder.go
new file mode 100644
index 000000000..ee4facad2
--- /dev/null
+++ b/pkg/gui/context/dynamic_title_builder.go
@@ -0,0 +1,23 @@
+package context
+
+import "fmt"
+
+type DynamicTitleBuilder struct {
+ formatStr string // e.g. 'remote branches for %s'
+
+ titleRef string // e.g. 'origin'
+}
+
+func NewDynamicTitleBuilder(formatStr string) *DynamicTitleBuilder {
+ return &DynamicTitleBuilder{
+ formatStr: formatStr,
+ }
+}
+
+func (self *DynamicTitleBuilder) SetTitleRef(titleRef string) {
+ self.titleRef = titleRef
+}
+
+func (self *DynamicTitleBuilder) Title() string {
+ return fmt.Sprintf(self.formatStr, self.titleRef)
+}
diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go
index cc7a2a0d2..0d7cc2f54 100644
--- a/pkg/gui/context/local_commits_context.go
+++ b/pkg/gui/context/local_commits_context.go
@@ -93,6 +93,16 @@ func (self *LocalCommitsContext) GetSelectedRefName() string {
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
}
diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go
index a1ad6cfda..0274a921e 100644
--- a/pkg/gui/context/reflog_commits_context.go
+++ b/pkg/gui/context/reflog_commits_context.go
@@ -74,3 +74,13 @@ func (self *ReflogCommitsContext) GetSelectedRefName() string {
func (self *ReflogCommitsContext) GetCommits() []*models.Commit {
return self.getModel()
}
+
+func (self *ReflogCommitsContext) GetSelectedDescription() string {
+ item := self.GetSelected()
+
+ if item == nil {
+ return ""
+ }
+
+ return item.Description()
+}
diff --git a/pkg/gui/context/remote_branches_context.go b/pkg/gui/context/remote_branches_context.go
index 3cdd43a69..52217ef11 100644
--- a/pkg/gui/context/remote_branches_context.go
+++ b/pkg/gui/context/remote_branches_context.go
@@ -9,6 +9,7 @@ import (
type RemoteBranchesContext struct {
*BasicViewModel[*models.RemoteBranch]
*ListContextTrait
+ *DynamicTitleBuilder
}
var _ types.IListContext = (*RemoteBranchesContext)(nil)
@@ -27,14 +28,16 @@ func NewRemoteBranchesContext(
viewModel := NewBasicViewModel(getModel)
return &RemoteBranchesContext{
- BasicViewModel: viewModel,
+ BasicViewModel: viewModel,
+ DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.RemoteBranchesDynamicTitle),
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
- ViewName: "branches",
+ ViewName: "remoteBranches",
WindowName: "branches",
Key: REMOTE_BRANCHES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
Focusable: true,
+ Transient: true,
}), ContextCallbackOpts{
OnFocus: onFocus,
OnFocusLost: onFocusLost,
@@ -65,3 +68,13 @@ func (self *RemoteBranchesContext) GetSelectedRefName() string {
return item.RefName()
}
+
+func (self *RemoteBranchesContext) GetSelectedDescription() string {
+ item := self.GetSelected()
+
+ if item == nil {
+ return ""
+ }
+
+ return item.Description()
+}
diff --git a/pkg/gui/context/stash_context.go b/pkg/gui/context/stash_context.go
index e2af64d10..ef443846f 100644
--- a/pkg/gui/context/stash_context.go
+++ b/pkg/gui/context/stash_context.go
@@ -70,3 +70,13 @@ func (self *StashContext) GetSelectedRefName() string {
return item.RefName()
}
+
+func (self *StashContext) GetSelectedDescription() string {
+ item := self.GetSelected()
+
+ if item == nil {
+ return ""
+ }
+
+ return item.Description()
+}
diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go
index 6c1d5910f..ffc053267 100644
--- a/pkg/gui/context/sub_commits_context.go
+++ b/pkg/gui/context/sub_commits_context.go
@@ -12,6 +12,7 @@ import (
type SubCommitsContext struct {
*SubCommitsViewModel
*ViewportListContextTrait
+ *DynamicTitleBuilder
}
var _ types.IListContext = (*SubCommitsContext)(nil)
@@ -34,6 +35,7 @@ func NewSubCommitsContext(
return &SubCommitsContext{
SubCommitsViewModel: viewModel,
+ DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.SubCommitsDynamicTitle),
ViewportListContextTrait: &ViewportListContextTrait{
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
@@ -99,3 +101,13 @@ func (self *SubCommitsContext) GetCommits() []*models.Commit {
func (self *SubCommitsContext) Title() string {
return fmt.Sprintf(self.c.Tr.SubCommitsDynamicTitle, utils.TruncateWithEllipsis(self.refName, 50))
}
+
+func (self *SubCommitsContext) GetSelectedDescription() string {
+ item := self.GetSelected()
+
+ if item == nil {
+ return ""
+ }
+
+ return item.Description()
+}
diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go
index fd411ec9a..d6f8d78ac 100644
--- a/pkg/gui/context/tags_context.go
+++ b/pkg/gui/context/tags_context.go
@@ -65,3 +65,13 @@ func (self *TagsContext) GetSelectedRefName() string {
return item.RefName()
}
+
+func (self *TagsContext) GetSelectedDescription() string {
+ item := self.GetSelected()
+
+ if item == nil {
+ return ""
+ }
+
+ return item.Description()
+}