1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-26 05:37:18 +02:00
lazygit/pkg/gui/discard_changes_menu_panel.go

57 lines
1.3 KiB
Go
Raw Normal View History

2020-02-14 22:07:56 +11:00
package gui
import (
"github.com/jesseduffield/gocui"
)
func (gui *Gui) handleCreateDiscardMenu(g *gocui.Gui, v *gocui.View) error {
2020-08-16 17:45:12 +10:00
file := gui.getSelectedFile()
if file == nil {
2020-02-14 22:07:56 +11:00
return nil
}
2020-09-28 09:14:32 +10:00
var menuItems []*menuItem
2020-09-28 08:21:53 +10:00
2020-09-30 09:06:11 +10:00
submodules := gui.State.Submodules
if file.IsSubmodule(submodules) {
submodule := file.SubmoduleConfig(submodules)
2020-09-28 09:14:32 +10:00
menuItems = []*menuItem{
{
2020-10-04 11:00:48 +11:00
displayString: gui.Tr.LcSubmoduleStashAndReset,
2020-09-28 09:14:32 +10:00
onPress: func() error {
2020-11-16 20:38:26 +11:00
return gui.handleResetSubmodule(submodule)
2020-09-28 09:14:32 +10:00
},
2020-02-14 22:07:56 +11:00
},
2020-09-28 09:14:32 +10:00
}
} else {
menuItems = []*menuItem{
{
2020-10-04 11:00:48 +11:00
displayString: gui.Tr.LcDiscardAllChanges,
2020-09-28 09:14:32 +10:00
onPress: func() error {
if err := gui.GitCommand.DiscardAllFileChanges(file); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{FILES}})
},
},
}
2020-02-14 22:07:56 +11:00
2020-09-28 09:14:32 +10:00
if file.HasStagedChanges && file.HasUnstagedChanges {
menuItems = append(menuItems, &menuItem{
2020-10-04 11:00:48 +11:00
displayString: gui.Tr.LcDiscardUnstagedChanges,
2020-09-28 09:14:32 +10:00
onPress: func() error {
if err := gui.GitCommand.DiscardUnstagedFileChanges(file); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{FILES}})
},
})
}
2020-02-14 22:07:56 +11:00
}
2020-02-14 23:39:02 +11:00
return gui.createMenu(file.Name, menuItems, createMenuOptions{showCancel: true})
2020-02-14 22:07:56 +11:00
}