Skip to content

Commit

Permalink
API update (#45589)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Mar 26, 2018
1 parent e3b9da4 commit e563e40
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/vs/platform/quickOpen/common/quickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface IPickOptions {
/**
* an optional flag to make this picker multi-select (honoured by extension API)
*/
multiSelect?: boolean;
canSelectMany?: boolean;
}

export interface IInputOptions {
Expand Down
52 changes: 32 additions & 20 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,14 @@ declare module 'vscode' {
* A human readable string which is rendered less prominent.
*/
detail?: string;

/**
* Optional flag indicating if this item is selected initially.
* (Only honored when the picker allows multiple selections.)
*
* @see [QuickPickOptions.canSelectMany](#QuickPickOptions.canSelectMany)
*/
selected?: boolean;
}

/**
Expand Down Expand Up @@ -1555,30 +1563,16 @@ declare module 'vscode' {
ignoreFocusOut?: boolean;

/**
* An optional flag to make the picker multi-select, if true the result is an array of picks.
* An optional flag to make the picker accept multiple selections, if true the result is an array of picks.
*/
multiSelect?: boolean;
canSelectMany?: boolean;

/**
* An optional function that is invoked whenever an item is selected.
*/
onDidSelectItem?(item: QuickPickItem | string): any;
}

/**
* Represents an item that can be selected in a multi-select quick pick UI.
*/
export interface MultiSelectQuickPickItem extends QuickPickItem {
selected?: boolean;
}

/**
* Options to configure the behavior of the multi-select quick pick UI. (Marker type.)
*/
export interface MultiSelectQuickPickOptions extends QuickPickOptions {
multiSelect: true;
}

/**
* Options to configure the behaviour of the [workspace folder](#WorkspaceFolder) pick UI.
*/
Expand Down Expand Up @@ -5080,26 +5074,44 @@ declare module 'vscode' {
*/
export function showErrorMessage<T extends MessageItem>(message: string, options: MessageOptions, ...items: T[]): Thenable<T | undefined>;

/**
* Shows a selection list allowing multiple selections.
*
* @param items An array of strings, or a promise that resolves to an array of strings.
* @param options Configures the behavior of the selection list.
* @param token A token that can be used to signal cancellation.
* @return A promise that resolves to the selected items or `undefined`.
*/
export function showQuickPick(items: string[] | Thenable<string[]>, options: QuickPickOptions & { canSelectMany: true; }, token?: CancellationToken): Thenable<string[] | undefined>;

/**
* Shows a selection list.
*
* @param items An array of strings, or a promise that resolves to an array of strings.
* @param options Configures the behavior of the selection list.
* @param token A token that can be used to signal cancellation.
* @return A promise that resolves to the selected item(s) or `undefined`.
* @return A promise that resolves to the selection or `undefined`.
*/
export function showQuickPick(items: string[] | Thenable<string[]>, options: MultiSelectQuickPickOptions, token?: CancellationToken): Thenable<string[] | undefined>;
export function showQuickPick(items: string[] | Thenable<string[]>, options?: QuickPickOptions, token?: CancellationToken): Thenable<string | undefined>;

/**
* Shows a selection list allowing multiple selections.
*
* @param items An array of items, or a promise that resolves to an array of items.
* @param options Configures the behavior of the selection list.
* @param token A token that can be used to signal cancellation.
* @return A promise that resolves to the selected items or `undefined`.
*/
export function showQuickPick<T extends QuickPickItem>(items: T[] | Thenable<T[]>, options: QuickPickOptions & { canSelectMany: true; }, token?: CancellationToken): Thenable<T[] | undefined>;

/**
* Shows a selection list.
*
* @param items An array of items, or a promise that resolves to an array of items.
* @param options Configures the behavior of the selection list.
* @param token A token that can be used to signal cancellation.
* @return A promise that resolves to the selected item(s) or `undefined`.
* @return A promise that resolves to the selected item or `undefined`.
*/
export function showQuickPick<T extends MultiSelectQuickPickItem>(items: T[] | Thenable<T[]>, options: MultiSelectQuickPickOptions, token?: CancellationToken): Thenable<T[] | undefined>;
export function showQuickPick<T extends QuickPickItem>(items: T[] | Thenable<T[]>, options?: QuickPickOptions, token?: CancellationToken): Thenable<T | undefined>;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class MainThreadQuickOpen implements MainThreadQuickOpenShape {
});

return asWinJsPromise<number | number[]>(token => {
if (options.multiSelect) {
if (options.canSelectMany) {
return this._quickInputService.pick(this._contents, options, token)
.then(items => {
if (items) {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/api/node/extHostQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { wireCancellationToken, asWinJsPromise } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { QuickPickOptions, QuickPickItem, InputBoxOptions, WorkspaceFolderPickOptions, WorkspaceFolder, MultiSelectQuickPickItem, MultiSelectQuickPickOptions } from 'vscode';
import { QuickPickOptions, QuickPickItem, InputBoxOptions, WorkspaceFolderPickOptions, WorkspaceFolder } from 'vscode';
import { MainContext, MainThreadQuickOpenShape, ExtHostQuickOpenShape, MyQuickPickItems, IMainContext } from './extHost.protocol';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
Expand All @@ -29,7 +29,7 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
this._commands = commands;
}

showQuickPick(itemsOrItemsPromise: MultiSelectQuickPickItem[] | Thenable<MultiSelectQuickPickItem[]>, options: MultiSelectQuickPickOptions, token?: CancellationToken): Thenable<MultiSelectQuickPickItem[] | undefined>;
showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Thenable<QuickPickItem[]>, options: QuickPickOptions & { canSelectMany: true; }, token?: CancellationToken): Thenable<QuickPickItem[] | undefined>;
showQuickPick(itemsOrItemsPromise: string[] | Thenable<string[]>, options?: QuickPickOptions, token?: CancellationToken): Thenable<string | undefined>;
showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Thenable<QuickPickItem[]>, options?: QuickPickOptions, token?: CancellationToken): Thenable<QuickPickItem | undefined>;
showQuickPick(itemsOrItemsPromise: Item[] | Thenable<Item[]>, options?: QuickPickOptions, token: CancellationToken = CancellationToken.None): Thenable<Item | Item[] | undefined> {
Expand All @@ -45,7 +45,7 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
matchOnDescription: options && options.matchOnDescription,
matchOnDetail: options && options.matchOnDetail,
ignoreFocusLost: options && options.ignoreFocusOut,
multiSelect: options && options.multiSelect
canSelectMany: options && options.canSelectMany
});

const promise = TPromise.any(<TPromise<number | Item[]>[]>[quickPickWidget, itemsPromise]).then(values => {
Expand All @@ -70,7 +70,7 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
label = item.label;
description = item.description;
detail = item.detail;
selected = options && options.multiSelect ? (<MultiSelectQuickPickItem>item).selected : undefined;
selected = item.selected;
}
pickItems.push({
label,
Expand Down

0 comments on commit e563e40

Please sign in to comment.