From eb9134685a0ffd89771fb0d68b3c3ca33f06445f Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 14 Feb 2020 23:29:41 +1100 Subject: [PATCH] refactor rebase menu panel --- pkg/gui/rebase_options_panel.go | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/pkg/gui/rebase_options_panel.go b/pkg/gui/rebase_options_panel.go index bf29d19c3..7ba3f45ab 100644 --- a/pkg/gui/rebase_options_panel.go +++ b/pkg/gui/rebase_options_panel.go @@ -7,33 +7,21 @@ import ( "github.com/jesseduffield/gocui" ) -type option struct { - value string -} - -// GetDisplayStrings is a function. -func (r *option) GetDisplayStrings(isFocused bool) []string { - return []string{r.value} -} - func (gui *Gui) handleCreateRebaseOptionsMenu(g *gocui.Gui, v *gocui.View) error { - options := []*option{ - {value: "continue"}, - {value: "abort"}, - } + options := []string{"continue", "abort"} if gui.State.WorkingTreeState == "rebasing" { - options = append(options, &option{value: "skip"}) + options = append(options, "skip") } - options = append(options, &option{value: "cancel"}) - - handleMenuPress := func(index int) error { - command := options[index].value - if command == "cancel" { - return nil + menuItems := make([]*menuItem, len(options)) + for i, option := range options { + menuItems[i] = &menuItem{ + displayString: option, + onPress: func() error { + return gui.genericMergeCommand(option) + }, } - return gui.genericMergeCommand(command) } var title string @@ -43,7 +31,7 @@ func (gui *Gui) handleCreateRebaseOptionsMenu(g *gocui.Gui, v *gocui.View) error title = gui.Tr.SLocalize("RebaseOptionsTitle") } - return gui.createMenu(title, options, len(options), handleMenuPress) + return gui.createMenuNew(title, menuItems, createMenuOptions{showCancel: true}) } func (gui *Gui) genericMergeCommand(command string) error {