From 94601b4dc951de9b1efa08120148d2d9766b637c Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 23 Aug 2020 12:20:49 +1000 Subject: use context to return to the correct view --- pkg/gui/branches_panel.go | 56 +++++++++++++++++----------------------- pkg/gui/cherry_picking.go | 6 ++--- pkg/gui/commit_files_panel.go | 18 +++++-------- pkg/gui/commits_panel.go | 42 ++++++++++-------------------- pkg/gui/confirmation_panel.go | 33 +++++++++-------------- pkg/gui/diffing.go | 2 +- pkg/gui/files_panel.go | 36 ++++++++++---------------- pkg/gui/filtering.go | 6 ++--- pkg/gui/filtering_menu_panel.go | 2 +- pkg/gui/git_flow.go | 2 +- pkg/gui/gui.go | 16 +++++------- pkg/gui/merge_panel.go | 6 ++--- pkg/gui/patch_options_panel.go | 6 ++--- pkg/gui/quitting.go | 6 ++--- pkg/gui/rebase_options_panel.go | 6 ++--- pkg/gui/reflog_panel.go | 6 ++--- pkg/gui/remote_branches_panel.go | 12 +++------ pkg/gui/remotes_panel.go | 16 +++++------- pkg/gui/staging_panel.go | 6 ++--- pkg/gui/stash_panel.go | 20 +++++--------- pkg/gui/sub_commits_panel.go | 6 ++--- pkg/gui/tags_panel.go | 10 +++---- pkg/gui/undoing.go | 6 ++--- pkg/gui/updates.go | 15 ++++------- 24 files changed, 124 insertions(+), 216 deletions(-) diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index d79e72b49..36c8ab112 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -115,10 +115,8 @@ func (gui *Gui) handleForceCheckout(g *gocui.Gui, v *gocui.View) error { title := gui.Tr.SLocalize("ForceCheckoutBranch") return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: title, - prompt: message, + title: title, + prompt: message, handleConfirm: func() error { if err := gui.GitCommand.Checkout(branch.Name, commands.CheckoutOptions{Force: true}); err != nil { _ = gui.surfaceError(err) @@ -160,10 +158,9 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions) if strings.Contains(err.Error(), "Please commit your changes or stash them before you switch branch") { // offer to autostash changes return gui.ask(askOpts{ - returnToView: gui.getBranchesView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("AutoStashTitle"), - prompt: gui.Tr.SLocalize("AutoStashPrompt"), + + title: gui.Tr.SLocalize("AutoStashTitle"), + prompt: gui.Tr.SLocalize("AutoStashPrompt"), handleConfirm: func() error { if err := gui.GitCommand.StashSave(gui.Tr.SLocalize("StashPrefix") + ref); err != nil { return gui.surfaceError(err) @@ -195,15 +192,14 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions) } func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error { - return gui.prompt(v, gui.Tr.SLocalize("BranchName")+":", "", func(response string) error { + return gui.prompt(gui.Tr.SLocalize("BranchName")+":", "", func(response string) error { return gui.handleCheckoutRef(response, handleCheckoutRefOptions{ onRefNotFound: func(ref string) error { return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("BranchNotFoundTitle"), - prompt: fmt.Sprintf("%s %s%s", gui.Tr.SLocalize("BranchNotFoundPrompt"), ref, "?"), + + title: gui.Tr.SLocalize("BranchNotFoundTitle"), + prompt: fmt.Sprintf("%s %s%s", gui.Tr.SLocalize("BranchNotFoundPrompt"), ref, "?"), handleConfirm: func() error { return gui.createNewBranchWithName(ref) }, @@ -266,10 +262,9 @@ func (gui *Gui) deleteNamedBranch(selectedBranch *commands.Branch, force bool) e ) return gui.ask(askOpts{ - returnToView: gui.getBranchesView(), - returnFocusOnClose: true, - title: title, - prompt: message, + + title: title, + prompt: message, handleConfirm: func() error { if err := gui.GitCommand.DeleteBranch(selectedBranch.Name, force); err != nil { errMessage := err.Error() @@ -304,10 +299,9 @@ func (gui *Gui) mergeBranchIntoCheckedOutBranch(branchName string) error { ) return gui.ask(askOpts{ - returnToView: gui.getBranchesView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("MergingTitle"), - prompt: prompt, + + title: gui.Tr.SLocalize("MergingTitle"), + prompt: prompt, handleConfirm: func() error { err := gui.GitCommand.Merge(branchName, commands.MergeOpts{}) return gui.handleGenericMergeCommandResult(err) @@ -347,10 +341,9 @@ func (gui *Gui) handleRebaseOntoBranch(selectedBranchName string) error { ) return gui.ask(askOpts{ - returnToView: gui.getBranchesView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("RebasingTitle"), - prompt: prompt, + + title: gui.Tr.SLocalize("RebasingTitle"), + prompt: prompt, handleConfirm: func() error { err := gui.GitCommand.RebaseBranch(selectedBranchName) return gui.handleGenericMergeCommandResult(err) @@ -422,7 +415,7 @@ 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(v, gui.Tr.SLocalize("NewBranchNamePrompt")+" "+branch.Name+":", "", func(newBranchName string) error { + return gui.prompt(gui.Tr.SLocalize("NewBranchNamePrompt")+" "+branch.Name+":", "", func(newBranchName string) error { if err := gui.GitCommand.RenameBranch(branch.Name, newBranchName); err != nil { return gui.surfaceError(err) } @@ -445,11 +438,10 @@ func (gui *Gui) handleRenameBranch(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("renameBranch"), - prompt: gui.Tr.SLocalize("RenameBranchWarning"), - handleConfirm: promptForNewName, + + title: gui.Tr.SLocalize("renameBranch"), + prompt: gui.Tr.SLocalize("RenameBranchWarning"), + handleConfirm: promptForNewName, }) } @@ -475,7 +467,7 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error { }, ) - return gui.prompt(gui.getCurrentSideView(), message, "", func(response string) error { + return gui.prompt(message, "", func(response string) error { if err := gui.GitCommand.NewBranch(response, item.ID()); err != nil { return err } diff --git a/pkg/gui/cherry_picking.go b/pkg/gui/cherry_picking.go index 1165a43a1..04e7517b7 100644 --- a/pkg/gui/cherry_picking.go +++ b/pkg/gui/cherry_picking.go @@ -146,10 +146,8 @@ func (gui *Gui) HandlePasteCommits() error { } return gui.ask(askOpts{ - returnToView: gui.getCommitsView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("CherryPick"), - prompt: gui.Tr.SLocalize("SureCherryPick"), + title: gui.Tr.SLocalize("CherryPick"), + prompt: gui.Tr.SLocalize("SureCherryPick"), handleConfirm: func() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("CherryPickingStatus"), func() error { err := gui.GitCommand.CherryPickCommits(gui.State.Modes.CherryPicking.CherryPickedCommits) diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 65ac9a936..505beda0e 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -59,10 +59,8 @@ func (gui *Gui) handleDiscardOldFileChange(g *gocui.Gui, v *gocui.View) error { fileName := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLineIdx].Name return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("DiscardFileChangesTitle"), - prompt: gui.Tr.SLocalize("DiscardFileChangesPrompt"), + title: gui.Tr.SLocalize("DiscardFileChangesTitle"), + prompt: gui.Tr.SLocalize("DiscardFileChangesPrompt"), handleConfirm: func() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error { if err := gui.GitCommand.DiscardOldFileChanges(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, fileName); err != nil { @@ -139,10 +137,8 @@ func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error { if gui.GitCommand.PatchManager.Active() && gui.GitCommand.PatchManager.To != commitFile.Parent { return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("DiscardPatch"), - prompt: gui.Tr.SLocalize("DiscardPatchConfirm"), + title: gui.Tr.SLocalize("DiscardPatch"), + prompt: gui.Tr.SLocalize("DiscardPatchConfirm"), handleConfirm: func() error { gui.GitCommand.PatchManager.Reset() return toggleTheFile() @@ -189,10 +185,8 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error { if gui.GitCommand.PatchManager.Active() && gui.GitCommand.PatchManager.To != commitFile.Parent { return gui.ask(askOpts{ - returnToView: gui.getCommitFilesView(), - returnFocusOnClose: false, - title: gui.Tr.SLocalize("DiscardPatch"), - prompt: gui.Tr.SLocalize("DiscardPatchConfirm"), + title: gui.Tr.SLocalize("DiscardPatch"), + prompt: gui.Tr.SLocalize("DiscardPatchConfirm"), handleConfirm: func() error { gui.GitCommand.PatchManager.Reset() return enterTheFile(selectedLineIdx) diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 007f3f447..200fea7af 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -135,10 +135,8 @@ func (gui *Gui) handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("Squash"), - prompt: gui.Tr.SLocalize("SureSquashThisCommit"), + title: gui.Tr.SLocalize("Squash"), + prompt: gui.Tr.SLocalize("SureSquashThisCommit"), handleConfirm: func() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("SquashingStatus"), func() error { err := gui.GitCommand.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "squash") @@ -166,10 +164,8 @@ func (gui *Gui) handleCommitFixup(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("Fixup"), - prompt: gui.Tr.SLocalize("SureFixupThisCommit"), + title: gui.Tr.SLocalize("Fixup"), + prompt: gui.Tr.SLocalize("SureFixupThisCommit"), handleConfirm: func() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("FixingStatus"), func() error { err := gui.GitCommand.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "fixup") @@ -206,7 +202,7 @@ func (gui *Gui) handleRenameCommit(g *gocui.Gui, v *gocui.View) error { return gui.surfaceError(err) } - return gui.prompt(v, gui.Tr.SLocalize("renameCommit"), message, func(response string) error { + return gui.prompt(gui.Tr.SLocalize("renameCommit"), message, func(response string) error { if err := gui.GitCommand.RenameCommit(response); err != nil { return gui.surfaceError(err) } @@ -279,10 +275,8 @@ func (gui *Gui) handleCommitDelete(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("DeleteCommitTitle"), - prompt: gui.Tr.SLocalize("DeleteCommitPrompt"), + title: gui.Tr.SLocalize("DeleteCommitTitle"), + prompt: gui.Tr.SLocalize("DeleteCommitPrompt"), handleConfirm: func() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("DeletingStatus"), func() error { err := gui.GitCommand.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "drop") @@ -371,10 +365,8 @@ func (gui *Gui) handleCommitAmendTo(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("AmendCommitTitle"), - prompt: gui.Tr.SLocalize("AmendCommitPrompt"), + title: gui.Tr.SLocalize("AmendCommitTitle"), + prompt: gui.Tr.SLocalize("AmendCommitPrompt"), handleConfirm: func() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("AmendingStatus"), func() error { err := gui.GitCommand.AmendTo(gui.State.Commits[gui.State.Panels.Commits.SelectedLineIdx].Sha) @@ -447,9 +439,7 @@ func (gui *Gui) handleCreateFixupCommit(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("CreateFixupCommit"), + title: gui.Tr.SLocalize("CreateFixupCommit"), prompt: gui.Tr.TemplateLocalize( "SureCreateFixupCommit", Teml{ @@ -477,9 +467,7 @@ func (gui *Gui) handleSquashAllAboveFixupCommits(g *gocui.Gui, v *gocui.View) er } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("SquashAboveCommits"), + title: gui.Tr.SLocalize("SquashAboveCommits"), prompt: gui.Tr.TemplateLocalize( "SureSquashAboveCommits", Teml{ @@ -508,7 +496,7 @@ func (gui *Gui) handleTagCommit(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleCreateLightweightTag(commitSha string) error { - return gui.prompt(gui.getCommitsView(), gui.Tr.SLocalize("TagNameTitle"), "", func(response string) error { + return gui.prompt(gui.Tr.SLocalize("TagNameTitle"), "", func(response string) error { if err := gui.GitCommand.CreateLightweightTag(response, commitSha); err != nil { return gui.surfaceError(err) } @@ -523,10 +511,8 @@ func (gui *Gui) handleCheckoutCommit(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: gui.getCommitsView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("checkoutCommit"), - prompt: gui.Tr.SLocalize("SureCheckoutThisCommit"), + title: gui.Tr.SLocalize("checkoutCommit"), + prompt: gui.Tr.SLocalize("SureCheckoutThisCommit"), handleConfirm: func() error { return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{}) }, diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index b74d45e3f..e9103b42a 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -16,7 +16,6 @@ import ( ) type createPopupPanelOpts struct { - returnToView *gocui.View hasLoader bool returnFocusOnClose bool editable bool @@ -28,7 +27,6 @@ type createPopupPanelOpts struct { } type askOpts struct { - returnToView *gocui.View returnFocusOnClose bool title string prompt string @@ -38,30 +36,25 @@ type askOpts struct { func (gui *Gui) createLoaderPanel(currentView *gocui.View, prompt string) error { return gui.createPopupPanel(createPopupPanelOpts{ - returnToView: currentView, - prompt: prompt, - hasLoader: true, - returnFocusOnClose: true, + prompt: prompt, + hasLoader: true, }) } func (gui *Gui) ask(opts askOpts) error { return gui.createPopupPanel(createPopupPanelOpts{ - returnToView: opts.returnToView, - title: opts.title, - prompt: opts.prompt, - returnFocusOnClose: opts.returnFocusOnClose, - handleConfirm: opts.handleConfirm, - handleClose: opts.handleClose, + title: opts.title, + prompt: opts.prompt, + + handleConfirm: opts.handleConfirm, + handleClose: opts.handleClose, }) } -func (gui *Gui) prompt(currentView *gocui.View, title string, initialContent string, handleConfirm func(string) error) error { +func (gui *Gui) prompt(title string, initialContent string, handleConfirm func(string) error) error { return gui.createPopupPanel(createPopupPanelOpts{ - returnToView: currentView, title: title, prompt: initialContent, - returnFocusOnClose: true, editable: true, handleConfirmPrompt: handleConfirm, }) @@ -146,7 +139,7 @@ func (gui *Gui) getConfirmationPanelDimensions(wrap bool, prompt string) (int, i height/2 + panelHeight/2 } -func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt string, hasLoader bool) (*gocui.View, error) { +func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader 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 { @@ -175,7 +168,7 @@ func (gui *Gui) createPopupPanel(opts createPopupPanelOpts) error { gui.Log.Error(err) } } - confirmationView, err := gui.prepareConfirmationPanel(opts.returnToView, opts.title, opts.prompt, opts.hasLoader) + confirmationView, err := gui.prepareConfirmationPanel(opts.title, opts.prompt, opts.hasLoader) if err != nil { return err } @@ -232,10 +225,8 @@ func (gui *Gui) createErrorPanel(message string) error { } return gui.ask(askOpts{ - returnToView: gui.g.CurrentView(), - title: gui.Tr.SLocalize("Error"), - prompt: coloredMessage, - returnFocusOnClose: true, + title: gui.Tr.SLocalize("Error"), + prompt: coloredMessage, }) } diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go index c3cc40fa0..ef7919273 100644 --- a/pkg/gui/diffing.go +++ b/pkg/gui/diffing.go @@ -127,7 +127,7 @@ func (gui *Gui) handleCreateDiffingMenuPanel(g *gocui.Gui, v *gocui.View) error { displayString: gui.Tr.SLocalize("enterRefToDiff"), onPress: func() error { - return gui.prompt(v, gui.Tr.SLocalize("enteRefName"), "", func(response string) error { + return gui.prompt(gui.Tr.SLocalize("enteRefName"), "", 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 4f52cb86c..a8aa02436 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -232,10 +232,8 @@ func (gui *Gui) handleIgnoreFile(g *gocui.Gui, v *gocui.View) error { if file.Tracked { return gui.ask(askOpts{ - returnToView: gui.g.CurrentView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("IgnoreTracked"), - prompt: gui.Tr.SLocalize("IgnoreTrackedPrompt"), + title: gui.Tr.SLocalize("IgnoreTracked"), + prompt: gui.Tr.SLocalize("IgnoreTrackedPrompt"), handleConfirm: func() error { if err := gui.GitCommand.Ignore(file.Name); err != nil { return err @@ -304,10 +302,8 @@ func (gui *Gui) handleCommitPress() error { func (gui *Gui) promptToStageAllAndRetry(retry func() error) error { return gui.ask(askOpts{ - returnToView: gui.getFilesView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("NoFilesStagedTitle"), - prompt: gui.Tr.SLocalize("NoFilesStagedPrompt"), + title: gui.Tr.SLocalize("NoFilesStagedTitle"), + prompt: gui.Tr.SLocalize("NoFilesStagedPrompt"), handleConfirm: func() error { if err := gui.GitCommand.StageAll(); err != nil { return gui.surfaceError(err) @@ -333,10 +329,8 @@ func (gui *Gui) handleAmendCommitPress() error { } return gui.ask(askOpts{ - returnToView: gui.getFilesView(), - returnFocusOnClose: true, - title: strings.Title(gui.Tr.SLocalize("AmendLastCommit")), - prompt: gui.Tr.SLocalize("SureToAmend"), + title: strings.Title(gui.Tr.SLocalize("AmendLastCommit")), + prompt: gui.Tr.SLocalize("SureToAmend"), handleConfirm: func() error { ok, err := gui.runSyncOrAsyncCommand(gui.GitCommand.AmendHead()) if err != nil { @@ -443,7 +437,7 @@ func (gui *Gui) handlePullFiles(g *gocui.Gui, v *gocui.View) error { } } - return gui.prompt(v, gui.Tr.SLocalize("EnterUpstream"), "origin/"+currentBranch.Name, func(upstream string) error { + return gui.prompt(gui.Tr.SLocalize("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") { @@ -512,10 +506,8 @@ func (gui *Gui) pushWithForceFlag(v *gocui.View, force bool, upstream string, ar err := gui.GitCommand.Push(branchName, force, upstream, args, gui.promptUserForCredential) if err != nil && !force && strings.Contains(err.Error(), "Updates were rejected") { gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("ForcePush"), - prompt: gui.Tr.SLocalize("ForcePushPrompt"), + title: gui.Tr.SLocalize("ForcePush"), + prompt: gui.Tr.SLocalize("ForcePushPrompt"), handleConfirm: func() error { return gui.pushWithForceFlag(v, true, upstream, args) }, @@ -552,7 +544,7 @@ 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(v, gui.Tr.SLocalize("EnterUpstream"), "origin "+currentBranch.Name, func(response string) error { + return gui.prompt(gui.Tr.SLocalize("EnterUpstream"), "origin "+currentBranch.Name, func(response string) error { return gui.pushWithForceFlag(v, false, response, "") }) } @@ -561,10 +553,8 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("ForcePush"), - prompt: gui.Tr.SLocalize("ForcePushPrompt"), + title: gui.Tr.SLocalize("ForcePush"), + prompt: gui.Tr.SLocalize("ForcePushPrompt"), handleConfirm: func() error { return gui.pushWithForceFlag(v, true, "", "") }, @@ -601,7 +591,7 @@ func (gui *Gui) anyFilesWithMergeConflicts() bool { } func (gui *Gui) handleCustomCommand(g *gocui.Gui, v *gocui.View) error { - return gui.prompt(v, gui.Tr.SLocalize("CustomCommand"), "", func(command string) error { + return gui.prompt(gui.Tr.SLocalize("CustomCommand"), "", func(command string) error { gui.SubProcess = gui.OSCommand.RunCustomCommand(command) return gui.Errors.ErrSubProcess }) diff --git a/pkg/gui/filtering.go b/pkg/gui/filtering.go index 2faafe9f2..222e59d14 100644 --- a/pkg/gui/filtering.go +++ b/pkg/gui/filtering.go @@ -3,10 +3,8 @@ package gui func (gui *Gui) validateNotInFilterMode() (bool, error) { if gui.State.Modes.Filtering.Active() { err := gui.ask(askOpts{ - returnToView: gui.g.CurrentView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("MustExitFilterModeTitle"), - prompt: gui.Tr.SLocalize("MustExitFilterModePrompt"), + title: gui.Tr.SLocalize("MustExitFilterModeTitle"), + prompt: gui.Tr.SLocalize("MustExitFilterModePrompt"), handleConfirm: func() error { return gui.exitFilterMode() }, diff --git a/pkg/gui/filtering_menu_panel.go b/pkg/gui/filtering_menu_panel.go index b70fc80b2..8925e1395 100644 --- a/pkg/gui/filtering_menu_panel.go +++ b/pkg/gui/filtering_menu_panel.go @@ -41,7 +41,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel(g *gocui.Gui, v *gocui.View) erro menuItems = append(menuItems, &menuItem{ displayString: gui.Tr.SLocalize("filterPathOption"), onPress: func() error { - return gui.prompt(v, gui.Tr.SLocalize("enterFileName"), "", func(response string) error { + return gui.prompt(gui.Tr.SLocalize("enterFileName"), "", 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 367dd3048..dc6827499 100644 --- a/pkg/gui/git_flow.go +++ b/pkg/gui/git_flow.go @@ -51,7 +51,7 @@ func (gui *Gui) handleCreateGitFlowMenu(g *gocui.Gui, v *gocui.View) error { startHandler := func(branchType string) func() error { return func() error { title := gui.Tr.TemplateLocalize("NewBranchNamePrompt", map[string]interface{}{"branchType": branchType}) - return gui.prompt(gui.getMenuView(), title, "", func(name string) error { + return gui.prompt(title, "", 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/gui.go b/pkg/gui/gui.go index c4d0bdf25..88b146d7c 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -555,12 +555,10 @@ func (gui *Gui) showIntroPopupMessage(done chan struct{}) error { } return gui.ask(askOpts{ - returnToView: nil, - returnFocusOnClose: true, - title: "", - prompt: gui.Tr.SLocalize("IntroPopupMessage"), - handleConfirm: onConfirm, - handleClose: onConfirm, + title: "", + prompt: gui.Tr.SLocalize("IntroPopupMessage"), + handleConfirm: onConfirm, + handleClose: onConfirm, }) } @@ -588,10 +586,8 @@ func (gui *Gui) startBackgroundFetch() { err := gui.fetch(false) if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew { _ = gui.ask(askOpts{ - returnToView: gui.g.CurrentView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("NoAutomaticGitFetchTitle"), - prompt: gui.Tr.SLocalize("NoAutomaticGitFetchBody"), + title: gui.Tr.SLocalize("NoAutomaticGitFetchTitle"), + prompt: gui.Tr.SLocalize("NoAutomaticGitFetchBody"), }) } else { gui.goEvery(time.Second*60, gui.stopChan, func() error { diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go index da54b01ed..aa4dbe00d 100644 --- a/pkg/gui/merge_panel.go +++ b/pkg/gui/merge_panel.go @@ -341,10 +341,8 @@ func (gui *Gui) promptToContinue() error { gui.takeOverScrolling() return gui.ask(askOpts{ - returnToView: gui.getFilesView(), - returnFocusOnClose: true, - title: "continue", - prompt: gui.Tr.SLocalize("ConflictsResolved"), + title: "continue", + prompt: gui.Tr.SLocalize("ConflictsResolved"), handleConfirm: func() error { return gui.genericMergeCommand("continue") }, diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index d2e1ba072..419efca23 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -138,10 +138,8 @@ func (gui *Gui) handlePullPatchIntoWorkingTree() error { if len(gui.trackedFiles()) > 0 { return gui.ask(askOpts{ - returnToView: gui.g.CurrentView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("MustStashTitle"), - prompt: gui.Tr.SLocalize("MustStashWarning"), + title: gui.Tr.SLocalize("MustStashTitle"), + prompt: gui.Tr.SLocalize("MustStashWarning"), handleConfirm: func() error { return pull(true) }, diff --git a/pkg/gui/quitting.go b/pkg/gui/quitting.go index 297b4a474..fc24d2155 100644 --- a/pkg/gui/quitting.go +++ b/pkg/gui/quitting.go @@ -61,10 +61,8 @@ func (gui *Gui) quit() error { if gui.Config.GetUserConfig().GetBool("confirmOnQuit") { return gui.ask(askOpts{ - returnToView: gui.g.CurrentView(), - returnFocusOnClose: true, - title: "", - prompt: gui.Tr.SLocalize("ConfirmQuit"), + title: "", + prompt: gui.Tr.SLocalize("ConfirmQuit"), handleConfirm: func() error { return gocui.ErrQuit }, diff --git a/pkg/gui/rebase_options_panel.go b/pkg/gui/rebase_options_panel.go index 03422da24..656ef0bbc 100644 --- a/pkg/gui/rebase_options_panel.go +++ b/pkg/gui/rebase_options_panel.go @@ -77,10 +77,8 @@ func (gui *Gui) handleGenericMergeCommandResult(result error) error { return nil } else if strings.Contains(result.Error(), "When you have resolved this problem") || strings.Contains(result.Error(), "fix conflicts") || strings.Contains(result.Error(), "Resolve all conflicts manually") { return gui.ask(askOpts{ - returnToView: gui.getFilesView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("FoundConflictsTitle"), - prompt: gui.Tr.SLocalize("FoundConflicts"), + title: gui.Tr.SLocalize("FoundConflictsTitle"), + prompt: gui.Tr.SLocalize("FoundConflicts"), handleConfirm: func() error { return nil }, diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go index b588e713d..ed06b3bcc 100644 --- a/pkg/gui/reflog_panel.go +++ b/pkg/gui/reflog_panel.go @@ -90,10 +90,8 @@ func (gui *Gui) handleCheckoutReflogCommit(g *gocui.Gui, v *gocui.View) error { } err := gui.ask(askOpts{ - returnToView: gui.getCommitsView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("checkoutCommit"), - prompt: gui.Tr.SLocalize("SureCheckoutThisCommit"), + title: gui.Tr.SLocalize("checkoutCommit"), + prompt: gui.Tr.SLocalize("SureCheckoutThisCommit"), handleConfirm: func() error { return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{}) }, diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go index 29e199cfc..2e7cbf73c 100644 --- a/pkg/gui/remote_branches_panel.go +++ b/pkg/gui/remote_branches_panel.go @@ -66,10 +66,8 @@ func (gui *Gui) handleDeleteRemoteBranch(g *gocui.Gui, v *gocui.View) error { message := fmt.Sprintf("%s '%s'?", gui.Tr.SLocalize("DeleteRemoteBranchMessage"), remoteBranch.FullName()) return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("DeleteRemoteBranch"), - prompt: message, + title: gui.Tr.SLocalize("DeleteRemoteBranch"), + prompt: message, handleConfirm: func() error { return gui.WithWaitingStatus(gui.Tr.SLocalize("DeletingStatus"), func() error { if err := gui.GitCommand.DeleteRemoteBranch(remoteBranch.RemoteName, remoteBranch.Name); err != nil { @@ -100,10 +98,8 @@ func (gui *Gui) handleSetBranchUpstream(g *gocui.Gui, v *gocui.View) error { ) return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("SetUpstreamTitle"), - prompt: message, + title: gui.Tr.SLocalize("SetUpstreamTitle"), + prompt: message, handleConfirm: func() error { if err := gui.GitCommand.SetBranchUpstream(selectedBranch.RemoteName, selectedBranch.Name, checkedOutBranch.Name); err != nil { return err diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index 3f11ec47a..137a7545e 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -80,9 +80,8 @@ func (gui *Gui) handleRemoteEnter() error { } func (gui *Gui) handleAddRemote(g *gocui.Gui, v *gocui.View) error { - branchesView := gui.getBranchesView() - return gui.prompt(branchesView, gui.Tr.SLocalize("newRemoteName"), "", func(remoteName string) error { - return gui.prompt(branchesView, gui.Tr.SLocalize("newRemoteUrl"), "", func(remoteUrl string) error { + return gui.prompt(gui.Tr.SLocalize("newRemoteName"), "", func(remoteName string) error { + return gui.prompt(gui.Tr.SLocalize("newRemoteUrl"), "", func(remoteUrl string) error { if err := gui.GitCommand.AddRemote(remoteName, remoteUrl); err != nil { return err } @@ -98,10 +97,8 @@ func (gui *Gui) handleRemoveRemote(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("removeRemote"), - prompt: gui.Tr.SLocalize("removeRemotePrompt") + " '" + remote.Name + "'?", + title: gui.Tr.SLocalize("removeRemote"), + prompt: gui.Tr.SLocalize("removeRemotePrompt") + " '" + remote.Name + "'?", handleConfirm: func() error { if err := gui.GitCommand.RemoveRemote(remote.Name); err != nil { return err @@ -113,7 +110,6 @@ func (gui *Gui) handleRemoveRemote(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleEditRemote(g *gocui.Gui, v *gocui.View) error { - branchesView := gui.getBranchesView() remote := gui.getSelectedRemote() if remote == nil { return nil @@ -126,7 +122,7 @@ func (gui *Gui) handleEditRemote(g *gocui.Gui, v *gocui.View) error { }, ) - return gui.prompt(branchesView, editNameMessage, "", func(updatedRemoteName string) error { + return gui.prompt(editNameMessage, "", func(updatedRemoteName string) error { if updatedRemoteName != remote.Name { if err := gui.GitCommand.RenameRemote(remote.Name, updatedRemoteName); err != nil { return gui.surfaceError(err) @@ -140,7 +136,7 @@ func (gui *Gui) handleEditRemote(g *gocui.Gui, v *gocui.View) error { }, ) - return gui.prompt(branchesView, editUrlMessage, "", func(updatedRemoteUrl string) error { + return gui.prompt(editUrlMessage, "", func(updatedRemoteUrl string) error { if err := gui.GitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil { return gui.surfaceError(err) } diff --git a/pkg/gui/staging_panel.go b/pkg/gui/staging_panel.go index 97bd84fbb..a9b351ba8 100644 --- a/pkg/gui/staging_panel.go +++ b/pkg/gui/staging_panel.go @@ -105,10 +105,8 @@ func (gui *Gui) handleResetSelection(g *gocui.Gui, v *gocui.View) error { if !gui.Config.GetUserConfig().GetBool("gui.skipUnstageLineWarning") { return gui.ask(askOpts{ - returnToView: gui.getMainView(), - returnFocusOnClose: false, - title: gui.Tr.SLocalize("UnstageLinesTitle"), - prompt: gui.Tr.SLocalize("UnstageLinesPrompt"), + title: gui.Tr.SLocalize("UnstageLinesTitle"), + prompt: gui.Tr.SLocalize("UnstageLinesPrompt"), handleConfirm: func() error { return gui.applySelection(true) }, diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go index 1ee2ab26e..71f246417 100644 --- a/pkg/gui/stash_panel.go +++ b/pkg/gui/stash_panel.go @@ -56,10 +56,8 @@ func (gui *Gui) handleStashApply(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("StashApply"), - prompt: gui.Tr.SLocalize("SureApplyStashEntry"), + title: gui.Tr.SLocalize("StashApply"), + prompt: gui.Tr.SLocalize("SureApplyStashEntry"), handleConfirm: func() error { return apply() }, @@ -78,10 +76,8 @@ func (gui *Gui) handleStashPop(g *gocui.Gui, v *gocui.View) error { } return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("StashPop"), - prompt: gui.Tr.SLocalize("SurePopStashEntry"), + title: gui.Tr.SLocalize("StashPop"), + prompt: gui.Tr.SLocalize("SurePopStashEntry"), handleConfirm: func() error { return pop() }, @@ -90,10 +86,8 @@ func (gui *Gui) handleStashPop(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleStashDrop(g *gocui.Gui, v *gocui.View) error { return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("StashDrop"), - prompt: gui.Tr.SLocalize("SureDropStashEntry"), + title: gui.Tr.SLocalize("StashDrop"), + prompt: gui.Tr.SLocalize("SureDropStashEntry"), handleConfirm: func() error { return gui.stashDo("drop") }, @@ -121,7 +115,7 @@ func (gui *Gui) handleStashSave(stashFunc func(message string) error) error { if len(gui.trackedFiles()) == 0 && len(gui.stagedFiles()) == 0 { return gui.createErrorPanel(gui.Tr.SLocalize("NoTrackedStagedFilesStash")) } - return gui.prompt(gui.getFilesView(), gui.Tr.SLocalize("StashChanges"), "", func(stashComment string) error { + return gui.prompt(gui.Tr.SLocalize("StashChanges"), "", func(stashComment string) error { if err := stashFunc(stashComment); err != nil { return gui.surfaceError(err) } diff --git a/pkg/gui/sub_commits_panel.go b/pkg/gui/sub_commits_panel.go index 1c2762faf..571df1820 100644 --- a/pkg/gui/sub_commits_panel.go +++ b/pkg/gui/sub_commits_panel.go @@ -45,10 +45,8 @@ func (gui *Gui) handleCheckoutSubCommit(g *gocui.Gui, v *gocui.View) error { } err := gui.ask(askOpts{ - returnToView: gui.getCommitsView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("checkoutCommit"), - prompt: gui.Tr.SLocalize("SureCheckoutThisCommit"), + title: gui.Tr.SLocalize("checkoutCommit"), + prompt: gui.Tr.SLocalize("SureCheckoutThisCommit"), handleConfirm: func() error { return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{}) }, diff --git a/pkg/gui/tags_panel.go b/pkg/gui/tags_panel.go index 8811e400e..6782ef012 100644 --- a/pkg/gui/tags_panel.go +++ b/pkg/gui/tags_panel.go @@ -72,10 +72,8 @@ func (gui *Gui) handleDeleteTag(g *gocui.Gui, v *gocui.View) error { ) return gui.ask(askOpts{ - returnToView: v, - returnFocusOnClose: true, - title: gui.Tr.SLocalize("DeleteTagTitle"), - prompt: prompt, + title: gui.Tr.SLocalize("DeleteTagTitle"), + prompt: prompt, handleConfirm: func() error { if err := gui.GitCommand.DeleteTag(tag.Name); err != nil { return gui.surfaceError(err) @@ -98,7 +96,7 @@ func (gui *Gui) handlePushTag(g *gocui.Gui, v *gocui.View) error { }, ) - return gui.prompt(v, title, "origin", func(response string) error { + return gui.prompt(title, "origin", func(response string) error { if err := gui.GitCommand.PushTag(response, tag.Name); err != nil { return gui.surfaceError(err) } @@ -107,7 +105,7 @@ func (gui *Gui) handlePushTag(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleCreateTag(g *gocui.Gui, v *gocui.View) error { - return gui.prompt(v, gui.Tr.SLocalize("CreateTagTitle"), "", func(tagName string) error { + return gui.prompt(gui.Tr.SLocalize("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) diff --git a/pkg/gui/undoing.go b/pkg/gui/undoing.go index 886eb49e3..2224c2b1f 100644 --- a/pkg/gui/undoing.go +++ b/pkg/gui/undoing.go @@ -167,10 +167,8 @@ func (gui *Gui) handleHardResetWithAutoStash(commitSha string, options handleHar if dirtyWorkingTree { // offer to autostash changes return gui.ask(askOpts{ - returnToView: gui.getBranchesView(), - returnFocusOnClose: true, - title: gui.Tr.SLocalize("AutoStashTitle"), - prompt: gui.Tr.SLocalize("AutoStashPrompt"), + title: gui.Tr.SLocalize("AutoStashTitle"), + prompt: gui.Tr.SLocalize("AutoStashPrompt"), handleConfirm: func() error { return gui.WithWaitingStatus(options.WaitingStatus, func() error { if err := gui.GitCommand.StashSave(gui.Tr.SLocalize("StashPrefix") + commitSha); err != nil { diff --git a/pkg/gui/updates.go b/pkg/gui/updates.go index 759287b82..b121e537d 100644 --- a/pkg/gui/updates.go +++ b/pkg/gui/updates.go @@ -2,14 +2,11 @@ package gui import "github.com/jesseduffield/gocui" -func (gui *Gui) showUpdatePrompt(newVersion string) error { - currentView := gui.g.CurrentView() +func (gui *Gui) showUpdatePrompt(newVersion string) error { return gui.ask(askOpts{ - returnToView: currentView, - returnFocusOnClose: true, - title: "New version available!", - prompt: "Download latest version? (enter/esc)", + title: "New version available!", + prompt: "Download latest version? (enter/esc)", handleConfirm: func() error { gui.startUpdating(newVersion) return nil @@ -61,10 +58,8 @@ func (gui *Gui) onUpdateFinish(err error) error { func (gui *Gui) createUpdateQuitConfirmation() error { return gui.ask(askOpts{ - returnToView: gui.g.CurrentView(), - returnFocusOnClose: true, - title: "Currently Updating", - prompt: "An update is in progress. Are you sure you want to quit?", + title: "Currently Updating", + prompt: "An update is in progress. Are you sure you want to quit?", handleConfirm: func() error { return gocui.ErrQuit }, -- cgit v1.2.3