Skip to content

Commit 21927a7

Browse files
committed
Adds progress indicator to stash quickpicks
1 parent a5616e6 commit 21927a7

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [Unreleased]
8+
### Added
9+
- Adds progress indicator to the `Show Stashed Changes` command (`gitlens.showQuickStashList`)
10+
- Adds progress indicator to the `Apply Stashed Changes` command (`gitlens.stashApply`)
11+
712
## [6.3.0] - 2017-11-30
813
### Added
914
- Adds support for files with staged changes
@@ -21,7 +26,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
2126
- Fixes [#217](https://github.com/eamodio/vscode-gitlens/issues/217) - empty editor has git lens in status bar with old information
2227
- Fixes [#218](https://github.com/eamodio/vscode-gitlens/issues/218) - Cannot read property 'replace' of undefined
2328
- Fixes issue with feedback when searching for commits without any matches
24-
- Fixes issue where quickpick progress indicators could get stuck
29+
- Fixes issue where quick pick menu progress indicators could get stuck
2530

2631
## [6.2.0] - 2017-11-27
2732
### Added

src/commands/showQuickStashList.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand {
2424
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickStashListCommandArgs = {}) {
2525
uri = getCommandUri(uri, editor);
2626

27+
const progressCancellation = StashListQuickPick.showProgress('list');
28+
2729
try {
2830
const repoPath = await this.git.getRepoPath(uri);
2931
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show stashed changes`);
3032

3133
const stash = await this.git.getStashList(repoPath);
3234
if (stash === undefined) return window.showWarningMessage(`Unable to show stashed changes`);
3335

36+
if (progressCancellation.token.isCancellationRequested) return undefined;
37+
3438
// Create a command to get back to here
3539
const currentCommand = new CommandQuickPickItem({
3640
label: `go back ${GlyphChars.ArrowBack}`,
@@ -42,7 +46,7 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand {
4246
} as ShowQuickStashListCommandArgs
4347
]);
4448

45-
const pick = await StashListQuickPick.show(this.git, stash, 'list', args.goBackCommand, currentCommand);
49+
const pick = await StashListQuickPick.show(this.git, stash, 'list', progressCancellation, args.goBackCommand, currentCommand);
4650
if (pick === undefined) return undefined;
4751

4852
if (pick instanceof CommandQuickPickItem) return pick.execute();
@@ -59,5 +63,8 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand {
5963
Logger.error(ex, 'ShowQuickStashListCommand');
6064
return window.showErrorMessage(`Unable to show stashed changes. See output channel for more details`);
6165
}
66+
finally {
67+
progressCancellation.dispose();
68+
}
6269
}
6370
}

src/commands/stashApply.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class StashApplyCommand extends Command {
3535

3636
async execute(args: StashApplyCommandArgs = { confirm: true, deleteAfter: false }) {
3737
args = { ...args };
38+
3839
if (args.stashItem === undefined || args.stashItem.stashName === undefined) {
3940
let goBackToRepositoriesCommand: CommandQuickPickItem | undefined;
4041

@@ -52,20 +53,29 @@ export class StashApplyCommand extends Command {
5253
repoPath = pick.repoPath;
5354
}
5455

55-
const stash = await this.git.getStashList(repoPath);
56-
if (stash === undefined) return window.showInformationMessage(`There are no stashed changes`);
56+
const progressCancellation = StashListQuickPick.showProgress('apply');
5757

58-
const currentCommand = new CommandQuickPickItem({
59-
label: `go back ${GlyphChars.ArrowBack}`,
60-
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to apply stashed changes`
61-
}, Commands.StashApply, [args]);
58+
try {
59+
const stash = await this.git.getStashList(repoPath);
60+
if (stash === undefined) return window.showInformationMessage(`There are no stashed changes`);
6261

63-
const pick = await StashListQuickPick.show(this.git, stash, 'apply', goBackToRepositoriesCommand || args.goBackCommand, currentCommand);
64-
if (pick instanceof CommandQuickPickItem) return pick.execute();
65-
if (pick === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
62+
if (progressCancellation.token.isCancellationRequested) return undefined;
6663

67-
args.goBackCommand = currentCommand;
68-
args.stashItem = pick.commit as GitStashCommit;
64+
const currentCommand = new CommandQuickPickItem({
65+
label: `go back ${GlyphChars.ArrowBack}`,
66+
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to apply stashed changes`
67+
}, Commands.StashApply, [args]);
68+
69+
const pick = await StashListQuickPick.show(this.git, stash, 'apply', progressCancellation, goBackToRepositoriesCommand || args.goBackCommand, currentCommand);
70+
if (pick instanceof CommandQuickPickItem) return pick.execute();
71+
if (pick === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
72+
73+
args.goBackCommand = currentCommand;
74+
args.stashItem = pick.commit as GitStashCommit;
75+
}
76+
finally {
77+
progressCancellation.dispose();
78+
}
6979
}
7080

7181
try {

src/quickPicks/stashList.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
'use strict';
22
import { Iterables, Strings } from '../system';
3-
import { QuickPickOptions, window } from 'vscode';
3+
import { CancellationTokenSource, QuickPickOptions, window } from 'vscode';
44
import { Commands, StashSaveCommandArgs } from '../commands';
55
import { GlyphChars } from '../constants';
66
import { GitService, GitStash } from '../gitService';
7-
import { Keyboard } from '../keyboard';
8-
import { CommandQuickPickItem, CommitQuickPickItem, getQuickPickIgnoreFocusOut } from '../quickPicks';
7+
import { Keyboard, KeyNoopCommand } from '../keyboard';
8+
import { CommandQuickPickItem, CommitQuickPickItem, getQuickPickIgnoreFocusOut, showQuickPickProgress } from '../quickPicks';
99

1010
export class StashListQuickPick {
1111

12-
static async show(git: GitService, stash: GitStash, mode: 'list' | 'apply', goBackCommand?: CommandQuickPickItem, currentCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
12+
static showProgress(mode: 'list' | 'apply') {
13+
const message = mode === 'apply'
14+
? `Apply stashed changes to your working tree${GlyphChars.Ellipsis}`
15+
: `stashed changes ${GlyphChars.Dash} search by message, filename, or commit id`;
16+
return showQuickPickProgress(message,
17+
{
18+
left: KeyNoopCommand,
19+
',': KeyNoopCommand,
20+
'.': KeyNoopCommand
21+
});
22+
}
23+
24+
static async show(git: GitService, stash: GitStash, mode: 'list' | 'apply', progressCancellation: CancellationTokenSource, goBackCommand?: CommandQuickPickItem, currentCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
1325
const items = ((stash && Array.from(Iterables.map(stash.commits.values(), c => new CommitQuickPickItem(c)))) || []) as (CommitQuickPickItem | CommandQuickPickItem)[];
1426

1527
if (mode === 'list') {
@@ -27,8 +39,12 @@ export class StashListQuickPick {
2739
items.splice(0, 0, goBackCommand);
2840
}
2941

42+
if (progressCancellation.token.isCancellationRequested) return undefined;
43+
3044
const scope = await Keyboard.instance.beginScope({ left: goBackCommand });
3145

46+
progressCancellation.cancel();
47+
3248
const pick = await window.showQuickPick(items, {
3349
matchOnDescription: true,
3450
placeHolder: mode === 'apply'

0 commit comments

Comments
 (0)