2020-02-14 13:07:56 +02:00
|
|
|
package gui
|
|
|
|
|
2021-03-15 13:29:34 +02:00
|
|
|
func (gui *Gui) handleCreateDiscardMenu() error {
|
2021-03-31 14:26:53 +02:00
|
|
|
node := gui.getSelectedFileNode()
|
2021-03-15 13:29:34 +02:00
|
|
|
if node == nil {
|
2020-02-14 13:07:56 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-28 01:14:32 +02:00
|
|
|
var menuItems []*menuItem
|
2021-03-15 13:29:34 +02:00
|
|
|
if node.File == nil {
|
2020-09-28 01:14:32 +02:00
|
|
|
menuItems = []*menuItem{
|
|
|
|
{
|
2020-10-04 02:00:48 +02:00
|
|
|
displayString: gui.Tr.LcDiscardAllChanges,
|
2020-09-28 01:14:32 +02:00
|
|
|
onPress: func() error {
|
2021-04-11 11:35:42 +02:00
|
|
|
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardAllChangesInDirectory).DiscardAllDirChanges(node); err != nil {
|
2020-09-28 01:14:32 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
2020-09-28 01:14:32 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-02-14 13:07:56 +02:00
|
|
|
|
2021-03-15 13:29:34 +02:00
|
|
|
if node.GetHasStagedChanges() && node.GetHasUnstagedChanges() {
|
2020-09-28 01:14:32 +02:00
|
|
|
menuItems = append(menuItems, &menuItem{
|
2020-10-04 02:00:48 +02:00
|
|
|
displayString: gui.Tr.LcDiscardUnstagedChanges,
|
2020-09-28 01:14:32 +02:00
|
|
|
onPress: func() error {
|
2021-04-11 11:35:42 +02:00
|
|
|
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardUnstagedChangesInDirectory).DiscardUnstagedDirChanges(node); err != nil {
|
2020-09-28 01:14:32 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
|
|
|
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
2020-09-28 01:14:32 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2021-03-15 13:29:34 +02:00
|
|
|
} else {
|
|
|
|
file := node.File
|
|
|
|
|
|
|
|
submodules := gui.State.Submodules
|
|
|
|
if file.IsSubmodule(submodules) {
|
|
|
|
submodule := file.SubmoduleConfig(submodules)
|
|
|
|
|
|
|
|
menuItems = []*menuItem{
|
|
|
|
{
|
|
|
|
displayString: gui.Tr.LcSubmoduleStashAndReset,
|
|
|
|
onPress: func() error {
|
|
|
|
return gui.handleResetSubmodule(submodule)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
menuItems = []*menuItem{
|
|
|
|
{
|
|
|
|
displayString: gui.Tr.LcDiscardAllChanges,
|
|
|
|
onPress: func() error {
|
2021-04-11 11:35:42 +02:00
|
|
|
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardAllChangesInFile).DiscardAllFileChanges(file); err != nil {
|
2021-03-15 13:29:34 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
2021-03-15 13:29:34 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-02-14 13:07:56 +02:00
|
|
|
|
2021-03-15 13:29:34 +02:00
|
|
|
if file.HasStagedChanges && file.HasUnstagedChanges {
|
|
|
|
menuItems = append(menuItems, &menuItem{
|
|
|
|
displayString: gui.Tr.LcDiscardUnstagedChanges,
|
|
|
|
onPress: func() error {
|
2021-04-11 11:35:42 +02:00
|
|
|
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardAllUnstagedChangesInFile).DiscardUnstagedFileChanges(file); err != nil {
|
2021-03-15 13:29:34 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
|
|
|
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
2021-03-15 13:29:34 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 13:07:56 +02:00
|
|
|
}
|
|
|
|
|
2021-03-15 13:29:34 +02:00
|
|
|
return gui.createMenu(node.GetPath(), menuItems, createMenuOptions{showCancel: true})
|
2020-02-14 13:07:56 +02:00
|
|
|
}
|