diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts index 6777aa5fdc9f0..84307f80d99fb 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts @@ -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); diff --git a/src/vs/platform/quickinput/common/quickInput.ts b/src/vs/platform/quickinput/common/quickInput.ts index 350395c6eb0bf..ec9fde4de40f6 100644 --- a/src/vs/platform/quickinput/common/quickInput.ts +++ b/src/vs/platform/quickinput/common/quickInput.ts @@ -27,6 +27,8 @@ export interface IQuickInputService { focus(): void; + toggle(): void; + navigate(next: boolean): void; accept(): TPromise; diff --git a/src/vs/workbench/browser/parts/quickinput/quickInput.contribution.ts b/src/vs/workbench/browser/parts/quickinput/quickInput.contribution.ts new file mode 100644 index 0000000000000..05802208d23c9 --- /dev/null +++ b/src/vs/workbench/browser/parts/quickinput/quickInput.contribution.ts @@ -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(ActionExtensions.WorkbenchActions); + +registry.registerWorkbenchAction(new SyncActionDescriptor(QuickPickManyToggleAction, QuickPickManyToggleAction.ID, QuickPickManyToggleAction.LABEL, null, inQuickOpenContext), 'Toggle Selection in Quick Pick'); diff --git a/src/vs/workbench/browser/parts/quickinput/quickInput.ts b/src/vs/workbench/browser/parts/quickinput/quickInput.ts index 62f5fb4babbc1..5ba1cf56f1f10 100644 --- a/src/vs/workbench/browser/parts/quickinput/quickInput.ts +++ b/src/vs/workbench/browser/parts/quickinput/quickInput.ts @@ -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.$; @@ -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'); @@ -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 { + this.quickInputService.toggle(); + return TPromise.as(true); + } +} diff --git a/src/vs/workbench/workbench.main.ts b/src/vs/workbench/workbench.main.ts index 78ae4f9f1eade..47c9671501d72 100644 --- a/src/vs/workbench/workbench.main.ts +++ b/src/vs/workbench/workbench.main.ts @@ -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';