diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 523ecd0c2..00d0c5875 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -207,20 +207,24 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions) } func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error { - return gui.prompt(gui.Tr.BranchName+":", "", func(response string) error { - return gui.handleCheckoutRef(response, handleCheckoutRefOptions{ - onRefNotFound: func(ref string) error { + return gui.prompt(promptOpts{ + title: gui.Tr.BranchName + ":", + showSuggestions: true, + handleConfirm: func(response string) error { + return gui.handleCheckoutRef(response, handleCheckoutRefOptions{ + onRefNotFound: func(ref string) error { - return gui.ask(askOpts{ - title: gui.Tr.BranchNotFoundTitle, - prompt: fmt.Sprintf("%s %s%s", gui.Tr.BranchNotFoundPrompt, ref, "?"), - handleConfirm: func() error { - return gui.createNewBranchWithName(ref) - }, - }) - }, - }) - }) + return gui.ask(askOpts{ + title: gui.Tr.BranchNotFoundTitle, + prompt: fmt.Sprintf("%s %s%s", gui.Tr.BranchNotFoundPrompt, ref, "?"), + handleConfirm: func() error { + return gui.createNewBranchWithName(ref) + }, + }) + }, + }) + }}, + ) } func (gui *Gui) getCheckedOutBranch() *models.Branch { @@ -427,17 +431,20 @@ func (gui *Gui) handleRenameBranch(g *gocui.Gui, v *gocui.View) error { // way to get it to show up in the reflog) promptForNewName := func() error { - return gui.prompt(gui.Tr.NewBranchNamePrompt+" "+branch.Name+":", "", func(newBranchName string) error { - if err := gui.GitCommand.RenameBranch(branch.Name, newBranchName); err != nil { - return gui.surfaceError(err) - } - // need to checkout so that the branch shows up in our reflog and therefore - // doesn't get lost among all the other branches when we switch to something else - if err := gui.GitCommand.Checkout(newBranchName, commands.CheckoutOptions{Force: false}); err != nil { - return gui.surfaceError(err) - } + return gui.prompt(promptOpts{ + title: gui.Tr.NewBranchNamePrompt + " " + branch.Name + ":", + handleConfirm: func(newBranchName string) error { + if err := gui.GitCommand.RenameBranch(branch.Name, newBranchName); err != nil { + return gui.surfaceError(err) + } + // need to checkout so that the branch shows up in our reflog and therefore + // doesn't get lost among all the other branches when we switch to something else + if err := gui.GitCommand.Checkout(newBranchName, commands.CheckoutOptions{Force: false}); err != nil { + return gui.surfaceError(err) + } - return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + }, }) } @@ -483,25 +490,30 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error { // will set to the remote's existing name prefilledName = item.ID() } - return gui.prompt(message, prefilledName, func(response string) error { - if err := gui.GitCommand.NewBranch(response, item.ID()); err != nil { - return err - } - // if we're currently in the branch commits context then the selected commit - // is about to go to the top of the list - if context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY { - context.GetPanelState().SetSelectedLineIdx(0) - } - - if context.GetKey() != gui.Contexts.Branches.Context.GetKey() { - if err := gui.pushContext(gui.Contexts.Branches.Context); err != nil { + return gui.prompt(promptOpts{ + title: message, + initialContent: prefilledName, + handleConfirm: func(response string) error { + if err := gui.GitCommand.NewBranch(response, item.ID()); err != nil { return err } - } - gui.State.Panels.Branches.SelectedLineIdx = 0 + // if we're currently in the branch commits context then the selected commit + // is about to go to the top of the list + if context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY { + context.GetPanelState().SetSelectedLineIdx(0) + } - return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + if context.GetKey() != gui.Contexts.Branches.Context.GetKey() { + if err := gui.pushContext(gui.Contexts.Branches.Context); err != nil { + return err + } + } + + gui.State.Panels.Branches.SelectedLineIdx = 0 + + return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + }, }) } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 5e0c18bfd..6be372f2e 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -233,12 +233,16 @@ func (gui *Gui) handleRenameCommit(g *gocui.Gui, v *gocui.View) error { return gui.surfaceError(err) } - return gui.prompt(gui.Tr.LcRenameCommit, message, func(response string) error { - if err := gui.GitCommand.RenameCommit(response); err != nil { - return gui.surfaceError(err) - } + return gui.prompt(promptOpts{ + title: gui.Tr.LcRenameCommit, + initialContent: message, + handleConfirm: func(response string) error { + if err := gui.GitCommand.RenameCommit(response); err != nil { + return gui.surfaceError(err) + } - return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + }, }) } @@ -517,11 +521,14 @@ func (gui *Gui) handleTagCommit(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleCreateLightweightTag(commitSha string) error { - return gui.prompt(gui.Tr.TagNameTitle, "", func(response string) error { - if err := gui.GitCommand.CreateLightweightTag(response, commitSha); err != nil { - return gui.surfaceError(err) - } - return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{COMMITS, TAGS}}) + return gui.prompt(promptOpts{ + title: gui.Tr.TagNameTitle, + handleConfirm: func(response string) error { + if err := gui.GitCommand.CreateLightweightTag(response, commitSha); err != nil { + return gui.surfaceError(err) + } + return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{COMMITS, TAGS}}) + }, }) } diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index dfea11c05..0446fb919 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -28,16 +28,44 @@ type createPopupPanelOpts struct { // when handlersManageFocus is true, do not return from the confirmation context automatically. It's expected that the handlers will manage focus, whether that means switching to another context, or manually returning the context. handlersManageFocus bool - showSuggestionsPanel bool + showSuggestions bool } type askOpts struct { - title string - prompt string - handleConfirm func() error - handleClose func() error - handlersManageFocus bool - showSuggestionsPanel bool + title string + prompt string + handleConfirm func() error + handleClose func() error + handlersManageFocus bool + showSuggestions bool +} + +type promptOpts struct { + title string + initialContent string + handleConfirm func(string) error + showSuggestions bool +} + +func (gui *Gui) ask(opts askOpts) error { + return gui.createPopupPanel(createPopupPanelOpts{ + title: opts.title, + prompt: opts.prompt, + handleConfirm: opts.handleConfirm, + handleClose: opts.handleClose, + handlersManageFocus: opts.handlersManageFocus, + showSuggestions: opts.showSuggestions, + }) +} + +func (gui *Gui) prompt(opts promptOpts) error { + return gui.createPopupPanel(createPopupPanelOpts{ + title: opts.title, + prompt: opts.initialContent, + editable: true, + handleConfirmPrompt: opts.handleConfirm, + showSuggestions: opts.showSuggestions, + }) } func (gui *Gui) createLoaderPanel(prompt string) error { @@ -47,27 +75,6 @@ func (gui *Gui) createLoaderPanel(prompt string) error { }) } -func (gui *Gui) ask(opts askOpts) error { - return gui.createPopupPanel(createPopupPanelOpts{ - title: opts.title, - prompt: opts.prompt, - handleConfirm: opts.handleConfirm, - handleClose: opts.handleClose, - handlersManageFocus: opts.handlersManageFocus, - showSuggestionsPanel: opts.showSuggestionsPanel, - }) -} - -func (gui *Gui) prompt(title string, initialContent string, handleConfirm func(string) error) error { - return gui.createPopupPanel(createPopupPanelOpts{ - title: title, - prompt: initialContent, - editable: true, - handleConfirmPrompt: handleConfirm, - showSuggestionsPanel: true, - }) -} - func (gui *Gui) wrappedConfirmationFunction(handlersManageFocus bool, function func() error) func(*gocui.Gui, *gocui.View) error { return func(g *gocui.Gui, v *gocui.View) error { if function != nil { @@ -173,7 +180,7 @@ func (gui *Gui) getConfirmationPanelDimensions(wrap bool, prompt string) (int, i height/2 + panelHeight/2 } -func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, showSuggestionsPanel bool) (*gocui.View, error) { +func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, showSuggestions bool) (*gocui.View, error) { x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(true, prompt) confirmationView, err := gui.g.SetView("confirmation", x0, y0, x1, y1, 0) if err != nil { @@ -189,7 +196,7 @@ func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, s confirmationView.FgColor = theme.GocuiDefaultTextColor } - if showSuggestionsPanel { + if showSuggestions { suggestionsViewHeight := 11 suggestionsView, err := gui.g.SetView("suggestions", x0, y1, x1, y1+suggestionsViewHeight, 0) if err != nil { @@ -215,7 +222,7 @@ func (gui *Gui) createPopupPanel(opts createPopupPanelOpts) error { if view, _ := g.View("confirmation"); view != nil { gui.deleteConfirmationView() } - confirmationView, err := gui.prepareConfirmationPanel(opts.title, opts.prompt, opts.hasLoader, opts.showSuggestionsPanel) + confirmationView, err := gui.prepareConfirmationPanel(opts.title, opts.prompt, opts.hasLoader, opts.showSuggestions) if err != nil { return err } diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index 0d5179006..6b86b07fd 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -98,15 +98,15 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand return gui.surfaceError(err) } - return gui.prompt( - title, - initialValue, - func(str string) error { + return gui.prompt(promptOpts{ + title: title, + initialContent: initialValue, + handleConfirm: func(str string) error { promptResponses[idx] = str return wrappedF() }, - ) + }) } case "menu": f = func() error { diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go index 4a1d92a8d..408ae436f 100644 --- a/pkg/gui/diffing.go +++ b/pkg/gui/diffing.go @@ -128,9 +128,12 @@ func (gui *Gui) handleCreateDiffingMenuPanel(g *gocui.Gui, v *gocui.View) error { displayString: gui.Tr.LcEnterRefToDiff, onPress: func() error { - return gui.prompt(gui.Tr.LcEnteRefName, "", func(response string) error { - gui.State.Modes.Diffing.Ref = strings.TrimSpace(response) - return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + return gui.prompt(promptOpts{ + title: gui.Tr.LcEnteRefName, + handleConfirm: func(response string) error { + gui.State.Modes.Diffing.Ref = strings.TrimSpace(response) + return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + }, }) }, }, diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 665a403cf..52bd6c346 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -496,15 +496,19 @@ func (gui *Gui) handlePullFiles(g *gocui.Gui, v *gocui.View) error { } } - return gui.prompt(gui.Tr.EnterUpstream, "origin/"+currentBranch.Name, func(upstream string) error { - if err := gui.GitCommand.SetUpstreamBranch(upstream); err != nil { - errorMessage := err.Error() - if strings.Contains(errorMessage, "does not exist") { - errorMessage = fmt.Sprintf("upstream branch %s not found.\nIf you expect it to exist, you should fetch (with 'f').\nOtherwise, you should push (with 'shift+P')", upstream) + return gui.prompt(promptOpts{ + title: gui.Tr.EnterUpstream, + initialContent: "origin/" + currentBranch.Name, + handleConfirm: func(upstream string) error { + if err := gui.GitCommand.SetUpstreamBranch(upstream); err != nil { + errorMessage := err.Error() + if strings.Contains(errorMessage, "does not exist") { + errorMessage = fmt.Sprintf("upstream branch %s not found.\nIf you expect it to exist, you should fetch (with 'f').\nOtherwise, you should push (with 'shift+P')", upstream) + } + return gui.createErrorPanel(errorMessage) } - return gui.createErrorPanel(errorMessage) - } - return gui.pullFiles(PullFilesOptions{}) + return gui.pullFiles(PullFilesOptions{}) + }, }) } @@ -610,8 +614,12 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error { if gui.GitCommand.PushToCurrent { return gui.pushWithForceFlag(v, false, "", "--set-upstream") } else { - return gui.prompt(gui.Tr.EnterUpstream, "origin "+currentBranch.Name, func(response string) error { - return gui.pushWithForceFlag(v, false, response, "") + return gui.prompt(promptOpts{ + title: gui.Tr.EnterUpstream, + initialContent: "origin " + currentBranch.Name, + handleConfirm: func(response string) error { + return gui.pushWithForceFlag(v, false, response, "") + }, }) } } else if currentBranch.Pullables == "0" { @@ -662,9 +670,12 @@ func (gui *Gui) anyFilesWithMergeConflicts() bool { } func (gui *Gui) handleCustomCommand(g *gocui.Gui, v *gocui.View) error { - return gui.prompt(gui.Tr.CustomCommand, "", func(command string) error { - gui.SubProcess = gui.OSCommand.RunCustomCommand(command) - return gui.Errors.ErrSubProcess + return gui.prompt(promptOpts{ + title: gui.Tr.CustomCommand, + handleConfirm: func(command string) error { + gui.SubProcess = gui.OSCommand.RunCustomCommand(command) + return gui.Errors.ErrSubProcess + }, }) } diff --git a/pkg/gui/filtering_menu_panel.go b/pkg/gui/filtering_menu_panel.go index f79f0ca46..d6872f7e4 100644 --- a/pkg/gui/filtering_menu_panel.go +++ b/pkg/gui/filtering_menu_panel.go @@ -41,9 +41,12 @@ func (gui *Gui) handleCreateFilteringMenuPanel(g *gocui.Gui, v *gocui.View) erro menuItems = append(menuItems, &menuItem{ displayString: gui.Tr.LcFilterPathOption, onPress: func() error { - return gui.prompt(gui.Tr.LcEnterFileName, "", func(response string) error { - gui.State.Modes.Filtering.Path = strings.TrimSpace(response) - return gui.Errors.ErrRestart + return gui.prompt(promptOpts{ + title: gui.Tr.LcEnterFileName, + handleConfirm: func(response string) error { + gui.State.Modes.Filtering.Path = strings.TrimSpace(response) + return gui.Errors.ErrRestart + }, }) }, }) diff --git a/pkg/gui/git_flow.go b/pkg/gui/git_flow.go index 1b207b04e..2aac6e3bb 100644 --- a/pkg/gui/git_flow.go +++ b/pkg/gui/git_flow.go @@ -52,10 +52,14 @@ func (gui *Gui) handleCreateGitFlowMenu(g *gocui.Gui, v *gocui.View) error { startHandler := func(branchType string) func() error { return func() error { title := utils.ResolvePlaceholderString(gui.Tr.NewGitFlowBranchPrompt, map[string]string{"branchType": branchType}) - return gui.prompt(title, "", func(name string) error { - subProcess := gui.OSCommand.PrepareSubProcess("git", "flow", branchType, "start", name) - gui.SubProcess = subProcess - return gui.Errors.ErrSubProcess + + return gui.prompt(promptOpts{ + title: title, + handleConfirm: func(name string) error { + subProcess := gui.OSCommand.PrepareSubProcess("git", "flow", branchType, "start", name) + gui.SubProcess = subProcess + return gui.Errors.ErrSubProcess + }, }) } } diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index 3987bea1b..2426c817a 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -85,14 +85,21 @@ func (gui *Gui) handleRemoteEnter() error { } func (gui *Gui) handleAddRemote(g *gocui.Gui, v *gocui.View) error { - return gui.prompt(gui.Tr.LcNewRemoteName, "", func(remoteName string) error { - return gui.prompt(gui.Tr.LcNewRemoteUrl, "", func(remoteUrl string) error { - if err := gui.GitCommand.AddRemote(remoteName, remoteUrl); err != nil { - return err - } - return gui.refreshSidePanels(refreshOptions{scope: []int{REMOTES}}) - }) + return gui.prompt(promptOpts{ + title: gui.Tr.LcNewRemoteName, + handleConfirm: func(remoteName string) error { + return gui.prompt(promptOpts{ + title: gui.Tr.LcNewRemoteUrl, + handleConfirm: func(remoteUrl string) error { + if err := gui.GitCommand.AddRemote(remoteName, remoteUrl); err != nil { + return err + } + return gui.refreshSidePanels(refreshOptions{scope: []int{REMOTES}}) + }, + }) + }, }) + } func (gui *Gui) handleRemoveRemote(g *gocui.Gui, v *gocui.View) error { @@ -127,32 +134,40 @@ func (gui *Gui) handleEditRemote(g *gocui.Gui, v *gocui.View) error { }, ) - return gui.prompt(editNameMessage, remote.Name, func(updatedRemoteName string) error { - if updatedRemoteName != remote.Name { - if err := gui.GitCommand.RenameRemote(remote.Name, updatedRemoteName); err != nil { - return gui.surfaceError(err) + return gui.prompt(promptOpts{ + title: editNameMessage, + initialContent: remote.Name, + handleConfirm: func(updatedRemoteName string) error { + if updatedRemoteName != remote.Name { + if err := gui.GitCommand.RenameRemote(remote.Name, updatedRemoteName); err != nil { + return gui.surfaceError(err) + } } - } - editUrlMessage := utils.ResolvePlaceholderString( - gui.Tr.LcEditRemoteUrl, - map[string]string{ - "remoteName": updatedRemoteName, - }, - ) + editUrlMessage := utils.ResolvePlaceholderString( + gui.Tr.LcEditRemoteUrl, + map[string]string{ + "remoteName": updatedRemoteName, + }, + ) - urls := remote.Urls - url := "" - if len(urls) > 0 { - url = urls[0] - } - - return gui.prompt(editUrlMessage, url, func(updatedRemoteUrl string) error { - if err := gui.GitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil { - return gui.surfaceError(err) + urls := remote.Urls + url := "" + if len(urls) > 0 { + url = urls[0] } - return gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, REMOTES}}) - }) + + return gui.prompt(promptOpts{ + title: editUrlMessage, + initialContent: url, + handleConfirm: func(updatedRemoteUrl string) error { + if err := gui.GitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil { + return gui.surfaceError(err) + } + return gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, REMOTES}}) + }, + }) + }, }) } diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go index d03a85c06..cac542d0e 100644 --- a/pkg/gui/stash_panel.go +++ b/pkg/gui/stash_panel.go @@ -117,11 +117,15 @@ func (gui *Gui) handleStashSave(stashFunc func(message string) error) error { if len(gui.trackedFiles()) == 0 && len(gui.stagedFiles()) == 0 { return gui.createErrorPanel(gui.Tr.NoTrackedStagedFilesStash) } - return gui.prompt(gui.Tr.StashChanges, "", func(stashComment string) error { - if err := stashFunc(stashComment); err != nil { - return gui.surfaceError(err) - } - return gui.refreshSidePanels(refreshOptions{scope: []int{STASH, FILES}}) + + return gui.prompt(promptOpts{ + title: gui.Tr.StashChanges, + handleConfirm: func(stashComment string) error { + if err := stashFunc(stashComment); err != nil { + return gui.surfaceError(err) + } + return gui.refreshSidePanels(refreshOptions{scope: []int{STASH, FILES}}) + }, }) } diff --git a/pkg/gui/submodules_panel.go b/pkg/gui/submodules_panel.go index 666e1afee..470a20e11 100644 --- a/pkg/gui/submodules_panel.go +++ b/pkg/gui/submodules_panel.go @@ -126,30 +126,47 @@ func (gui *Gui) resetSubmodule(submodule *models.SubmoduleConfig) error { } func (gui *Gui) handleAddSubmodule() error { - return gui.prompt(gui.Tr.LcNewSubmoduleUrl, "", func(submoduleUrl string) error { - nameSuggestion := filepath.Base(strings.TrimSuffix(submoduleUrl, filepath.Ext(submoduleUrl))) + return gui.prompt(promptOpts{ + title: gui.Tr.LcNewSubmoduleUrl, + handleConfirm: func(submoduleUrl string) error { + nameSuggestion := filepath.Base(strings.TrimSuffix(submoduleUrl, filepath.Ext(submoduleUrl))) - return gui.prompt(gui.Tr.LcNewSubmoduleName, nameSuggestion, func(submoduleName string) error { - return gui.prompt(gui.Tr.LcNewSubmodulePath, submoduleName, func(submodulePath string) error { - return gui.WithWaitingStatus(gui.Tr.LcAddingSubmoduleStatus, func() error { - err := gui.GitCommand.SubmoduleAdd(submoduleName, submodulePath, submoduleUrl) - gui.handleCredentialsPopup(err) + return gui.prompt(promptOpts{ + title: gui.Tr.LcNewSubmoduleName, + initialContent: nameSuggestion, + handleConfirm: func(submoduleName string) error { - return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}}) - }) + return gui.prompt(promptOpts{ + title: gui.Tr.LcNewSubmodulePath, + initialContent: submoduleName, + handleConfirm: func(submodulePath string) error { + return gui.WithWaitingStatus(gui.Tr.LcAddingSubmoduleStatus, func() error { + err := gui.GitCommand.SubmoduleAdd(submoduleName, submodulePath, submoduleUrl) + gui.handleCredentialsPopup(err) + + return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}}) + }) + }, + }) + }, }) - }) + }, }) + } func (gui *Gui) handleEditSubmoduleUrl(submodule *models.SubmoduleConfig) error { - return gui.prompt(fmt.Sprintf(gui.Tr.LcUpdateSubmoduleUrl, submodule.Name), submodule.Url, func(newUrl string) error { - return gui.WithWaitingStatus(gui.Tr.LcUpdatingSubmoduleUrlStatus, func() error { - err := gui.GitCommand.SubmoduleUpdateUrl(submodule.Name, submodule.Path, newUrl) - gui.handleCredentialsPopup(err) + return gui.prompt(promptOpts{ + title: fmt.Sprintf(gui.Tr.LcUpdateSubmoduleUrl, submodule.Name), + initialContent: submodule.Url, + handleConfirm: func(newUrl string) error { + return gui.WithWaitingStatus(gui.Tr.LcUpdatingSubmoduleUrlStatus, func() error { + err := gui.GitCommand.SubmoduleUpdateUrl(submodule.Name, submodule.Path, newUrl) + gui.handleCredentialsPopup(err) - return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}}) - }) + return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}}) + }) + }, }) } diff --git a/pkg/gui/tags_panel.go b/pkg/gui/tags_panel.go index 6a4ad3832..5425253f0 100644 --- a/pkg/gui/tags_panel.go +++ b/pkg/gui/tags_panel.go @@ -97,36 +97,43 @@ func (gui *Gui) handlePushTag(g *gocui.Gui, v *gocui.View) error { }, ) - return gui.prompt(title, "origin", func(response string) error { - return gui.WithWaitingStatus(gui.Tr.PushingTagStatus, func() error { - err := gui.GitCommand.PushTag(response, tag.Name, gui.promptUserForCredential) - gui.handleCredentialsPopup(err) + return gui.prompt(promptOpts{ + title: title, + initialContent: "origin", + handleConfirm: func(response string) error { + return gui.WithWaitingStatus(gui.Tr.PushingTagStatus, func() error { + err := gui.GitCommand.PushTag(response, tag.Name, gui.promptUserForCredential) + gui.handleCredentialsPopup(err) - return nil - }) + return nil + }) + }, }) } func (gui *Gui) handleCreateTag(g *gocui.Gui, v *gocui.View) error { - return gui.prompt(gui.Tr.CreateTagTitle, "", func(tagName string) error { - // leaving commit SHA blank so that we're just creating the tag for the current commit - if err := gui.GitCommand.CreateLightweightTag(tagName, ""); err != nil { - return gui.surfaceError(err) - } - return gui.refreshSidePanels(refreshOptions{scope: []int{COMMITS, TAGS}, then: func() { - // find the index of the tag and set that as the currently selected line - for i, tag := range gui.State.Tags { - if tag.Name == tagName { - gui.State.Panels.Tags.SelectedLineIdx = i - if err := gui.Contexts.Tags.Context.HandleRender(); err != nil { - gui.Log.Error(err) - } - - return - } + return gui.prompt(promptOpts{ + title: gui.Tr.CreateTagTitle, + handleConfirm: func(tagName string) error { + // leaving commit SHA blank so that we're just creating the tag for the current commit + if err := gui.GitCommand.CreateLightweightTag(tagName, ""); err != nil { + return gui.surfaceError(err) } + return gui.refreshSidePanels(refreshOptions{scope: []int{COMMITS, TAGS}, then: func() { + // find the index of the tag and set that as the currently selected line + for i, tag := range gui.State.Tags { + if tag.Name == tagName { + gui.State.Panels.Tags.SelectedLineIdx = i + if err := gui.Contexts.Tags.Context.HandleRender(); err != nil { + gui.Log.Error(err) + } + + return + } + } + }, + }) }, - }) }) }