mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-17 01:42:45 +02:00
prepare for OnRender prop
This commit is contained in:
@ -454,18 +454,6 @@ func (gui *Gui) onBranchesTabClick(tabIndex int) error {
|
|||||||
return gui.switchContext(context)
|
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 {
|
func (gui *Gui) refreshBranchesViewWithSelection() error {
|
||||||
branchesView := gui.getBranchesView()
|
branchesView := gui.getBranchesView()
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package gui
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ func GetKindWrapper(k int) func() int { return func() int { return k } }
|
|||||||
type Context interface {
|
type Context interface {
|
||||||
HandleFocus() error
|
HandleFocus() error
|
||||||
HandleFocusLost() error
|
HandleFocusLost() error
|
||||||
|
HandleRender() error
|
||||||
GetKind() int
|
GetKind() int
|
||||||
GetViewName() string
|
GetViewName() string
|
||||||
GetKey() string
|
GetKey() string
|
||||||
@ -26,11 +28,19 @@ type Context interface {
|
|||||||
type BasicContext struct {
|
type BasicContext struct {
|
||||||
OnFocus func() error
|
OnFocus func() error
|
||||||
OnFocusLost func() error
|
OnFocusLost func() error
|
||||||
|
OnRender func() error
|
||||||
Kind int
|
Kind int
|
||||||
Key string
|
Key string
|
||||||
ViewName string
|
ViewName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c BasicContext) HandleRender() error {
|
||||||
|
if c.OnRender != nil {
|
||||||
|
return c.OnRender()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c BasicContext) GetViewName() string {
|
func (c BasicContext) GetViewName() string {
|
||||||
return c.ViewName
|
return c.ViewName
|
||||||
}
|
}
|
||||||
@ -159,7 +169,7 @@ func (gui *Gui) deactivateContext(c Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) activateContext(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()
|
viewName := c.GetViewName()
|
||||||
_, err := gui.g.View(viewName)
|
_, err := gui.g.View(viewName)
|
||||||
@ -205,7 +215,7 @@ func (gui *Gui) activateContext(c Context) error {
|
|||||||
func (gui *Gui) renderContextStack() string {
|
func (gui *Gui) renderContextStack() string {
|
||||||
result := ""
|
result := ""
|
||||||
for _, context := range gui.State.ContextStack {
|
for _, context := range gui.State.ContextStack {
|
||||||
result += context.GetViewName() + "\n"
|
result += context.GetKey() + "\n"
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -446,9 +456,9 @@ func (gui *Gui) changeMainViewsContext(context string) {
|
|||||||
gui.State.MainContext = context
|
gui.State.MainContext = context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) viewTabContextMap() map[string]tabContexts {
|
func (gui *Gui) viewTabContextMap() map[string][]tabContext {
|
||||||
return map[string]tabContexts{
|
return map[string][]tabContext{
|
||||||
"branches": tabContexts{
|
"branches": []tabContext{
|
||||||
{
|
{
|
||||||
tab: "Branches",
|
tab: "Branches",
|
||||||
contexts: []Context{gui.Contexts.Branches.Context},
|
contexts: []Context{gui.Contexts.Branches.Context},
|
||||||
@ -465,7 +475,7 @@ func (gui *Gui) viewTabContextMap() map[string]tabContexts {
|
|||||||
contexts: []Context{gui.Contexts.Tags.Context},
|
contexts: []Context{gui.Contexts.Tags.Context},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"commits": tabContexts{
|
"commits": []tabContext{
|
||||||
{
|
{
|
||||||
tab: "Commits",
|
tab: "Commits",
|
||||||
contexts: []Context{gui.Contexts.BranchCommits.Context},
|
contexts: []Context{gui.Contexts.BranchCommits.Context},
|
||||||
@ -481,10 +491,13 @@ func (gui *Gui) viewTabContextMap() map[string]tabContexts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) setViewTabForContext(c Context) {
|
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
|
// 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()]
|
tabContexts, ok := gui.ViewTabContextMap[c.GetViewName()]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
gui.Log.Warnf("in set view tab: returning")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,6 +510,7 @@ func (gui *Gui) setViewTabForContext(c Context) {
|
|||||||
gui.Log.Error(err)
|
gui.Log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
gui.Log.Warnf("index: %d", tabIndex)
|
||||||
v.TabIndex = tabIndex
|
v.TabIndex = tabIndex
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -504,7 +518,7 @@ func (gui *Gui) setViewTabForContext(c Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type tabContexts []struct {
|
type tabContext struct {
|
||||||
tab string
|
tab string
|
||||||
contexts []Context
|
contexts []Context
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ type Gui struct {
|
|||||||
// recent repo with the recent repos popup showing
|
// recent repo with the recent repos popup showing
|
||||||
showRecentRepos bool
|
showRecentRepos bool
|
||||||
Contexts ContextTree
|
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
|
// 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
|
OnFocusLost func() error
|
||||||
OnItemSelect func() error
|
OnItemSelect func() error
|
||||||
OnClickSelectedItem func() error
|
OnClickSelectedItem func() error
|
||||||
Gui *Gui
|
|
||||||
RendersToMainView bool
|
// 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
|
||||||
Kind int
|
OnRender func() error
|
||||||
|
Gui *Gui
|
||||||
|
RendersToMainView bool
|
||||||
|
Kind int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lc *ListContext) GetKey() string {
|
func (lc *ListContext) GetKey() string {
|
||||||
@ -40,6 +43,10 @@ func (lc *ListContext) HandleFocus() error {
|
|||||||
return lc.OnFocus()
|
return lc.OnFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (lc *ListContext) HandleRender() error {
|
||||||
|
return lc.OnRender()
|
||||||
|
}
|
||||||
|
|
||||||
func (lc *ListContext) handlePrevLine(g *gocui.Gui, v *gocui.View) error {
|
func (lc *ListContext) handlePrevLine(g *gocui.Gui, v *gocui.View) error {
|
||||||
return lc.handleLineChange(-1)
|
return lc.handleLineChange(-1)
|
||||||
}
|
}
|
||||||
@ -187,9 +194,9 @@ func (gui *Gui) branchesListContext() *ListContext {
|
|||||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Branches.SelectedLine },
|
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Branches.SelectedLine },
|
||||||
OnFocus: gui.handleBranchSelect,
|
OnFocus: gui.handleBranchSelect,
|
||||||
OnItemSelect: gui.handleBranchSelect,
|
OnItemSelect: gui.handleBranchSelect,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user