diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-14 23:13:37 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-15 08:47:36 +1100 |
commit | 27c7aeb1177f95f63e49af3fea5844acf4e01d64 (patch) | |
tree | 726adbc0049edc1cf96d71258628397931d26105 /pkg/gui/workspace_reset_options_panel.go | |
parent | c9714600e832875533fd1d2f4cbe615452727e05 (diff) |
refactor workspace reset options panel
Diffstat (limited to 'pkg/gui/workspace_reset_options_panel.go')
-rw-r--r-- | pkg/gui/workspace_reset_options_panel.go | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/pkg/gui/workspace_reset_options_panel.go b/pkg/gui/workspace_reset_options_panel.go index 0e3cd59c6..5f92c0efb 100644 --- a/pkg/gui/workspace_reset_options_panel.go +++ b/pkg/gui/workspace_reset_options_panel.go @@ -5,23 +5,16 @@ import ( "github.com/jesseduffield/gocui" ) -type workspaceResetOption struct { - handler func() error - description string - command string -} - -// GetDisplayStrings is a function. -func (r *workspaceResetOption) GetDisplayStrings(isFocused bool) []string { - return []string{r.description, color.New(color.FgRed).Sprint(r.command)} -} - func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error { - options := []*workspaceResetOption{ + red := color.New(color.FgRed) + + menuItems := []*menuItem{ { - description: gui.Tr.SLocalize("discardAllChangesToAllFiles"), - command: "reset --hard HEAD && git clean -fd", - handler: func() error { + displayStrings: []string{ + gui.Tr.SLocalize("discardAllChangesToAllFiles"), + red.Sprint("reset --hard HEAD && git clean -fd"), + }, + onPress: func() error { if err := gui.GitCommand.ResetAndClean(); err != nil { return gui.createErrorPanel(gui.g, err.Error()) } @@ -30,9 +23,11 @@ func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error { }, }, { - description: gui.Tr.SLocalize("discardAnyUnstagedChanges"), - command: "git checkout -- .", - handler: func() error { + displayStrings: []string{ + gui.Tr.SLocalize("discardAnyUnstagedChanges"), + red.Sprint("git checkout -- ."), + }, + onPress: func() error { if err := gui.GitCommand.DiscardAnyUnstagedFileChanges(); err != nil { return gui.createErrorPanel(gui.g, err.Error()) } @@ -41,9 +36,11 @@ func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error { }, }, { - description: gui.Tr.SLocalize("discardUntrackedFiles"), - command: "git clean -fd", - handler: func() error { + displayStrings: []string{ + gui.Tr.SLocalize("discardUntrackedFiles"), + red.Sprint("git clean -fd"), + }, + onPress: func() error { if err := gui.GitCommand.RemoveUntrackedFiles(); err != nil { return gui.createErrorPanel(gui.g, err.Error()) } @@ -52,9 +49,11 @@ func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error { }, }, { - description: gui.Tr.SLocalize("softReset"), - command: "git reset --soft HEAD", - handler: func() error { + displayStrings: []string{ + gui.Tr.SLocalize("softReset"), + red.Sprint("git reset --soft HEAD"), + }, + onPress: func() error { if err := gui.GitCommand.ResetSoft("HEAD"); err != nil { return gui.createErrorPanel(gui.g, err.Error()) } @@ -63,9 +62,11 @@ func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error { }, }, { - description: gui.Tr.SLocalize("hardReset"), - command: "git reset --hard HEAD", - handler: func() error { + displayStrings: []string{ + gui.Tr.SLocalize("hardReset"), + red.Sprint("git reset --hard HEAD"), + }, + onPress: func() error { if err := gui.GitCommand.ResetHard("HEAD"); err != nil { return gui.createErrorPanel(gui.g, err.Error()) } @@ -74,9 +75,11 @@ func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error { }, }, { - description: gui.Tr.SLocalize("hardResetUpstream"), - command: "git reset --hard @{upstream}", - handler: func() error { + displayStrings: []string{ + gui.Tr.SLocalize("hardResetUpstream"), + red.Sprint("git reset --hard @{upstream}"), + }, + onPress: func() error { if err := gui.GitCommand.ResetHard("@{upstream}"); err != nil { return gui.createErrorPanel(gui.g, err.Error()) } @@ -84,17 +87,7 @@ func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error { return gui.refreshSidePanels(gui.g) }, }, - { - description: gui.Tr.SLocalize("cancel"), - handler: func() error { - return nil - }, - }, - } - - handleMenuPress := func(index int) error { - return options[index].handler() } - return gui.createMenu("", options, len(options), handleMenuPress) + return gui.createMenuNew("", menuItems, createMenuOptions{showCancel: true}) } |