Skip to content

Commit 8e00bbd

Browse files
authored
Show "Log (x of y)" in the title bar when there is more than one branch log command (#4943)
Addresses #4939.
2 parents 47ca082 + 5d02cba commit 8e00bbd

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

pkg/commands/git_commands/branch.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
type BranchCommands struct {
1515
*GitCommon
16-
allBranchesLogCmdIndex uint8 // keeps track of current all branches log command
16+
allBranchesLogCmdIndex int // keeps track of current all branches log command
1717
}
1818

1919
func NewBranchCommands(gitCommon *GitCommon) *BranchCommands {
@@ -278,14 +278,24 @@ func (self *BranchCommands) allBranchesLogCandidates() []string {
278278
func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj {
279279
candidates := self.allBranchesLogCandidates()
280280

281+
if self.allBranchesLogCmdIndex >= len(candidates) {
282+
self.allBranchesLogCmdIndex = 0
283+
}
284+
281285
i := self.allBranchesLogCmdIndex
282286
return self.cmd.New(str.ToArgv(candidates[i])).DontLog()
283287
}
284288

285289
func (self *BranchCommands) RotateAllBranchesLogIdx() {
286290
n := len(self.allBranchesLogCandidates())
287291
i := self.allBranchesLogCmdIndex
288-
self.allBranchesLogCmdIndex = uint8((int(i) + 1) % n)
292+
self.allBranchesLogCmdIndex = (i + 1) % n
293+
}
294+
295+
func (self *BranchCommands) GetAllBranchesLogIdxAndCount() (int, int) {
296+
n := len(self.allBranchesLogCandidates())
297+
i := self.allBranchesLogCmdIndex
298+
return i, n
289299
}
290300

291301
func (self *BranchCommands) IsBranchMerged(branch *models.Branch, mainBranches *MainBranches) (bool, error) {

pkg/gui/controllers/status_controller.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,14 @@ func (self *StatusController) showAllBranchLogs() {
181181
cmdObj := self.c.Git().Branch.AllBranchesLogCmdObj()
182182
task := types.NewRunPtyTask(cmdObj.GetCmd())
183183

184+
title := self.c.Tr.LogTitle
185+
if i, n := self.c.Git().Branch.GetAllBranchesLogIdxAndCount(); n > 1 {
186+
title = fmt.Sprintf(self.c.Tr.LogXOfYTitle, i+1, n)
187+
}
184188
self.c.RenderToMainViews(types.RefreshMainOpts{
185189
Pair: self.c.MainViewPairs().Normal,
186190
Main: &types.ViewUpdateOpts{
187-
Title: self.c.Tr.LogTitle,
191+
Title: title,
188192
Task: task,
189193
},
190194
})
@@ -196,7 +200,7 @@ func (self *StatusController) switchToOrRotateAllBranchesLogs() {
196200
// A bit of a hack to ensure we only rotate to the next branch log command
197201
// if we currently are looking at a branch log. Otherwise, we should just show
198202
// the current index (if we are coming from the dashboard).
199-
if self.c.Views().Main.Title == self.c.Tr.LogTitle {
203+
if self.c.Views().Main.Title != self.c.Tr.StatusTitle {
200204
self.c.Git().Branch.RotateAllBranchesLogIdx()
201205
}
202206
self.showAllBranchLogs()

pkg/i18n/english.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type TranslationSet struct {
3030
RegularMergeTooltip string
3131
NormalTitle string
3232
LogTitle string
33+
LogXOfYTitle string
3334
CommitSummary string
3435
CredentialsUsername string
3536
CredentialsPassword string
@@ -1110,6 +1111,7 @@ func EnglishTranslationSet() *TranslationSet {
11101111
MergingTitle: "Main panel (merging)",
11111112
NormalTitle: "Main panel (normal)",
11121113
LogTitle: "Log",
1114+
LogXOfYTitle: "Log (%d of %d)",
11131115
CommitSummary: "Commit summary",
11141116
CredentialsUsername: "Username",
11151117
CredentialsPassword: "Password",

0 commit comments

Comments
 (0)