1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-15 01:34:26 +02:00

chore(i18n): move InitialViewTabContextMap to gui package

This commit is contained in:
Ryooooooga
2022-05-18 21:09:48 +09:00
parent 5275161a88
commit bfefef92a6
3 changed files with 42 additions and 43 deletions

View File

@ -4,7 +4,6 @@ import (
"sync" "sync"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/i18n"
) )
const ( const (
@ -144,42 +143,3 @@ type TabContext struct {
Tab string Tab string
Context types.Context Context types.Context
} }
func (tree ContextTree) InitialViewTabContextMap(tr *i18n.TranslationSet) map[string][]TabContext {
return map[string][]TabContext{
"branches": {
{
Tab: tr.LocalBranchesTitle,
Context: tree.Branches,
},
{
Tab: tr.RemotesTitle,
Context: tree.Remotes,
},
{
Tab: tr.TagsTitle,
Context: tree.Tags,
},
},
"commits": {
{
Tab: tr.CommitsTitle,
Context: tree.LocalCommits,
},
{
Tab: tr.ReflogCommitsTitle,
Context: tree.ReflogCommits,
},
},
"files": {
{
Tab: tr.FilesTitle,
Context: tree.Files,
},
{
Tab: tr.SubmodulesTitle,
Context: tree.Submodules,
},
},
}
}

View File

@ -343,7 +343,7 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) {
Diffing: diffing.New(), Diffing: diffing.New(),
}, },
ViewContextMap: viewContextMap, ViewContextMap: viewContextMap,
ViewTabContextMap: contextTree.InitialViewTabContextMap(gui.c.Tr), ViewTabContextMap: gui.initialViewTabContextMap(contextTree),
ScreenMode: screenMode, ScreenMode: screenMode,
// TODO: put contexts in the context manager // TODO: put contexts in the context manager
ContextManager: NewContextManager(initialContext), ContextManager: NewContextManager(initialContext),
@ -466,6 +466,45 @@ func (gui *Gui) initGocui() (*gocui.Gui, error) {
return g, nil return g, nil
} }
func (gui *Gui) initialViewTabContextMap(contextTree *context.ContextTree) map[string][]context.TabContext {
return map[string][]context.TabContext{
"branches": {
{
Tab: gui.c.Tr.LocalBranchesTitle,
Context: contextTree.Branches,
},
{
Tab: gui.c.Tr.RemotesTitle,
Context: contextTree.Remotes,
},
{
Tab: gui.c.Tr.TagsTitle,
Context: contextTree.Tags,
},
},
"commits": {
{
Tab: gui.c.Tr.CommitsTitle,
Context: contextTree.LocalCommits,
},
{
Tab: gui.c.Tr.ReflogCommitsTitle,
Context: contextTree.ReflogCommits,
},
},
"files": {
{
Tab: gui.c.Tr.FilesTitle,
Context: contextTree.Files,
},
{
Tab: gui.c.Tr.SubmodulesTitle,
Context: contextTree.Submodules,
},
},
}
}
// Run: setup the gui with keybindings and start the mainloop // Run: setup the gui with keybindings and start the mainloop
func (gui *Gui) Run(filterPath string) error { func (gui *Gui) Run(filterPath string) error {
g, err := gui.initGocui() g, err := gui.initGocui()

View File

@ -868,7 +868,7 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
} }
} }
for viewName := range self.State.Contexts.InitialViewTabContextMap(self.c.Tr) { for viewName := range self.initialViewTabContextMap(self.State.Contexts) {
bindings = append(bindings, []*types.Binding{ bindings = append(bindings, []*types.Binding{
{ {
ViewName: viewName, ViewName: viewName,
@ -914,7 +914,7 @@ func (gui *Gui) resetKeybindings() error {
} }
} }
for viewName := range gui.State.Contexts.InitialViewTabContextMap(gui.c.Tr) { for viewName := range gui.initialViewTabContextMap(gui.State.Contexts) {
viewName := viewName viewName := viewName
tabClickCallback := func(tabIndex int) error { return gui.onViewTabClick(viewName, tabIndex) } tabClickCallback := func(tabIndex int) error { return gui.onViewTabClick(viewName, tabIndex) }