diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-14 23:35:01 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-15 08:47:36 +1100 |
commit | fd4f37b5c323a4cc303c521c59d63f973ba3047e (patch) | |
tree | 747a14fd412bea76f98b4405886df4da9130df00 /pkg/gui/git_flow.go | |
parent | d76e8887e506eace806b03d674e164aba2086123 (diff) |
refactor git flow menu
Diffstat (limited to 'pkg/gui/git_flow.go')
-rw-r--r-- | pkg/gui/git_flow.go | 40 |
1 files changed, 10 insertions, 30 deletions
diff --git a/pkg/gui/git_flow.go b/pkg/gui/git_flow.go index f132f564e..8876a064c 100644 --- a/pkg/gui/git_flow.go +++ b/pkg/gui/git_flow.go @@ -8,11 +8,6 @@ import ( "github.com/jesseduffield/gocui" ) -type gitFlowOption struct { - handler func() error - description string -} - func (gui *Gui) gitFlowFinishBranch(gitFlowConfig string, branchName string) error { // need to find out what kind of branch this is prefix := strings.SplitAfterN(branchName, "/", 2)[0] @@ -41,11 +36,6 @@ func (gui *Gui) gitFlowFinishBranch(gitFlowConfig string, branchName string) err 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 { branch := gui.getSelectedBranch() 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 - description: fmt.Sprintf("finish branch '%s'", branch.Name), - handler: func() error { + displayString: fmt.Sprintf("finish branch '%s'", branch.Name), + onPress: func() error { return gui.gitFlowFinishBranch(gitFlowConfig, branch.Name) }, }, { - description: "start feature", - handler: startHandler("feature"), + displayString: "start feature", + onPress: startHandler("feature"), }, { - description: "start hotfix", - handler: startHandler("hotfix"), + displayString: "start hotfix", + onPress: startHandler("hotfix"), }, { - description: "start release", - handler: startHandler("release"), + displayString: "start release", + onPress: startHandler("release"), }, - { - description: gui.Tr.SLocalize("cancel"), - handler: func() error { - return nil - }, - }, - } - - handleMenuPress := func(index int) error { - return options[index].handler() } - return gui.createMenu("git flow", options, len(options), handleMenuPress) + return gui.createMenuNew("git flow", menuItems, createMenuOptions{}) } |