From dfcceb9edd2a76b4033f002efd73b4d68218a8bf Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 13 Apr 2020 00:36:43 +1000 Subject: [PATCH] more click support --- pkg/gui/global_handlers.go | 19 +++++++++++++------ pkg/gui/keybindings.go | 7 +------ pkg/gui/list_view.go | 5 +++++ pkg/gui/main_view.go | 7 ++++++- pkg/gui/view_helpers.go | 4 +++- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index e44ce90..510beff 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -104,15 +104,13 @@ func (gui *Gui) handleMouseDownMain(g *gocui.Gui, v *gocui.View) error { return nil } - return gui.switchFocus(gui.g, gui.g.CurrentView(), gui.getMainView()) -} - -func (gui *Gui) handleMouseDownSecondary(g *gocui.Gui, v *gocui.View) error { - if gui.popupPanelFocused() { + id := gui.currentContextViewID() + view, err := gui.g.View(id) + if err != nil { return nil } - return nil + return gui.switchFocus(gui.g, gui.g.CurrentView(), view) } func (gui *Gui) handleInfoClick(g *gocui.Gui, v *gocui.View) error { @@ -180,3 +178,12 @@ func (gui *Gui) finalStep(err error) error { return gui.surfaceError(gui.refreshPackages()) } + +func (gui *Gui) enterMainView() error { + id := gui.currentContextViewID() + view, err := gui.g.View(id) + if err != nil { + return nil + } + return gui.switchFocus(gui.g, gui.g.CurrentView(), view) +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 559a6cd..6c4c2a9 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -328,12 +328,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Key: gocui.MouseLeft, Handler: gui.handleInfoClick, }, - { - ViewName: "secondary", - Contexts: []string{"normal"}, - Key: gocui.MouseLeft, - Handler: gui.handleMouseDownSecondary, - }, { ViewName: "status", Key: gocui.MouseLeft, @@ -508,6 +502,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { // Appends keybindings to jump to a particular sideView using numbers for i, viewName := range []string{"status", "packages", "deps", "scripts"} { bindings = append(bindings, &Binding{ViewName: "", Key: rune(i+1) + '0', Handler: gui.goToSideView(viewName)}) + bindings = append(bindings, &Binding{ViewName: viewName, Key: gui.getKey("universal.goInto"), Handler: gui.wrappedHandler(gui.enterMainView)}) } for _, listView := range gui.getListViews() { diff --git a/pkg/gui/list_view.go b/pkg/gui/list_view.go index ef30d3d..23ce52a 100644 --- a/pkg/gui/list_view.go +++ b/pkg/gui/list_view.go @@ -90,6 +90,11 @@ func (lv *listView) handleClick(g *gocui.Gui, v *gocui.View) error { prevSelectedLineIdx := *selectedLineIdxPtr newSelectedLineIdx := v.SelectedLineIdx() + // we need to focus the view + if err := lv.gui.switchFocus(lv.gui.g, nil, v); err != nil { + return err + } + if newSelectedLineIdx > lv.getItemsLength()-1 { return lv.handleFocus(lv.gui.g, v) } diff --git a/pkg/gui/main_view.go b/pkg/gui/main_view.go index fe9f2eb..808f1d9 100644 --- a/pkg/gui/main_view.go +++ b/pkg/gui/main_view.go @@ -1,5 +1,10 @@ package gui func (gui *Gui) handleEscapeMain() error { - return gui.returnFocus(gui.g, nil) + viewName := gui.State.CurrentSideView + view, err := gui.g.View(viewName) + if err != nil { + return nil + } + return gui.switchFocus(gui.g, nil, view) } diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index ca0d4d4..7658a67 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -105,8 +105,10 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error { return nil case "search", "confirmation": return nil + case "tarballs": + panic("remind me to do this") default: - panic(gui.Tr.SLocalize("NoViewMachingNewLineFocusedSwitchStatement")) + return nil } }