mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-13 13:59:06 +02:00
refactor git flow menu
This commit is contained in:
parent
d76e8887e5
commit
fd4f37b5c3
@ -8,11 +8,6 @@ import (
|
|||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
)
|
)
|
||||||
|
|
||||||
type gitFlowOption struct {
|
|
||||||
handler func() error
|
|
||||||
description string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) gitFlowFinishBranch(gitFlowConfig string, branchName string) error {
|
func (gui *Gui) gitFlowFinishBranch(gitFlowConfig string, branchName string) error {
|
||||||
// need to find out what kind of branch this is
|
// need to find out what kind of branch this is
|
||||||
prefix := strings.SplitAfterN(branchName, "/", 2)[0]
|
prefix := strings.SplitAfterN(branchName, "/", 2)[0]
|
||||||
@ -41,11 +36,6 @@ func (gui *Gui) gitFlowFinishBranch(gitFlowConfig string, branchName string) err
|
|||||||
return gui.Errors.ErrSubProcess
|
return gui.Errors.ErrSubProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDisplayStrings is a function.
|
|
||||||
func (r *gitFlowOption) GetDisplayStrings(isFocused bool) []string {
|
|
||||||
return []string{r.description}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleCreateGitFlowMenu(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleCreateGitFlowMenu(g *gocui.Gui, v *gocui.View) error {
|
||||||
branch := gui.getSelectedBranch()
|
branch := gui.getSelectedBranch()
|
||||||
if branch == nil {
|
if branch == nil {
|
||||||
@ -70,37 +60,27 @@ func (gui *Gui) handleCreateGitFlowMenu(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
options := []*gitFlowOption{
|
menuItems := []*menuItem{
|
||||||
{
|
{
|
||||||
// not localising here because it's one to one with the actual git flow commands
|
// not localising here because it's one to one with the actual git flow commands
|
||||||
description: fmt.Sprintf("finish branch '%s'", branch.Name),
|
displayString: fmt.Sprintf("finish branch '%s'", branch.Name),
|
||||||
handler: func() error {
|
onPress: func() error {
|
||||||
return gui.gitFlowFinishBranch(gitFlowConfig, branch.Name)
|
return gui.gitFlowFinishBranch(gitFlowConfig, branch.Name)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "start feature",
|
displayString: "start feature",
|
||||||
handler: startHandler("feature"),
|
onPress: startHandler("feature"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "start hotfix",
|
displayString: "start hotfix",
|
||||||
handler: startHandler("hotfix"),
|
onPress: startHandler("hotfix"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "start release",
|
displayString: "start release",
|
||||||
handler: startHandler("release"),
|
onPress: startHandler("release"),
|
||||||
},
|
|
||||||
{
|
|
||||||
description: gui.Tr.SLocalize("cancel"),
|
|
||||||
handler: func() error {
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMenuPress := func(index int) error {
|
return gui.createMenuNew("git flow", menuItems, createMenuOptions{})
|
||||||
return options[index].handler()
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.createMenu("git flow", options, len(options), handleMenuPress)
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user