summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-01-09 22:23:28 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-01-09 22:36:07 +1100
commitd647a96ed55e134f1464878be8d0be3a464d996f (patch)
tree47b2818e5587d4cffbddc3b54523c7c795916e0c
parent1b64ea32102185229231907a843ab925146b0595 (diff)
add reflog reset optionsv0.13
-rw-r--r--pkg/gui/keybindings.go8
-rw-r--r--pkg/gui/reflog_reset_options_panel.go60
2 files changed, 68 insertions, 0 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 44417ad09..3048d3235 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -786,6 +786,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Description: gui.Tr.SLocalize("checkoutCommit"),
},
{
+ ViewName: "commits",
+ Contexts: []string{"reflog-commits"},
+ Key: gui.getKey("commits.viewResetOptions"),
+ Modifier: gocui.ModNone,
+ Handler: gui.handleCreateReflogResetMenu,
+ Description: gui.Tr.SLocalize("viewResetOptions"),
+ },
+ {
ViewName: "stash",
Key: gui.getKey("universal.select"),
Modifier: gocui.ModNone,
diff --git a/pkg/gui/reflog_reset_options_panel.go b/pkg/gui/reflog_reset_options_panel.go
new file mode 100644
index 000000000..c76dfed81
--- /dev/null
+++ b/pkg/gui/reflog_reset_options_panel.go
@@ -0,0 +1,60 @@
+package gui
+
+import (
+ "fmt"
+
+ "github.com/fatih/color"
+ "github.com/jesseduffield/gocui"
+)
+
+type reflogResetOption struct {
+ handler func() error
+ description string
+ command string
+}
+
+// GetDisplayStrings is a function.
+func (r *reflogResetOption) GetDisplayStrings(isFocused bool) []string {
+ return []string{r.description, color.New(color.FgRed).Sprint(r.command)}
+}
+
+func (gui *Gui) handleCreateReflogResetMenu(g *gocui.Gui, v *gocui.View) error {
+ commit := gui.getSelectedReflogCommit()
+
+ resetFunction := func(reset func(string) error) func() error {
+ return func() error {
+ if err := reset(commit.Sha); err != nil {
+ return gui.createErrorPanel(gui.g, err.Error())
+ }
+
+ gui.State.Panels.ReflogCommits.SelectedLine = 0
+
+ return gui.refreshSidePanels(gui.g)
+ }
+ }
+
+ options := []*reflogResetOption{
+ {
+ description: gui.Tr.SLocalize("hardReset"),
+ command: fmt.Sprintf("reset --hard %s", commit.Sha),
+ handler: resetFunction(gui.GitCommand.ResetHard),
+ },
+ {
+ description: gui.Tr.SLocalize("softReset"),
+ command: fmt.Sprintf("reset --soft %s", commit.Sha),
+ handler: resetFunction(gui.GitCommand.ResetSoft),
+ },
+ {
+ 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)
+}