mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Fix changing language while lazygit is running (#4361)
- **PR Description** When changing the language in the config file while lazygit is running, the panel titles and tab titles weren't properly updated. I noticed this while working on #4359. Probably not an important feature for users, because they are unlikely to change the language all the time; but it's still nice if this isn't broken.
This commit is contained in:
commit
182cefcafc
3 changed files with 50 additions and 65 deletions
|
@ -424,6 +424,15 @@ func (gui *Gui) onUserConfigLoaded() error {
|
|||
userConfig := gui.Config.GetUserConfig()
|
||||
gui.Common.SetUserConfig(userConfig)
|
||||
|
||||
if gui.previousLanguageConfig != userConfig.Gui.Language {
|
||||
tr, err := i18n.NewTranslationSetFromConfig(gui.Log, userConfig.Gui.Language)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gui.c.Tr = tr
|
||||
gui.previousLanguageConfig = userConfig.Gui.Language
|
||||
}
|
||||
|
||||
gui.setColorScheme()
|
||||
gui.configureViewProperties()
|
||||
|
||||
|
@ -435,15 +444,6 @@ func (gui *Gui) onUserConfigLoaded() error {
|
|||
|
||||
gui.g.Mouse = userConfig.Gui.MouseEvents
|
||||
|
||||
if gui.previousLanguageConfig != userConfig.Gui.Language {
|
||||
tr, err := i18n.NewTranslationSetFromConfig(gui.Log, userConfig.Gui.Language)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gui.c.Tr = tr
|
||||
gui.previousLanguageConfig = userConfig.Gui.Language
|
||||
}
|
||||
|
||||
// originally we could only hide the command log permanently via the config
|
||||
// but now we do it via state. So we need to still support the config for the
|
||||
// sake of backwards compatibility. We're making use of short circuiting here
|
||||
|
|
|
@ -2,10 +2,8 @@ package gui
|
|||
|
||||
import (
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
// layout is called for every screen re-render e.g. when the screen is resized
|
||||
|
@ -244,25 +242,6 @@ func (gui *Gui) onRepoViewReset() error {
|
|||
}
|
||||
}
|
||||
|
||||
gui.g.Mutexes.ViewsMutex.Lock()
|
||||
// add tabs to views
|
||||
for _, view := range gui.g.Views() {
|
||||
// if the view is in our mapping, we'll set the tabs and the tab index
|
||||
for _, values := range gui.viewTabMap() {
|
||||
index := slices.IndexFunc(values, func(tabContext context.TabView) bool {
|
||||
return tabContext.ViewName == view.Name()
|
||||
})
|
||||
|
||||
if index != -1 {
|
||||
view.Tabs = lo.Map(values, func(tabContext context.TabView, _ int) string {
|
||||
return tabContext.Tab
|
||||
})
|
||||
view.TabIndex = index
|
||||
}
|
||||
}
|
||||
}
|
||||
gui.g.Mutexes.ViewsMutex.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,10 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||
"github.com/samber/lo"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
type viewNameMapping struct {
|
||||
|
@ -86,7 +88,6 @@ func (gui *Gui) createAllViews() error {
|
|||
gui.Views.SearchPrefix.BgColor = gocui.ColorDefault
|
||||
gui.Views.SearchPrefix.FgColor = gocui.ColorCyan
|
||||
gui.Views.SearchPrefix.Frame = false
|
||||
gui.c.SetViewContent(gui.Views.SearchPrefix, gui.Tr.SearchPrefix)
|
||||
|
||||
gui.Views.StatusSpacer1.Frame = false
|
||||
gui.Views.StatusSpacer2.Frame = false
|
||||
|
@ -97,62 +98,30 @@ func (gui *Gui) createAllViews() error {
|
|||
gui.Views.Search.Frame = false
|
||||
gui.Views.Search.Editor = gocui.EditorFunc(gui.searchEditor)
|
||||
|
||||
gui.Views.Stash.Title = gui.c.Tr.StashTitle
|
||||
|
||||
gui.Views.Commits.Title = gui.c.Tr.CommitsTitle
|
||||
|
||||
gui.Views.CommitFiles.Title = gui.c.Tr.CommitFiles
|
||||
|
||||
gui.Views.Branches.Title = gui.c.Tr.BranchesTitle
|
||||
|
||||
gui.Views.Remotes.Title = gui.c.Tr.RemotesTitle
|
||||
|
||||
gui.Views.Worktrees.Title = gui.c.Tr.WorktreesTitle
|
||||
|
||||
gui.Views.Tags.Title = gui.c.Tr.TagsTitle
|
||||
|
||||
gui.Views.Files.Title = gui.c.Tr.FilesTitle
|
||||
|
||||
for _, view := range []*gocui.View{gui.Views.Main, gui.Views.Secondary, gui.Views.Staging, gui.Views.StagingSecondary, gui.Views.PatchBuilding, gui.Views.PatchBuildingSecondary, gui.Views.MergeConflicts} {
|
||||
view.Title = gui.c.Tr.DiffTitle
|
||||
view.Wrap = true
|
||||
view.IgnoreCarriageReturns = true
|
||||
view.UnderlineHyperLinksOnlyOnHover = true
|
||||
view.AutoRenderHyperLinks = true
|
||||
}
|
||||
|
||||
gui.Views.Staging.Title = gui.c.Tr.UnstagedChanges
|
||||
gui.Views.Staging.Wrap = true
|
||||
|
||||
gui.Views.StagingSecondary.Title = gui.c.Tr.StagedChanges
|
||||
gui.Views.StagingSecondary.Wrap = true
|
||||
|
||||
gui.Views.PatchBuilding.Title = gui.Tr.Patch
|
||||
gui.Views.PatchBuilding.Wrap = true
|
||||
|
||||
gui.Views.PatchBuildingSecondary.Title = gui.Tr.CustomPatch
|
||||
gui.Views.PatchBuildingSecondary.Wrap = true
|
||||
|
||||
gui.Views.MergeConflicts.Title = gui.c.Tr.MergeConflictsTitle
|
||||
gui.Views.MergeConflicts.Wrap = false
|
||||
|
||||
gui.Views.Limit.Title = gui.c.Tr.NotEnoughSpace
|
||||
gui.Views.Limit.Wrap = true
|
||||
|
||||
gui.Views.Status.Title = gui.c.Tr.StatusTitle
|
||||
|
||||
gui.Views.AppStatus.BgColor = gocui.ColorDefault
|
||||
gui.Views.AppStatus.FgColor = gocui.ColorCyan
|
||||
gui.Views.AppStatus.Visible = false
|
||||
gui.Views.AppStatus.Frame = false
|
||||
|
||||
gui.Views.CommitMessage.Visible = false
|
||||
gui.Views.CommitMessage.Title = gui.c.Tr.CommitSummary
|
||||
gui.Views.CommitMessage.Editable = true
|
||||
gui.Views.CommitMessage.Editor = gocui.EditorFunc(gui.commitMessageEditor)
|
||||
|
||||
gui.Views.CommitDescription.Visible = false
|
||||
gui.Views.CommitDescription.Title = gui.c.Tr.CommitDescriptionTitle
|
||||
gui.Views.CommitDescription.Editable = true
|
||||
gui.Views.CommitDescription.Editor = gocui.EditorFunc(gui.commitDescriptionEditor)
|
||||
|
||||
|
@ -170,12 +139,10 @@ func (gui *Gui) createAllViews() error {
|
|||
gui.Views.Information.FgColor = gocui.ColorGreen
|
||||
gui.Views.Information.Frame = false
|
||||
|
||||
gui.Views.Extras.Title = gui.c.Tr.CommandLog
|
||||
gui.Views.Extras.Autoscroll = true
|
||||
gui.Views.Extras.Wrap = true
|
||||
gui.Views.Extras.AutoRenderHyperLinks = true
|
||||
|
||||
gui.Views.Snake.Title = gui.c.Tr.SnakeTitle
|
||||
gui.Views.Snake.FgColor = gocui.ColorGreen
|
||||
|
||||
return nil
|
||||
|
@ -201,7 +168,30 @@ func (gui *Gui) configureViewProperties() {
|
|||
(*mapping.viewPtr).InactiveViewSelBgColor = theme.GocuiInactiveViewSelectedLineBgColor
|
||||
}
|
||||
|
||||
gui.c.SetViewContent(gui.Views.SearchPrefix, gui.c.Tr.SearchPrefix)
|
||||
|
||||
gui.Views.Stash.Title = gui.c.Tr.StashTitle
|
||||
gui.Views.Commits.Title = gui.c.Tr.CommitsTitle
|
||||
gui.Views.CommitFiles.Title = gui.c.Tr.CommitFiles
|
||||
gui.Views.Branches.Title = gui.c.Tr.BranchesTitle
|
||||
gui.Views.Remotes.Title = gui.c.Tr.RemotesTitle
|
||||
gui.Views.Worktrees.Title = gui.c.Tr.WorktreesTitle
|
||||
gui.Views.Tags.Title = gui.c.Tr.TagsTitle
|
||||
gui.Views.Files.Title = gui.c.Tr.FilesTitle
|
||||
gui.Views.PatchBuilding.Title = gui.c.Tr.Patch
|
||||
gui.Views.PatchBuildingSecondary.Title = gui.c.Tr.CustomPatch
|
||||
gui.Views.MergeConflicts.Title = gui.c.Tr.MergeConflictsTitle
|
||||
gui.Views.Limit.Title = gui.c.Tr.NotEnoughSpace
|
||||
gui.Views.Status.Title = gui.c.Tr.StatusTitle
|
||||
gui.Views.Staging.Title = gui.c.Tr.UnstagedChanges
|
||||
gui.Views.StagingSecondary.Title = gui.c.Tr.StagedChanges
|
||||
gui.Views.CommitMessage.Title = gui.c.Tr.CommitSummary
|
||||
gui.Views.CommitDescription.Title = gui.c.Tr.CommitDescriptionTitle
|
||||
gui.Views.Extras.Title = gui.c.Tr.CommandLog
|
||||
gui.Views.Snake.Title = gui.c.Tr.SnakeTitle
|
||||
|
||||
for _, view := range []*gocui.View{gui.Views.Main, gui.Views.Secondary, gui.Views.Staging, gui.Views.StagingSecondary, gui.Views.PatchBuilding, gui.Views.PatchBuildingSecondary, gui.Views.MergeConflicts} {
|
||||
view.Title = gui.c.Tr.DiffTitle
|
||||
view.CanScrollPastBottom = gui.c.UserConfig().Gui.ScrollPastBottom
|
||||
view.TabWidth = gui.c.UserConfig().Gui.TabWidth
|
||||
}
|
||||
|
@ -246,4 +236,20 @@ func (gui *Gui) configureViewProperties() {
|
|||
|
||||
gui.Views.Stash.TitlePrefix = ""
|
||||
}
|
||||
|
||||
for _, view := range gui.g.Views() {
|
||||
// if the view is in our mapping, we'll set the tabs and the tab index
|
||||
for _, values := range gui.viewTabMap() {
|
||||
index := slices.IndexFunc(values, func(tabContext context.TabView) bool {
|
||||
return tabContext.ViewName == view.Name()
|
||||
})
|
||||
|
||||
if index != -1 {
|
||||
view.Tabs = lo.Map(values, func(tabContext context.TabView, _ int) string {
|
||||
return tabContext.Tab
|
||||
})
|
||||
view.TabIndex = index
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue