From 6fdc1791e4197a4149e80323c72ea00d6317bd74 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 14 Feb 2020 23:36:55 +1100 Subject: [PATCH] refactor stash options menu --- pkg/gui/files_panel.go | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index c2f3b9206..a92561a50 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -548,43 +548,23 @@ func (gui *Gui) handleCustomCommand(g *gocui.Gui, v *gocui.View) error { }) } -type stashOption struct { - description string - handler func() error -} - -// GetDisplayStrings is a function. -func (o *stashOption) GetDisplayStrings(isFocused bool) []string { - return []string{o.description} -} - func (gui *Gui) handleCreateStashMenu(g *gocui.Gui, v *gocui.View) error { - options := []*stashOption{ + menuItems := []*menuItem{ { - description: gui.Tr.SLocalize("stashAllChanges"), - handler: func() error { + displayString: gui.Tr.SLocalize("stashAllChanges"), + onPress: func() error { return gui.handleStashSave(gui.GitCommand.StashSave) }, }, { - description: gui.Tr.SLocalize("stashStagedChanges"), - handler: func() error { + displayString: gui.Tr.SLocalize("stashStagedChanges"), + onPress: func() error { return gui.handleStashSave(gui.GitCommand.StashSaveStagedChanges) }, }, - { - description: gui.Tr.SLocalize("cancel"), - handler: func() error { - return nil - }, - }, } - handleMenuPress := func(index int) error { - return options[index].handler() - } - - return gui.createMenu(gui.Tr.SLocalize("stashOptions"), options, len(options), handleMenuPress) + return gui.createMenuNew(gui.Tr.SLocalize("stashOptions"), menuItems, createMenuOptions{showCancel: true}) } func (gui *Gui) handleStashChanges(g *gocui.Gui, v *gocui.View) error {