Skip to content

Commit

Permalink
Quick Pick tests (#49340)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed May 8, 2018
1 parent 50cf92c commit 18c9739
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
38 changes: 38 additions & 0 deletions extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,44 @@ suite('window namespace tests', () => {
});


test('showQuickPick, accept first', async function () {
const pick = window.showQuickPick(['eins', 'zwei', 'drei']);
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick, 'eins');
});

test('showQuickPick, accept second', async function () {
const resolves: ((value: string) => void)[] = [];
const first = new Promise(resolve => resolves.push(resolve));
const pick = window.showQuickPick(['eins', 'zwei', 'drei'], {
onDidSelectItem: item => resolves.shift()!(item as string)
});
assert.equal(await first, 'eins');
const second = new Promise(resolve => resolves.push(resolve));
await commands.executeCommand('workbench.action.quickOpenSelectNext');
assert.equal(await second, 'zwei');
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick, 'zwei');
});

test('showQuickPick, select first two', async function () {
const resolves: ((value: string) => void)[] = [];
const picks = window.showQuickPick(['eins', 'zwei', 'drei'], {
onDidSelectItem: item => resolves.shift()!(item as string),
canPickMany: true
});
const first = new Promise(resolve => resolves.push(resolve));
await commands.executeCommand('workbench.action.quickOpenSelectNext');
assert.equal(await first, 'eins');
await commands.executeCommand('workbench.action.quickPickManyToggle');
const second = new Promise(resolve => resolves.push(resolve));
await commands.executeCommand('workbench.action.quickOpenSelectNext');
assert.equal(await second, 'zwei');
await commands.executeCommand('workbench.action.quickPickManyToggle');
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.deepStrictEqual(await picks, ['eins', 'zwei']);
});

test('showQuickPick, undefined on cancel', function () {
const source = new CancellationTokenSource();
const p = window.showQuickPick(['eins', 'zwei', 'drei'], undefined, source.token);
Expand Down
2 changes: 2 additions & 0 deletions src/vs/platform/quickinput/common/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface IQuickInputService {

focus(): void;

toggle(): void;

navigate(next: boolean): void;

accept(): TPromise<void>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { Registry } from 'vs/platform/registry/common/platform';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { QuickPickManyToggleAction } from 'vs/workbench/browser/parts/quickinput/quickInput';
import { inQuickOpenContext } from 'vs/workbench/browser/parts/quickopen/quickopen';

const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);

registry.registerWorkbenchAction(new SyncActionDescriptor(QuickPickManyToggleAction, QuickPickManyToggleAction.ID, QuickPickManyToggleAction.LABEL, null, inQuickOpenContext), 'Toggle Selection in Quick Pick');
28 changes: 27 additions & 1 deletion src/vs/workbench/browser/parts/quickinput/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { onUnexpectedError, canceled } from 'vs/base/common/errors';
import Severity from 'vs/base/common/severity';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { Action } from 'vs/base/common/actions';

const $ = dom.$;

Expand Down Expand Up @@ -588,11 +589,17 @@ export class QuickInputService extends Component implements IQuickInputService {
}

focus() {
if (this.ui) {
if (this.isDisplayed()) {
this.ui.inputBox.setFocus();
}
}

toggle() {
if (this.isDisplayed() && this.controller instanceof PickManyController) {
this.ui.checkboxList.toggleCheckbox();
}
}

navigate(next: boolean) {
if (this.isDisplayed() && this.ui.checkboxList.isDisplayed()) {
this.ui.checkboxList.focus(next ? 'Next' : 'Previous');
Expand Down Expand Up @@ -649,3 +656,22 @@ export class QuickInputService extends Component implements IQuickInputService {
return this.container && this.container.style.display !== 'none';
}
}

export class QuickPickManyToggleAction extends Action {

public static readonly ID = 'workbench.action.quickPickManyToggle';
public static readonly LABEL = localize('quickPickManyToggle', "Toggle Selection in Quick Pick");

constructor(
id: string,
label: string,
@IQuickInputService private quickInputService: IQuickInputService
) {
super(id, label);
}

public run(event?: any): TPromise<any> {
this.quickInputService.toggle();
return TPromise.as(true);
}
}
1 change: 1 addition & 0 deletions src/vs/workbench/workbench.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import 'vs/workbench/parts/logs/electron-browser/logs.contribution';
import 'vs/workbench/browser/parts/quickopen/quickopen.contribution';
import 'vs/workbench/parts/quickopen/browser/quickopen.contribution';
import 'vs/workbench/browser/parts/editor/editorPicker';
import 'vs/workbench/browser/parts/quickinput/quickInput.contribution';

import 'vs/workbench/parts/files/electron-browser/explorerViewlet';
import 'vs/workbench/parts/files/electron-browser/fileActions.contribution';
Expand Down

0 comments on commit 18c9739

Please sign in to comment.