diff --git a/src/commands/showQuickStashList.ts b/src/commands/showQuickStashList.ts index d8e5ddd..d0d2c22 100644 --- a/src/commands/showQuickStashList.ts +++ b/src/commands/showQuickStashList.ts @@ -21,18 +21,21 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand { if (!repoPath) return window.showWarningMessage(`Unable to show stashed changes`); const stash = await this.git.getStashList(repoPath); - const pick = await StashListQuickPick.show(this.git, stash, 'list', goBackCommand); + + // Create a command to get back to here + const currentCommand = new CommandQuickPickItem({ + label: `go back \u21A9`, + description: `\u00a0 \u2014 \u00a0\u00a0 to stashed changes` + }, Commands.ShowQuickStashList, [uri, goBackCommand]); + + const pick = await StashListQuickPick.show(this.git, stash, 'list', goBackCommand, currentCommand); if (!pick) return undefined; if (pick instanceof CommandQuickPickItem) { return pick.execute(); } - return commands.executeCommand(Commands.ShowQuickCommitDetails, new GitUri(pick.commit.uri, pick.commit), pick.commit.sha, pick.commit, - new CommandQuickPickItem({ - label: `go back \u21A9`, - description: `\u00a0 \u2014 \u00a0\u00a0 to stashed changes` - }, Commands.ShowQuickStashList, [uri, goBackCommand])); + return commands.executeCommand(Commands.ShowQuickCommitDetails, new GitUri(pick.commit.uri, pick.commit), pick.commit.sha, pick.commit, currentCommand); } catch (ex) { Logger.error(ex, 'ShowQuickStashListCommand'); diff --git a/src/commands/stashApply.ts b/src/commands/stashApply.ts index d5ff84d..64e77ef 100644 --- a/src/commands/stashApply.ts +++ b/src/commands/stashApply.ts @@ -4,6 +4,7 @@ import { GitService, GitStashCommit } from '../gitService'; import { Command, Commands } from './common'; import { CommitQuickPickItem, StashListQuickPick } from '../quickPicks'; import { Logger } from '../logger'; +import { CommandQuickPickItem } from '../quickPicks'; export class StashApplyCommand extends Command { @@ -11,7 +12,7 @@ export class StashApplyCommand extends Command { super(Commands.StashApply); } - async execute(stashItem: { stashName: string, message: string }, confirm: boolean = true, deleteAfter: boolean = false) { + async execute(stashItem: { stashName: string, message: string }, confirm: boolean = true, deleteAfter: boolean = false, goBackCommand?: CommandQuickPickItem) { if (!this.git.config.insiders) return undefined; if (!this.git.repoPath) return undefined; @@ -19,9 +20,15 @@ export class StashApplyCommand extends Command { const stash = await this.git.getStashList(this.git.repoPath); if (!stash) return window.showInformationMessage(`There are no stashed changes`); - const pick = await StashListQuickPick.show(this.git, stash, 'apply'); - if (!pick || !(pick instanceof CommitQuickPickItem)) return undefined; + const currentCommand = new CommandQuickPickItem({ + label: `go back \u21A9`, + description: `\u00a0 \u2014 \u00a0\u00a0 to apply stashed changes` + }, Commands.StashApply, [stashItem, confirm, deleteAfter, goBackCommand]); + const pick = await StashListQuickPick.show(this.git, stash, 'apply', goBackCommand, currentCommand); + if (!pick || !(pick instanceof CommitQuickPickItem)) return goBackCommand && goBackCommand.execute(); + + goBackCommand = currentCommand; stashItem = pick.commit as GitStashCommit; } @@ -29,7 +36,7 @@ export class StashApplyCommand extends Command { if (confirm) { const message = stashItem.message.length > 80 ? `${stashItem.message.substring(0, 80)}\u2026` : stashItem.message; const result = await window.showWarningMessage(`Apply stashed changes '${message}' to your working tree?`, { title: 'Yes, delete after applying' } as MessageItem, { title: 'Yes' } as MessageItem, { title: 'No', isCloseAffordance: true } as MessageItem); - if (!result || result.title === 'No') return undefined; + if (!result || result.title === 'No') return goBackCommand && goBackCommand.execute(); deleteAfter = result.title !== 'Yes'; } diff --git a/src/commands/stashDelete.ts b/src/commands/stashDelete.ts index 168e460..3245eb2 100644 --- a/src/commands/stashDelete.ts +++ b/src/commands/stashDelete.ts @@ -3,6 +3,7 @@ import { MessageItem, window } from 'vscode'; import { GitService } from '../gitService'; import { Command, Commands } from './common'; import { Logger } from '../logger'; +import { CommandQuickPickItem } from '../quickPicks'; export class StashDeleteCommand extends Command { @@ -10,7 +11,7 @@ export class StashDeleteCommand extends Command { super(Commands.StashDelete); } - async execute(stashItem: { stashName: string, message: string }, confirm: boolean = true) { + async execute(stashItem: { stashName: string, message: string }, confirm: boolean = true, goBackCommand?: CommandQuickPickItem) { if (!this.git.config.insiders) return undefined; if (!this.git.repoPath) return undefined; if (!stashItem || !stashItem.stashName) return undefined; @@ -19,7 +20,7 @@ export class StashDeleteCommand extends Command { if (confirm) { const message = stashItem.message.length > 80 ? `${stashItem.message.substring(0, 80)}\u2026` : stashItem.message; const result = await window.showWarningMessage(`Delete stashed changes '${message}'?`, { title: 'Yes' } as MessageItem, { title: 'No', isCloseAffordance: true } as MessageItem); - if (!result || result.title !== 'Yes') return undefined; + if (!result || result.title !== 'Yes') return goBackCommand && goBackCommand.execute(); } return await this.git.stashDelete(this.git.repoPath, stashItem.stashName); diff --git a/src/commands/stashSave.ts b/src/commands/stashSave.ts index cd596a0..1a2c725 100644 --- a/src/commands/stashSave.ts +++ b/src/commands/stashSave.ts @@ -3,6 +3,7 @@ import { InputBoxOptions, window } from 'vscode'; import { GitService } from '../gitService'; import { Command, Commands } from './common'; import { Logger } from '../logger'; +import { CommandQuickPickItem } from '../quickPicks'; export class StashSaveCommand extends Command { @@ -10,7 +11,7 @@ export class StashSaveCommand extends Command { super(Commands.StashSave); } - async execute(message?: string, unstagedOnly: boolean = false) { + async execute(message?: string, unstagedOnly: boolean = false, goBackCommand?: CommandQuickPickItem) { if (!this.git.config.insiders) return undefined; if (!this.git.repoPath) return undefined; @@ -20,7 +21,7 @@ export class StashSaveCommand extends Command { prompt: `Please provide a stash message`, placeHolder: `Stash message` } as InputBoxOptions); - if (message === undefined) return undefined; + if (message === undefined) return goBackCommand && goBackCommand.execute(); } return await this.git.stashSave(this.git.repoPath, message, unstagedOnly); diff --git a/src/quickPicks/commitDetails.ts b/src/quickPicks/commitDetails.ts index 36d9de0..d01da98 100644 --- a/src/quickPicks/commitDetails.ts +++ b/src/quickPicks/commitDetails.ts @@ -80,12 +80,12 @@ export class CommitDetailsQuickPick { items.splice(index++, 0, new CommandQuickPickItem({ label: `$(git-pull-request) Apply Stashed Changes`, description: `\u00a0 \u2014 \u00a0\u00a0 ${commit.message}` - }, Commands.StashApply, [commit as GitStashCommit, true, false])); + }, Commands.StashApply, [commit as GitStashCommit, true, false, currentCommand])); items.splice(index++, 0, new CommandQuickPickItem({ label: `$(x) Delete Stashed Changes`, description: `\u00a0 \u2014 \u00a0\u00a0 ${commit.message}` - }, Commands.StashDelete, [commit as GitStashCommit, true])); + }, Commands.StashDelete, [commit as GitStashCommit, true, currentCommand])); } if (!stash) { diff --git a/src/quickPicks/stashList.ts b/src/quickPicks/stashList.ts index 6558bb6..111d4e4 100644 --- a/src/quickPicks/stashList.ts +++ b/src/quickPicks/stashList.ts @@ -7,19 +7,19 @@ import { CommandQuickPickItem, CommitQuickPickItem, getQuickPickIgnoreFocusOut } export class StashListQuickPick { - static async show(git: GitService, stash: IGitStash, mode: 'list' | 'apply', goBackCommand?: CommandQuickPickItem): Promise { + static async show(git: GitService, stash: IGitStash, mode: 'list' | 'apply', goBackCommand?: CommandQuickPickItem, currentCommand?: CommandQuickPickItem): Promise { const items = ((stash && Array.from(Iterables.map(stash.commits.values(), c => new CommitQuickPickItem(c)))) || []) as (CommitQuickPickItem | CommandQuickPickItem)[]; if (mode === 'list' && git.config.insiders) { items.splice(0, 0, new CommandQuickPickItem({ label: `$(repo-push) Stash Unstaged Changes`, description: `\u00a0 \u2014 \u00a0\u00a0 stashes only unstaged changes` - }, Commands.StashSave, [undefined, true])); + }, Commands.StashSave, [undefined, true, currentCommand])); items.splice(0, 0, new CommandQuickPickItem({ label: `$(repo-push) Stash Changes`, description: `\u00a0 \u2014 \u00a0\u00a0 stashes all changes` - }, Commands.StashSave)); + }, Commands.StashSave, [undefined, undefined, currentCommand])); } if (goBackCommand) {