diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 4efbe6397..79b436c4e 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -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() diff --git a/pkg/gui/context.go b/pkg/gui/context.go index ef3139f48..e41224d2a 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -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 } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 818cfbf60..5aede3f9b 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -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 diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index 7a1248d22..9454aadf9 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -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, } }