From ad7703df65e09d23bb7e709ca9b22251673ac272 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 26 Mar 2022 14:44:30 +1100 Subject: show namesake for child views --- pkg/cheatsheet/generate.go | 41 +++++++------ pkg/cheatsheet/generate_test.go | 70 +++++++++------------ pkg/gui/commit_files_panel.go | 4 +- pkg/gui/context.go | 15 ++--- pkg/gui/context/branches_context.go | 10 +++ pkg/gui/context/commit_files_context.go | 9 +-- pkg/gui/context/context.go | 19 ++---- pkg/gui/context/dynamic_title_builder.go | 23 +++++++ pkg/gui/context/local_commits_context.go | 10 +++ pkg/gui/context/reflog_commits_context.go | 10 +++ pkg/gui/context/remote_branches_context.go | 17 +++++- pkg/gui/context/stash_context.go | 10 +++ pkg/gui/context/sub_commits_context.go | 12 ++++ pkg/gui/context/tags_context.go | 10 +++ pkg/gui/controllers/local_commits_controller.go | 15 +++-- pkg/gui/controllers/remotes_controller.go | 5 ++ .../controllers/switch_to_diff_files_controller.go | 8 ++- .../switch_to_sub_commits_controller.go | 2 + pkg/gui/controllers/types.go | 14 ++++- pkg/gui/gui.go | 71 ++++++++++++---------- pkg/gui/keybindings.go | 2 +- pkg/gui/layout.go | 5 +- pkg/gui/list_context_config.go | 2 +- pkg/gui/refresh.go | 2 + pkg/i18n/chinese.go | 2 +- pkg/i18n/dutch.go | 10 +-- pkg/i18n/english.go | 26 ++++---- 27 files changed, 267 insertions(+), 157 deletions(-) create mode 100644 pkg/gui/context/dynamic_title_builder.go (limited to 'pkg') diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index d20a0c71a..6c641fa1f 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -131,16 +131,19 @@ func getBindingSections(bindings []*types.Binding, tr *i18n.TranslationSet) []*b return getHeaders(binding, tr) }) - bindingGroups := maps.MapToSlice(bindingsByHeader, func(header header, hBindings []*types.Binding) headerWithBindings { - uniqBindings := lo.UniqBy(hBindings, func(binding *types.Binding) string { - return binding.Description + gui.GetKeyDisplay(binding.Key) - }) - - return headerWithBindings{ - header: header, - bindings: uniqBindings, - } - }) + bindingGroups := maps.MapToSlice( + bindingsByHeader, + func(header header, hBindings []*types.Binding) headerWithBindings { + uniqBindings := lo.UniqBy(hBindings, func(binding *types.Binding) string { + return binding.Description + gui.GetKeyDisplay(binding.Key) + }) + + return headerWithBindings{ + header: header, + bindings: uniqBindings, + } + }, + ) slices.SortFunc(bindingGroups, func(a, b headerWithBindings) bool { if a.header.priority != b.header.priority { @@ -169,18 +172,11 @@ func getHeaders(binding *types.Binding, tr *i18n.TranslationSet) []header { } if len(binding.Contexts) == 0 { - translatedView := localisedTitle(tr, binding.ViewName) - title := fmt.Sprintf("%s %s", translatedView, tr.Panel) - - return []header{{priority: 1, title: title}} + return []header{} } return slices.Map(binding.Contexts, func(context string) header { - translatedView := localisedTitle(tr, binding.ViewName) - translatedContextName := localisedTitle(tr, context) - title := fmt.Sprintf("%s %s (%s)", translatedView, tr.Panel, translatedContextName) - - return header{priority: 1, title: title} + return header{priority: 1, title: localisedTitle(tr, context)} }) } @@ -205,7 +201,12 @@ func formatTitle(title string) string { func formatBinding(binding *types.Binding) string { if binding.Alternative != "" { - return fmt.Sprintf(" %s: %s (%s)\n", gui.GetKeyDisplay(binding.Key), binding.Description, binding.Alternative) + return fmt.Sprintf( + " %s: %s (%s)\n", + gui.GetKeyDisplay(binding.Key), + binding.Description, + binding.Alternative, + ) } return fmt.Sprintf(" %s: %s\n", gui.GetKeyDisplay(binding.Key), binding.Description) } diff --git a/pkg/cheatsheet/generate_test.go b/pkg/cheatsheet/generate_test.go index 94b571454..149ed28c7 100644 --- a/pkg/cheatsheet/generate_test.go +++ b/pkg/cheatsheet/generate_test.go @@ -26,38 +26,18 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", }, }, expected: []*bindingSection{ { - title: "Files Panel", - bindings: []*types.Binding{ - { - ViewName: "files", - Description: "stage file", - }, - }, - }, - }, - }, - { - testName: "one binding with context", - bindings: []*types.Binding{ - { - ViewName: "files", - Description: "stage file", - Contexts: []string{"submodules"}, - }, - }, - expected: []*bindingSection{ - { - title: "Files Panel (Submodules)", + title: "Files", bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", - Contexts: []string{"submodules"}, }, }, }, @@ -101,23 +81,10 @@ func TestGetBindingSections(t *testing.T) { Description: "drop submodule", Contexts: []string{"submodules"}, }, - { - ViewName: "commits", - Description: "revert commit", - }, }, expected: []*bindingSection{ { - title: "Commits Panel", - bindings: []*types.Binding{ - { - ViewName: "commits", - Description: "revert commit", - }, - }, - }, - { - title: "Files Panel (Files)", + title: "Files", bindings: []*types.Binding{ { ViewName: "files", @@ -132,7 +99,7 @@ func TestGetBindingSections(t *testing.T) { }, }, { - title: "Files Panel (Submodules)", + title: "Submodules", bindings: []*types.Binding{ { ViewName: "files", @@ -148,19 +115,23 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "unstage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", + Contexts: []string{"commits"}, Description: "revert commit", }, }, @@ -170,29 +141,33 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, }, }, { - title: "Commits Panel", + title: "Commits", bindings: []*types.Binding{ { ViewName: "commits", + Contexts: []string{"commits"}, Description: "revert commit", }, }, }, { - title: "Files Panel", + title: "Files", bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "unstage file", }, }, @@ -204,28 +179,34 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "unstage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", + Contexts: []string{"commits"}, Description: "revert commit", }, { ViewName: "commits", + Contexts: []string{"commits"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", + Contexts: []string{"commits"}, Description: "page up", Tag: "navigation", }, @@ -236,34 +217,39 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", + Contexts: []string{"commits"}, Description: "page up", Tag: "navigation", }, }, }, { - title: "Commits Panel", + title: "Commits", bindings: []*types.Binding{ { ViewName: "commits", + Contexts: []string{"commits"}, Description: "revert commit", }, }, }, { - title: "Files Panel", + title: "Files", bindings: []*types.Binding{ { ViewName: "files", + Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", + Contexts: []string{"files"}, Description: "unstage file", }, }, diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 4f292d3eb..a93486b07 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -41,6 +41,7 @@ func (gui *Gui) commitFilesRenderToMain() error { func (gui *Gui) SwitchToCommitFilesContext(opts controllers.SwitchToCommitFilesContextOpts) error { gui.State.Contexts.CommitFiles.SetSelectedLineIdx(0) gui.State.Contexts.CommitFiles.SetRefName(opts.RefName) + gui.State.Contexts.CommitFiles.SetTitleRef(opts.RefDescription) gui.State.Contexts.CommitFiles.SetCanRebase(opts.CanRebase) gui.State.Contexts.CommitFiles.SetParentContext(opts.Context) gui.State.Contexts.CommitFiles.SetWindowName(opts.Context.GetWindowName()) @@ -54,7 +55,8 @@ func (gui *Gui) SwitchToCommitFilesContext(opts controllers.SwitchToCommitFilesC func (gui *Gui) refreshCommitFilesContext() error { currentSideContext := gui.currentSideContext() - if currentSideContext.GetKey() == context.COMMIT_FILES_CONTEXT_KEY || currentSideContext.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY { + if currentSideContext.GetKey() == context.COMMIT_FILES_CONTEXT_KEY || + currentSideContext.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY { if err := gui.handleRefreshPatchBuildingPanel(-1); err != nil { return err } diff --git a/pkg/gui/context.go b/pkg/gui/context.go index c02411640..c63defba4 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -151,8 +151,7 @@ func (gui *Gui) deactivateContext(c types.Context) error { if view != nil && (c.GetKind() == types.TEMPORARY_POPUP || c.GetKind() == types.PERSISTENT_POPUP || - c.GetKey() == context.COMMIT_FILES_CONTEXT_KEY || - c.GetKey() == context.SUB_COMMITS_CONTEXT_KEY) { + c.IsTransient()) { view.Visible = false } @@ -393,11 +392,7 @@ func (gui *Gui) onViewFocusLost(oldView *gocui.View, newView *gocui.View) error _ = oldView.SetOriginX(0) if !lo.Contains([]*gocui.View{gui.Views.Main, gui.Views.Secondary, gui.Views.Search}, newView) { - transientContexts := slices.Filter(gui.State.Contexts.Flatten(), func(context types.Context) bool { - return context.IsTransient() - }) - - for _, context := range transientContexts { + for _, context := range gui.TransientContexts() { if oldView.Name() == context.GetViewName() { if err := gui.deactivateContext(context); err != nil { return err @@ -409,6 +404,12 @@ func (gui *Gui) onViewFocusLost(oldView *gocui.View, newView *gocui.View) error return nil } +func (gui *Gui) TransientContexts() []types.Context { + return slices.Filter(gui.State.Contexts.Flatten(), func(context types.Context) bool { + return context.IsTransient() + }) +} + // changeContext is a helper function for when we want to change a 'main' context // which currently just means a context that affects both the main and secondary views // other views can have their context changed directly but this function helps 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() +} diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 41433068d..1df223365 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -497,9 +497,7 @@ func (self *LocalCommitsController) createFixupCommit(commit *models.Commit) err func (self *LocalCommitsController) squashAllAboveFixupCommits(commit *models.Commit) error { prompt := utils.ResolvePlaceholderString( self.c.Tr.SureSquashAboveCommits, - map[string]string{ - "commit": commit.Sha, - }, + map[string]string{"commit": commit.Sha}, ) return self.c.Ask(types.AskOpts{ @@ -561,7 +559,9 @@ func (self *LocalCommitsController) handleOpenLogMenu() error { } return self.c.WithWaitingStatus(self.c.Tr.LcLoadingCommits, func() error { - return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.COMMITS}}) + return self.c.Refresh( + types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.COMMITS}}, + ) }) }, }, @@ -602,7 +602,12 @@ func (self *LocalCommitsController) handleOpenLogMenu() error { return func() error { self.c.UserConfig.Git.Log.Order = value return self.c.WithWaitingStatus(self.c.Tr.LcLoadingCommits, func() error { - return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.COMMITS}}) + return self.c.Refresh( + types.RefreshOptions{ + Mode: types.SYNC, + Scope: []types.RefreshableView{types.COMMITS}, + }, + ) }) } } diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go index fd4b34297..208f36af7 100644 --- a/pkg/gui/controllers/remotes_controller.go +++ b/pkg/gui/controllers/remotes_controller.go @@ -73,6 +73,11 @@ func (self *RemotesController) enter(remote *models.Remote) error { newSelectedLine = -1 } self.contexts.RemoteBranches.SetSelectedLineIdx(newSelectedLine) + self.contexts.RemoteBranches.SetTitleRef(remote.Name) + + if err := self.c.PostRefreshUpdate(self.contexts.RemoteBranches); err != nil { + return err + } return self.c.PushContext(self.contexts.RemoteBranches) } diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index 9a3111cae..c41dbdd37 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -12,6 +12,7 @@ type CanSwitchToDiffFiles interface { types.Context CanRebase() bool GetSelectedRefName() string + GetSelectedDescription() string } type SwitchToDiffFilesController struct { @@ -63,9 +64,10 @@ func (self *SwitchToDiffFilesController) checkSelected(callback func(string) err func (self *SwitchToDiffFilesController) enter(refName string) error { return self.viewFiles(SwitchToCommitFilesContextOpts{ - RefName: refName, - CanRebase: self.context.CanRebase(), - Context: self.context, + RefName: refName, + RefDescription: self.context.GetSelectedDescription(), + CanRebase: self.context.CanRebase(), + Context: self.context, }) } diff --git a/pkg/gui/controllers/switch_to_sub_commits_controller.go b/pkg/gui/controllers/switch_to_sub_commits_controller.go index 82b52509b..d59f4fdbf 100644 --- a/pkg/gui/controllers/switch_to_sub_commits_controller.go +++ b/pkg/gui/controllers/switch_to_sub_commits_controller.go @@ -11,6 +11,7 @@ var _ types.IController = &SwitchToSubCommitsController{} type CanSwitchToSubCommits interface { types.Context GetSelectedRefName() string + GetSelectedDescription() string } type SwitchToSubCommitsController struct { @@ -74,6 +75,7 @@ func (self *SwitchToSubCommitsController) viewCommits() error { self.contexts.SubCommits.SetSelectedLineIdx(0) self.contexts.SubCommits.SetParentContext(self.context) self.contexts.SubCommits.SetWindowName(self.context.GetWindowName()) + self.contexts.SubCommits.SetTitleRef(self.context.GetSelectedDescription()) self.contexts.SubCommits.SetRefName(refName) err = self.c.PostRefreshUpdate(self.contexts.SubCommits) diff --git a/pkg/gui/controllers/types.go b/pkg/gui/controllers/types.go index 9783ca3b7..e9af41089 100644 --- a/pkg/gui/controllers/types.go +++ b/pkg/gui/controllers/types.go @@ -6,7 +6,17 @@ import ( // all fields mandatory (except `CanRebase` because it's boolean) type SwitchToCommitFilesContextOpts struct { - RefName string + // this is something like a commit sha or branch name + RefName string + + // this will be displayed in the title of the view so we know whose diff files + // we're viewing + RefDescription string + + // from the local commits view we're allowed to do rebase stuff with any patch + // we generate from the diff files context, but we don't have that same ability + // with say the sub commits context or the reflog context. CanRebase bool - Context types.Context + + Context types.Context } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 334133487..b4e0f8de4 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -240,26 +240,27 @@ type panelStates struct { } type Views struct { - Status *gocui.View - Files *gocui.View - Branches *gocui.View - Commits *gocui.View - Stash *gocui.View - Main *gocui.View - Secondary *gocui.View - Options *gocui.View - Confirmation *gocui.View - Menu *gocui.View - CommitMessage *gocui.View - CommitFiles *gocui.View - SubCommits *gocui.View - Information *gocui.View - AppStatus *gocui.View - Search *gocui.View - SearchPrefix *gocui.View - Limit *gocui.View - Suggestions *gocui.View - Extras *gocui.View + Status *gocui.View + Files *gocui.View + Branches *gocui.View + RemoteBranches *gocui.View + Commits *gocui.View + Stash *gocui.View + Main *gocui.View + Secondary *gocui.View + Options *gocui.View + Confirmation *gocui.View + Menu *gocui.View + CommitMessage *gocui.View + CommitFiles *gocui.View + SubCommits *gocui.View + Information *gocui.View + AppStatus *gocui.View + Search *gocui.View + SearchPrefix *gocui.View + Limit *gocui.View + Suggestions *gocui.View + Extras *gocui.View } type searchingState struct { @@ -406,19 +407,20 @@ func (gui *Gui) syncViewContexts() { func initialViewContextMapping(contextTree *context.ContextTree) map[string]types.Context { return map[string]types.Context{ - "status": contextTree.Status, - "files": contextTree.Files, - "branches": contextTree.Branches, - "commits": contextTree.LocalCommits, - "commitFiles": contextTree.CommitFiles, - "subCommits": contextTree.SubCommits, - "stash": contextTree.Stash, - "menu": contextTree.Menu, - "confirmation": contextTree.Confirmation, - "commitMessage": contextTree.CommitMessage, - "main": contextTree.Normal, - "secondary": contextTree.Normal, - "extras": contextTree.CommandLog, + "status": contextTree.Status, + "files": contextTree.Files, + "branches": contextTree.Branches, + "remoteBranches": contextTree.RemoteBranches, + "commits": contextTree.LocalCommits, + "commitFiles": contextTree.CommitFiles, + "subCommits": contextTree.SubCommits, + "stash": contextTree.Stash, + "menu": contextTree.Menu, + "confirmation": contextTree.Confirmation, + "commitMessage": contextTree.CommitMessage, + "main": contextTree.Normal, + "secondary": contextTree.Normal, + "extras": contextTree.CommandLog, } } @@ -600,6 +602,7 @@ func (gui *Gui) createAllViews() error { {viewPtr: &gui.Views.Status, name: "status"}, {viewPtr: &gui.Views.Files, name: "files"}, {viewPtr: &gui.Views.Branches, name: "branches"}, + {viewPtr: &gui.Views.RemoteBranches, name: "remoteBranches"}, {viewPtr: &gui.Views.Commits, name: "commits"}, {viewPtr: &gui.Views.Stash, name: "stash"}, {viewPtr: &gui.Views.CommitFiles, name: "commitFiles"}, @@ -649,6 +652,8 @@ func (gui *Gui) createAllViews() error { gui.Views.Branches.Title = gui.c.Tr.BranchesTitle gui.Views.Branches.FgColor = theme.GocuiDefaultTextColor + gui.Views.RemoteBranches.FgColor = theme.GocuiDefaultTextColor + gui.Views.Files.Highlight = true gui.Views.Files.Title = gui.c.Tr.FilesTitle gui.Views.Files.FgColor = theme.GocuiDefaultTextColor diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 122fbfd04..e19f42935 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -999,7 +999,7 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi mouseKeybindings = append(mouseKeybindings, c.GetMouseKeybindings(opts)...) } - for _, viewName := range []string{"status", "branches", "files", "commits", "commitFiles", "subCommits", "stash", "menu"} { + for _, viewName := range []string{"status", "branches", "remoteBranches", "files", "commits", "commitFiles", "subCommits", "stash", "menu"} { bindings = append(bindings, []*types.Binding{ {ViewName: viewName, Key: opts.GetKey(opts.Config.Universal.PrevBlock), Modifier: gocui.ModNone, Handler: self.previousSideWindow}, {ViewName: viewName, Key: opts.GetKey(opts.Config.Universal.NextBlock), Modifier: gocui.ModNone, Handler: self.nextSideWindow}, diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index c77c9030d..2fb165ff4 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -2,7 +2,6 @@ package gui import ( "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/theme" ) @@ -96,6 +95,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { {viewName: "status", windowName: "status", frame: true}, {viewName: "files", windowName: "files", frame: true}, {viewName: "branches", windowName: "branches", frame: true}, + {viewName: "remoteBranches", windowName: "branches", frame: true}, {viewName: "commitFiles", windowName: gui.State.Contexts.CommitFiles.GetWindowName(), frame: true}, {viewName: "subCommits", windowName: gui.State.Contexts.SubCommits.GetWindowName(), frame: true}, {viewName: "commits", windowName: "commits", frame: true}, @@ -115,7 +115,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } } - for _, context := range []types.Context{gui.State.Contexts.SubCommits, gui.State.Contexts.CommitFiles} { + for _, context := range gui.TransientContexts() { view, err := gui.g.View(context.GetViewName()) if err != nil && err.Error() != UNKNOWN_VIEW_ERROR_MSG { return err @@ -211,6 +211,7 @@ func (gui *Gui) onInitialViewsCreation() error { gui.Views.Status, gui.Views.Files, gui.Views.Branches, + gui.Views.RemoteBranches, gui.Views.Commits, gui.Views.Stash, gui.Views.SubCommits, diff --git a/pkg/gui/list_context_config.go b/pkg/gui/list_context_config.go index b2f267a6a..e8a65d6da 100644 --- a/pkg/gui/list_context_config.go +++ b/pkg/gui/list_context_config.go @@ -71,7 +71,7 @@ func (gui *Gui) remotesListContext() *context.RemotesContext { func (gui *Gui) remoteBranchesListContext() *context.RemoteBranchesContext { return context.NewRemoteBranchesContext( func() []*models.RemoteBranch { return gui.State.Model.RemoteBranches }, - gui.Views.Branches, + gui.Views.RemoteBranches, func(startIdx int, length int) [][]string { return presentation.GetRemoteBranchListDisplayStrings(gui.State.Model.RemoteBranches, gui.State.Modes.Diffing.Ref) }, diff --git a/pkg/gui/refresh.go b/pkg/gui/refresh.go index f56cb55d7..244c0c050 100644 --- a/pkg/gui/refresh.go +++ b/pkg/gui/refresh.go @@ -187,6 +187,7 @@ func (gui *Gui) refreshCommits() { commit := gui.getSelectedLocalCommit() if commit != nil { gui.State.Contexts.CommitFiles.SetRefName(commit.RefName()) + gui.State.Contexts.CommitFiles.SetTitleRef(commit.RefName()) _ = gui.refreshCommitFilesContext() } } @@ -490,6 +491,7 @@ func (gui *Gui) refreshRemotes() error { for _, remote := range remotes { if remote.Name == prevSelectedRemote.Name { gui.State.Model.RemoteBranches = remote.Branches + break } } } diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index 400a12da6..3b33f3841 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -196,7 +196,7 @@ func chineseTranslationSet() TranslationSet { TagsTitle: "标签页面", MenuTitle: "菜单", RemotesTitle: "远程页面", - RemoteBranchesTitle: "远程分支(在远程页面中)", + RemoteBranchesTitle: "远程分支", PatchBuildingTitle: "构建补丁中", InformationTitle: "信息", SecondaryTitle: "次要", diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index c77321ae2..394b4abc4 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -156,16 +156,16 @@ func dutchTranslationSet() TranslationSet { MergeOptionsTitle: "Merge Opties", RebaseOptionsTitle: "Rebase Opties", CommitMessageTitle: "Commit Bericht", - LocalBranchesTitle: "Branches Tabblad", + LocalBranchesTitle: "Branches", SearchTitle: "Zoek", - TagsTitle: "Tags Tabblad", + TagsTitle: "Tags", MenuTitle: "Menu", - RemotesTitle: "Remotes Tabblad", - RemoteBranchesTitle: "Remote Branches (in Remotes tabblad)", + RemotesTitle: "Remotes", + RemoteBranchesTitle: "Remote Branches", PatchBuildingTitle: "Patch Bouwen", InformationTitle: "Informatie", SecondaryTitle: "Secondary", - ReflogCommitsTitle: "Reflog Tabblad", + ReflogCommitsTitle: "Reflog", GlobalTitle: "Globale Sneltoetsen", ConflictsResolved: "alle merge conflicten zijn opgelost. Wilt je verder gaan?", RebasingTitle: "Rebasen", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index a5cadb47d..678b8cd18 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -232,6 +232,7 @@ type TranslationSet struct { CommitFiles string SubCommitsDynamicTitle string CommitFilesDynamicTitle string + RemoteBranchesDynamicTitle string LcViewItemFiles string CommitFilesTitle string LcCheckoutCommitFile string @@ -611,9 +612,9 @@ func EnglishTranslationSet() TranslationSet { UnstagedChanges: `Unstaged Changes`, StagedChanges: `Staged Changes`, MainTitle: "Main", - StagingTitle: "Staging", - MergingTitle: "Merging", - NormalTitle: "Normal", + StagingTitle: "Main Panel (Staging)", + MergingTitle: "Main Panel (Merging)", + NormalTitle: "Main Panel (Normal)", CommitMessage: "Commit message", CredentialsUsername: "Username", CredentialsPassword: "Password", @@ -762,16 +763,16 @@ func EnglishTranslationSet() TranslationSet { MergeOptionsTitle: "Merge Options", RebaseOptionsTitle: "Rebase Options", CommitMessageTitle: "Commit Message", - LocalBranchesTitle: "Branches Tab", + LocalBranchesTitle: "Branches", SearchTitle: "Search", - TagsTitle: "Tags Tab", + TagsTitle: "Tags", MenuTitle: "Menu", - RemotesTitle: "Remotes Tab", - RemoteBranchesTitle: "Remote Branches (in Remotes tab)", - PatchBuildingTitle: "Patch Building", + RemotesTitle: "Remotes", + RemoteBranchesTitle: "Remote Branches", + PatchBuildingTitle: "Main Panel (Patch Building)", InformationTitle: "Information", SecondaryTitle: "Secondary", - ReflogCommitsTitle: "Reflog Tab", + ReflogCommitsTitle: "Reflog", GlobalTitle: "Global Keybindings", ConflictsResolved: "all merge conflicts resolved. Continue?", RebasingTitle: "Rebasing", @@ -821,8 +822,9 @@ func EnglishTranslationSet() TranslationSet { CheckingOutStatus: "checking out", CommittingStatus: "committing", CommitFiles: "Commit files", - SubCommitsDynamicTitle: "Commits for %s", - CommitFilesDynamicTitle: "Diff files for %s", + SubCommitsDynamicTitle: "Commits (%s)", + CommitFilesDynamicTitle: "Diff files (%s)", + RemoteBranchesDynamicTitle: "Remote branches (%s)", LcViewItemFiles: "view selected item's files", CommitFilesTitle: "Commit Files", LcCheckoutCommitFile: "checkout file", @@ -1010,7 +1012,7 @@ func EnglishTranslationSet() TranslationSet { NavigationTitle: "List Panel Navigation", SuggestionsCheatsheetTitle: "Suggestions", SuggestionsTitle: "Suggestions (press %s to focus)", - ExtrasTitle: "Extras", + ExtrasTitle: "Command Log", PushingTagStatus: "pushing tag", PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard", CommitDiffCopiedToClipboard: "Commit diff copied to clipboard", -- cgit v1.2.3