diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index 5429ec2e89d..849157598f0 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -6,16 +6,6 @@ import ( "github.com/jesseduffield/gocui" ) -type patchMenuOption struct { - displayName string - function func() error -} - -// GetDisplayStrings is a function. -func (o *patchMenuOption) GetDisplayStrings(isFocused bool) []string { - return []string{o.displayName} -} - func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error { if !gui.GitCommand.PatchManager.CommitSelected() { return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoPatchError")) diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go index e766070fbd6..fc4ff98c7bc 100644 --- a/pkg/gui/reflog_panel.go +++ b/pkg/gui/reflog_panel.go @@ -95,3 +95,9 @@ func (gui *Gui) handleCheckoutReflogCommit(g *gocui.Gui, v *gocui.View) error { return nil } + +func (gui *Gui) handleCreateReflogResetMenu(g *gocui.Gui, v *gocui.View) error { + commit := gui.getSelectedReflogCommit() + + return gui.createResetMenu(commit.Sha) +} diff --git a/pkg/gui/reflog_reset_options_panel.go b/pkg/gui/reflog_reset_options_panel.go deleted file mode 100644 index 54edad47579..00000000000 --- a/pkg/gui/reflog_reset_options_panel.go +++ /dev/null @@ -1,55 +0,0 @@ -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() - red := color.New(color.FgRed) - - 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) - } - } - - menuItems := []*menuItem{ - { - displayStrings: []string{ - gui.Tr.SLocalize("hardReset"), - red.Sprint(fmt.Sprintf("reset --hard %s", commit.Sha)), - }, - onPress: resetFunction(gui.GitCommand.ResetHard), - }, - { - displayStrings: []string{ - gui.Tr.SLocalize("softReset"), - red.Sprint(fmt.Sprintf("reset --soft %s", commit.Sha)), - }, - onPress: resetFunction(gui.GitCommand.ResetSoft), - }, - } - - return gui.createMenu("", menuItems, createMenuOptions{showCancel: true}) -} diff --git a/pkg/gui/reset_menu_panel.go b/pkg/gui/reset_menu_panel.go index 10f2705dc65..44c33e0355e 100644 --- a/pkg/gui/reset_menu_panel.go +++ b/pkg/gui/reset_menu_panel.go @@ -20,9 +20,13 @@ func (gui *Gui) createResetMenu(ref string) error { }, onPress: func() error { if err := gui.GitCommand.ResetToCommit(ref, innerStrength); err != nil { - return err + return gui.createErrorPanel(gui.g, err.Error()) } + gui.switchCommitsPanelContext("branch-commits") + gui.State.Panels.Commits.SelectedLine = 0 + gui.State.Panels.ReflogCommits.SelectedLine = 0 + if err := gui.refreshCommits(gui.g); err != nil { return err } @@ -33,7 +37,6 @@ func (gui *Gui) createResetMenu(ref string) error { return err } - gui.State.Panels.Commits.SelectedLine = 0 return gui.handleCommitSelect(gui.g, gui.getCommitsView()) }, }