1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/discard_changes_menu_panel.go

43 lines
1.0 KiB
Go
Raw Normal View History

2020-02-14 13:07:56 +02:00
package gui
import (
"github.com/jesseduffield/gocui"
)
func (gui *Gui) handleCreateDiscardMenu(g *gocui.Gui, v *gocui.View) error {
file, err := gui.getSelectedFile(g)
if err != nil {
if err != gui.Errors.ErrNoFiles {
return err
}
return nil
}
menuItems := []*menuItem{
{
2020-02-14 13:32:31 +02:00
displayString: gui.Tr.SLocalize("discardAllChanges"),
2020-02-14 13:07:56 +02:00
onPress: func() error {
if err := gui.GitCommand.DiscardAllFileChanges(file); err != nil {
return err
}
2020-03-28 00:57:36 +02:00
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{FILES}})
2020-02-14 13:07:56 +02:00
},
},
}
if file.HasStagedChanges && file.HasUnstagedChanges {
menuItems = append(menuItems, &menuItem{
2020-02-14 13:32:31 +02:00
displayString: gui.Tr.SLocalize("discardUnstagedChanges"),
2020-02-14 13:07:56 +02:00
onPress: func() error {
if err := gui.GitCommand.DiscardUnstagedFileChanges(file); err != nil {
return err
}
2020-03-28 00:57:36 +02:00
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{FILES}})
2020-02-14 13:07:56 +02:00
},
})
}
2020-02-14 14:39:02 +02:00
return gui.createMenu(file.Name, menuItems, createMenuOptions{showCancel: true})
2020-02-14 13:07:56 +02:00
}