mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-06 03:53:59 +02:00
refactor workspace reset options panel
This commit is contained in:
parent
c9714600e8
commit
27c7aeb117
@ -5,23 +5,16 @@ import (
|
|||||||
"github.com/jesseduffield/gocui"
|
"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 {
|
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"),
|
displayStrings: []string{
|
||||||
command: "reset --hard HEAD && git clean -fd",
|
gui.Tr.SLocalize("discardAllChangesToAllFiles"),
|
||||||
handler: func() error {
|
red.Sprint("reset --hard HEAD && git clean -fd"),
|
||||||
|
},
|
||||||
|
onPress: func() error {
|
||||||
if err := gui.GitCommand.ResetAndClean(); err != nil {
|
if err := gui.GitCommand.ResetAndClean(); err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
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"),
|
displayStrings: []string{
|
||||||
command: "git checkout -- .",
|
gui.Tr.SLocalize("discardAnyUnstagedChanges"),
|
||||||
handler: func() error {
|
red.Sprint("git checkout -- ."),
|
||||||
|
},
|
||||||
|
onPress: func() error {
|
||||||
if err := gui.GitCommand.DiscardAnyUnstagedFileChanges(); err != nil {
|
if err := gui.GitCommand.DiscardAnyUnstagedFileChanges(); err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
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"),
|
displayStrings: []string{
|
||||||
command: "git clean -fd",
|
gui.Tr.SLocalize("discardUntrackedFiles"),
|
||||||
handler: func() error {
|
red.Sprint("git clean -fd"),
|
||||||
|
},
|
||||||
|
onPress: func() error {
|
||||||
if err := gui.GitCommand.RemoveUntrackedFiles(); err != nil {
|
if err := gui.GitCommand.RemoveUntrackedFiles(); err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
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"),
|
displayStrings: []string{
|
||||||
command: "git reset --soft HEAD",
|
gui.Tr.SLocalize("softReset"),
|
||||||
handler: func() error {
|
red.Sprint("git reset --soft HEAD"),
|
||||||
|
},
|
||||||
|
onPress: func() error {
|
||||||
if err := gui.GitCommand.ResetSoft("HEAD"); err != nil {
|
if err := gui.GitCommand.ResetSoft("HEAD"); err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
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"),
|
displayStrings: []string{
|
||||||
command: "git reset --hard HEAD",
|
gui.Tr.SLocalize("hardReset"),
|
||||||
handler: func() error {
|
red.Sprint("git reset --hard HEAD"),
|
||||||
|
},
|
||||||
|
onPress: func() error {
|
||||||
if err := gui.GitCommand.ResetHard("HEAD"); err != nil {
|
if err := gui.GitCommand.ResetHard("HEAD"); err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
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"),
|
displayStrings: []string{
|
||||||
command: "git reset --hard @{upstream}",
|
gui.Tr.SLocalize("hardResetUpstream"),
|
||||||
handler: func() error {
|
red.Sprint("git reset --hard @{upstream}"),
|
||||||
|
},
|
||||||
|
onPress: func() error {
|
||||||
if err := gui.GitCommand.ResetHard("@{upstream}"); err != nil {
|
if err := gui.GitCommand.ResetHard("@{upstream}"); err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
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)
|
return gui.refreshSidePanels(gui.g)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
description: gui.Tr.SLocalize("cancel"),
|
|
||||||
handler: func() error {
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMenuPress := func(index int) error {
|
return gui.createMenuNew("", menuItems, createMenuOptions{showCancel: true})
|
||||||
return options[index].handler()
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.createMenu("", options, len(options), handleMenuPress)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user