summaryrefslogtreecommitdiffstats
path: root/pkg/gui/layout.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-04-03 11:32:14 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-04-06 19:34:32 +1000
commitbc9a99387f68afb24863d17ab4d29c1686843a76 (patch)
treeaac694046f93d457177086d4c5afb5a0c12ea302 /pkg/gui/layout.go
parent5289d49f75e9735f129e1f8e2a2f9dc74373515b (diff)
refactor of contexts and filtering
Diffstat (limited to 'pkg/gui/layout.go')
-rw-r--r--pkg/gui/layout.go43
1 files changed, 13 insertions, 30 deletions
diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go
index 2594cb9ad..32ad1de85 100644
--- a/pkg/gui/layout.go
+++ b/pkg/gui/layout.go
@@ -152,7 +152,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
branchesView.ContainsList = true
}
- commitFilesView, err := setViewFromDimensions("commitFiles", gui.Contexts.CommitFiles.Context.GetWindowName(), true)
+ commitFilesView, err := setViewFromDimensions("commitFiles", gui.Contexts.CommitFiles.GetWindowName(), true)
if err != nil {
if err.Error() != UNKNOWN_VIEW_ERROR_MSG {
return err
@@ -272,9 +272,9 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
if gui.g.CurrentView() == nil {
- initialContext := gui.Contexts.Files.Context
+ initialContext := gui.Contexts.Files
if gui.State.Modes.Filtering.Active() {
- initialContext = gui.Contexts.BranchCommits.Context
+ initialContext = gui.Contexts.BranchCommits
}
if err := gui.pushContext(initialContext); err != nil {
@@ -282,41 +282,24 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
}
- type listContextState struct {
- view *gocui.View
- listContext *ListContext
- }
-
- // TODO: don't we already have the view included in the context object itself? Or might that change in a way we don't want reflected here?
- listContextStates := []listContextState{
- {view: filesView, listContext: gui.filesListContext()},
- {view: filesView, listContext: gui.submodulesListContext()},
- {view: branchesView, listContext: gui.branchesListContext()},
- {view: branchesView, listContext: gui.remotesListContext()},
- {view: branchesView, listContext: gui.remoteBranchesListContext()},
- {view: branchesView, listContext: gui.tagsListContext()},
- {view: commitsView, listContext: gui.branchCommitsListContext()},
- {view: commitsView, listContext: gui.reflogCommitsListContext()},
- {view: stashView, listContext: gui.stashListContext()},
- {view: commitFilesView, listContext: gui.commitFilesListContext()},
- }
+ for _, listContext := range gui.getListContexts() {
+ view, err := gui.g.View(listContext.ViewName)
+ if err != nil {
+ continue
+ }
- // menu view might not exist so we check to be safe
- if menuView, err := gui.g.View("menu"); err == nil {
- listContextStates = append(listContextStates, listContextState{view: menuView, listContext: gui.menuListContext()})
- }
- for _, listContextState := range listContextStates {
// ignore contexts whose view is owned by another context right now
- if listContextState.view.Context != listContextState.listContext.GetKey() {
+ if view.Context != listContext.GetKey() {
continue
}
+
// check if the selected line is now out of view and if so refocus it
- listContextState.view.FocusPoint(0, listContextState.listContext.GetPanelState().GetSelectedLineIdx())
+ view.FocusPoint(0, listContext.GetPanelState().GetSelectedLineIdx())
- listContextState.view.SelBgColor = theme.GocuiSelectedLineBgColor
+ view.SelBgColor = theme.GocuiSelectedLineBgColor
// I doubt this is expensive though it's admittedly redundant after the first render
- listContextState.view.SetOnSelectItem(gui.onSelectItemWrapper(listContextState.listContext.onSearchSelect))
+ view.SetOnSelectItem(gui.onSelectItemWrapper(listContext.onSearchSelect))
}
gui.getMainView().SetOnSelectItem(gui.onSelectItemWrapper(gui.handlelineByLineNavigateTo))