Skip to content

Commit

Permalink
allow click events in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Jun 29, 2019
1 parent 7025468 commit 0e76f61
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
nextLine func(*gocui.Gui, *gocui.View) error
focus func(*gocui.Gui, *gocui.View) error
}{
"menu": {prevLine: gui.handleMenuPrevLine, nextLine: gui.handleMenuNextLine, focus: gui.handleMenuSelect},
"menu": {prevLine: gui.handleMenuPrevLine, nextLine: gui.handleMenuNextLine, focus: gui.handleMenuClick},
"services": {prevLine: gui.handleServicesPrevLine, nextLine: gui.handleServicesNextLine, focus: gui.handleServicesClick},
"containers": {prevLine: gui.handleContainersPrevLine, nextLine: gui.handleContainersNextLine, focus: gui.handleContainersClick},
"images": {prevLine: gui.handleImagesPrevLine, nextLine: gui.handleImagesNextLine, focus: gui.handleImagesClick},
Expand Down
8 changes: 8 additions & 0 deletions pkg/gui/menu_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func (gui *Gui) handleMenuNextLine(g *gocui.Gui, v *gocui.View) error {
return gui.handleMenuSelect(g, v)
}

func (gui *Gui) handleMenuClick(g *gocui.Gui, v *gocui.View) error {
itemCount := gui.State.MenuItemCount
handleSelect := gui.handleMenuSelect
selectedLine := &gui.State.Panels.Menu.SelectedLine

return gui.handleClick(v, itemCount, selectedLine, handleSelect)
}

func (gui *Gui) handleMenuPrevLine(g *gocui.Gui, v *gocui.View) error {
panelState := gui.State.Panels.Menu
gui.changeSelectedLine(&panelState.SelectedLine, v.LinesHeight(), true)
Expand Down
4 changes: 4 additions & 0 deletions pkg/gui/options_menu_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (gui *Gui) getBindings(v *gocui.View) []*Binding {
}

func (gui *Gui) handleCreateOptionsMenu(g *gocui.Gui, v *gocui.View) error {
if v.Name() == "menu" {
return nil
}

bindings := gui.getBindings(v)

handleMenuPress := func(index int) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/view_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (gui *Gui) clearMainView() {
}

func (gui *Gui) handleClick(v *gocui.View, itemCount int, selectedLine *int, handleSelect func(*gocui.Gui, *gocui.View) error) error {
if gui.popupPanelFocused() {
if gui.popupPanelFocused() && v != nil && !gui.isPopupPanel(v.Name()) {
return nil
}

Expand Down

0 comments on commit 0e76f61

Please sign in to comment.