mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-24 05:36:19 +02:00
prepare for OnRender prop
This commit is contained in:
parent
2fdadd383a
commit
a32947e7a7
@ -454,18 +454,6 @@ func (gui *Gui) onBranchesTabClick(tabIndex int) error {
|
||||
return gui.switchContext(context)
|
||||
}
|
||||
|
||||
func (gui *Gui) tabIndexForContext(c Context, tabContexts tabContexts) int {
|
||||
for i, tabContext := range tabContexts {
|
||||
for _, context := range tabContext.contexts {
|
||||
if context.GetKey() == c.GetKey() {
|
||||
return i
|
||||
}
|
||||
}
|
||||
}
|
||||
gui.Log.Errorf("tab not found for context %s", c.GetKey())
|
||||
return 0
|
||||
}
|
||||
|
||||
func (gui *Gui) refreshBranchesViewWithSelection() error {
|
||||
branchesView := gui.getBranchesView()
|
||||
|
||||
|
@ -3,6 +3,7 @@ package gui
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/jesseduffield/gocui"
|
||||
)
|
||||
|
||||
@ -18,6 +19,7 @@ func GetKindWrapper(k int) func() int { return func() int { return k } }
|
||||
type Context interface {
|
||||
HandleFocus() error
|
||||
HandleFocusLost() error
|
||||
HandleRender() error
|
||||
GetKind() int
|
||||
GetViewName() string
|
||||
GetKey() string
|
||||
@ -26,11 +28,19 @@ type Context interface {
|
||||
type BasicContext struct {
|
||||
OnFocus func() error
|
||||
OnFocusLost func() error
|
||||
OnRender func() error
|
||||
Kind int
|
||||
Key string
|
||||
ViewName string
|
||||
}
|
||||
|
||||
func (c BasicContext) HandleRender() error {
|
||||
if c.OnRender != nil {
|
||||
return c.OnRender()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c BasicContext) GetViewName() string {
|
||||
return c.ViewName
|
||||
}
|
||||
@ -159,7 +169,7 @@ func (gui *Gui) deactivateContext(c Context) error {
|
||||
}
|
||||
|
||||
func (gui *Gui) activateContext(c Context) error {
|
||||
gui.Log.Warn(gui.renderContextStack())
|
||||
gui.Log.Warn(spew.Sdump(gui.renderContextStack()))
|
||||
|
||||
viewName := c.GetViewName()
|
||||
_, err := gui.g.View(viewName)
|
||||
@ -205,7 +215,7 @@ func (gui *Gui) activateContext(c Context) error {
|
||||
func (gui *Gui) renderContextStack() string {
|
||||
result := ""
|
||||
for _, context := range gui.State.ContextStack {
|
||||
result += context.GetViewName() + "\n"
|
||||
result += context.GetKey() + "\n"
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -446,9 +456,9 @@ func (gui *Gui) changeMainViewsContext(context string) {
|
||||
gui.State.MainContext = context
|
||||
}
|
||||
|
||||
func (gui *Gui) viewTabContextMap() map[string]tabContexts {
|
||||
return map[string]tabContexts{
|
||||
"branches": tabContexts{
|
||||
func (gui *Gui) viewTabContextMap() map[string][]tabContext {
|
||||
return map[string][]tabContext{
|
||||
"branches": []tabContext{
|
||||
{
|
||||
tab: "Branches",
|
||||
contexts: []Context{gui.Contexts.Branches.Context},
|
||||
@ -465,7 +475,7 @@ func (gui *Gui) viewTabContextMap() map[string]tabContexts {
|
||||
contexts: []Context{gui.Contexts.Tags.Context},
|
||||
},
|
||||
},
|
||||
"commits": tabContexts{
|
||||
"commits": []tabContext{
|
||||
{
|
||||
tab: "Commits",
|
||||
contexts: []Context{gui.Contexts.BranchCommits.Context},
|
||||
@ -481,10 +491,13 @@ func (gui *Gui) viewTabContextMap() map[string]tabContexts {
|
||||
}
|
||||
|
||||
func (gui *Gui) setViewTabForContext(c Context) {
|
||||
gui.Log.Warnf("in set view tab: %s", c.GetKey())
|
||||
|
||||
// search for the context in our map and if we find it, set the tab for the corresponding view
|
||||
|
||||
tabContexts, ok := gui.ViewTabContextMap[c.GetViewName()]
|
||||
if !ok {
|
||||
gui.Log.Warnf("in set view tab: returning")
|
||||
return
|
||||
}
|
||||
|
||||
@ -497,6 +510,7 @@ func (gui *Gui) setViewTabForContext(c Context) {
|
||||
gui.Log.Error(err)
|
||||
return
|
||||
}
|
||||
gui.Log.Warnf("index: %d", tabIndex)
|
||||
v.TabIndex = tabIndex
|
||||
return
|
||||
}
|
||||
@ -504,7 +518,7 @@ func (gui *Gui) setViewTabForContext(c Context) {
|
||||
}
|
||||
}
|
||||
|
||||
type tabContexts []struct {
|
||||
type tabContext struct {
|
||||
tab string
|
||||
contexts []Context
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ type Gui struct {
|
||||
// recent repo with the recent repos popup showing
|
||||
showRecentRepos bool
|
||||
Contexts ContextTree
|
||||
ViewTabContextMap map[string]tabContexts
|
||||
ViewTabContextMap map[string][]tabContext
|
||||
}
|
||||
|
||||
// for now the staging panel state, unlike the other panel states, is going to be
|
||||
|
@ -11,9 +11,12 @@ type ListContext struct {
|
||||
OnFocusLost func() error
|
||||
OnItemSelect func() error
|
||||
OnClickSelectedItem func() error
|
||||
Gui *Gui
|
||||
RendersToMainView bool
|
||||
Kind int
|
||||
|
||||
// OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view
|
||||
OnRender func() error
|
||||
Gui *Gui
|
||||
RendersToMainView bool
|
||||
Kind int
|
||||
}
|
||||
|
||||
func (lc *ListContext) GetKey() string {
|
||||
@ -40,6 +43,10 @@ func (lc *ListContext) HandleFocus() error {
|
||||
return lc.OnFocus()
|
||||
}
|
||||
|
||||
func (lc *ListContext) HandleRender() error {
|
||||
return lc.OnRender()
|
||||
}
|
||||
|
||||
func (lc *ListContext) handlePrevLine(g *gocui.Gui, v *gocui.View) error {
|
||||
return lc.handleLineChange(-1)
|
||||
}
|
||||
@ -187,9 +194,9 @@ func (gui *Gui) branchesListContext() *ListContext {
|
||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Branches.SelectedLine },
|
||||
OnFocus: gui.handleBranchSelect,
|
||||
OnItemSelect: gui.handleBranchSelect,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
Gui: gui,
|
||||
RendersToMainView: true,
|
||||
Kind: SIDE_CONTEXT,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user