mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-15 01:34:26 +02:00
refactor patch options menu panel
This commit is contained in:
@ -21,33 +21,38 @@ func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error
|
|||||||
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoPatchError"))
|
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoPatchError"))
|
||||||
}
|
}
|
||||||
|
|
||||||
options := []*patchMenuOption{
|
menuItems := []*menuItem{
|
||||||
{displayName: fmt.Sprintf("remove patch from original commit (%s)", gui.GitCommand.PatchManager.CommitSha), function: gui.handleDeletePatchFromCommit},
|
{
|
||||||
{displayName: "pull patch out into index", function: gui.handlePullPatchIntoWorkingTree},
|
displayString: fmt.Sprintf("remove patch from original commit (%s)", gui.GitCommand.PatchManager.CommitSha),
|
||||||
{displayName: "reset patch", function: gui.handleResetPatch},
|
onPress: gui.handleDeletePatchFromCommit,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayString: "pull patch out into index",
|
||||||
|
onPress: gui.handlePullPatchIntoWorkingTree,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayString: "reset patch",
|
||||||
|
onPress: gui.handleResetPatch,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedCommit := gui.getSelectedCommit(gui.g)
|
selectedCommit := gui.getSelectedCommit(gui.g)
|
||||||
if selectedCommit != nil && gui.GitCommand.PatchManager.CommitSha != selectedCommit.Sha {
|
if selectedCommit != nil && gui.GitCommand.PatchManager.CommitSha != selectedCommit.Sha {
|
||||||
// adding this option to index 1
|
// adding this option to index 1
|
||||||
options = append(
|
menuItems = append(
|
||||||
options[:1],
|
menuItems[:1],
|
||||||
append(
|
append(
|
||||||
[]*patchMenuOption{
|
[]*menuItem{
|
||||||
{
|
{
|
||||||
displayName: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha),
|
displayString: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha),
|
||||||
function: gui.handleMovePatchToSelectedCommit,
|
onPress: gui.handleMovePatchToSelectedCommit,
|
||||||
},
|
},
|
||||||
}, options[1:]...,
|
}, menuItems[1:]...,
|
||||||
)...,
|
)...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMenuPress := func(index int) error {
|
return gui.createMenuNew(gui.Tr.SLocalize("PatchOptionsTitle"), menuItems, createMenuOptions{showCancel: true})
|
||||||
return options[index].function()
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.createMenu(gui.Tr.SLocalize("PatchOptionsTitle"), options, len(options), handleMenuPress)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) getPatchCommitIndex() int {
|
func (gui *Gui) getPatchCommitIndex() int {
|
||||||
|
Reference in New Issue
Block a user