mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
add cancellation support for showInput and showQuickPick, #9377
This commit is contained in:
@@ -236,11 +236,11 @@ export class ExtHostAPIImplementation {
|
||||
showErrorMessage: (message, ...items) => {
|
||||
return extHostMessageService.showMessage(Severity.Error, message, items);
|
||||
},
|
||||
showQuickPick: (items: any, options: vscode.QuickPickOptions) => {
|
||||
return extHostQuickOpen.show(items, options);
|
||||
showQuickPick: (items: any, options: vscode.QuickPickOptions, token?: vscode.CancellationToken) => {
|
||||
return extHostQuickOpen.showQuickPick(items, options, token);
|
||||
},
|
||||
showInputBox(options?: vscode.InputBoxOptions) {
|
||||
return extHostQuickOpen.input(options);
|
||||
showInputBox(options?: vscode.InputBoxOptions, token?: vscode.CancellationToken) {
|
||||
return extHostQuickOpen.showInput(options, token);
|
||||
},
|
||||
|
||||
createStatusBarItem(position?: vscode.StatusBarAlignment, priority?: number): vscode.StatusBarItem {
|
||||
|
||||
@@ -153,7 +153,7 @@ export abstract class MainThreadQuickOpenShape {
|
||||
$show(options: IPickOptions): Thenable<number> { throw ni(); }
|
||||
$setItems(items: MyQuickPickItems[]): Thenable<any> { throw ni(); }
|
||||
$setError(error: Error): Thenable<any> { throw ni(); }
|
||||
$input(options: vscode.InputBoxOptions, validateInput: boolean): Thenable<string> { throw ni(); }
|
||||
$input(options: vscode.InputBoxOptions, validateInput: boolean): TPromise<string> { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class MainThreadStatusBarShape {
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
'use strict';
|
||||
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {wireCancellationToken} from 'vs/base/common/async';
|
||||
import {CancellationToken} from 'vs/base/common/cancellation';
|
||||
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
|
||||
import {QuickPickOptions, QuickPickItem, InputBoxOptions} from 'vscode';
|
||||
import {MainContext, MainThreadQuickOpenShape, ExtHostQuickOpenShape, MyQuickPickItems} from './extHost.protocol';
|
||||
@@ -22,26 +24,21 @@ export class ExtHostQuickOpen extends ExtHostQuickOpenShape {
|
||||
this._proxy = threadService.get(MainContext.MainThreadQuickOpen);
|
||||
}
|
||||
|
||||
show(itemsOrItemsPromise: Item[] | Thenable<Item[]>, options?: QuickPickOptions): Thenable<Item> {
|
||||
showQuickPick(itemsOrItemsPromise: Item[] | Thenable<Item[]>, options?: QuickPickOptions, token: CancellationToken = CancellationToken.None): Thenable<Item> {
|
||||
|
||||
// clear state from last invocation
|
||||
this._onDidSelectItem = undefined;
|
||||
|
||||
let itemsPromise: Thenable<Item[]>;
|
||||
if (!Array.isArray(itemsOrItemsPromise)) {
|
||||
itemsPromise = itemsOrItemsPromise;
|
||||
} else {
|
||||
itemsPromise = TPromise.as(itemsOrItemsPromise);
|
||||
}
|
||||
const itemsPromise = <TPromise<Item[]>> TPromise.as(itemsOrItemsPromise);
|
||||
|
||||
let quickPickWidget = this._proxy.$show({
|
||||
const quickPickWidget = this._proxy.$show({
|
||||
autoFocus: { autoFocusFirstEntry: true },
|
||||
placeHolder: options && options.placeHolder,
|
||||
matchOnDescription: options && options.matchOnDescription,
|
||||
matchOnDetail: options && options.matchOnDetail
|
||||
});
|
||||
|
||||
return itemsPromise.then(items => {
|
||||
const promise = itemsPromise.then(items => {
|
||||
|
||||
let pickItems: MyQuickPickItems[] = [];
|
||||
for (let handle = 0; handle < items.length; handle++) {
|
||||
@@ -86,6 +83,8 @@ export class ExtHostQuickOpen extends ExtHostQuickOpenShape {
|
||||
|
||||
return TPromise.wrapError(err);
|
||||
});
|
||||
|
||||
return wireCancellationToken(token, promise, true);
|
||||
}
|
||||
|
||||
$onItemSelected(handle: number): void {
|
||||
@@ -96,9 +95,13 @@ export class ExtHostQuickOpen extends ExtHostQuickOpenShape {
|
||||
|
||||
// ---- input
|
||||
|
||||
input(options?: InputBoxOptions): Thenable<string> {
|
||||
showInput(options?: InputBoxOptions, token: CancellationToken = CancellationToken.None): Thenable<string> {
|
||||
|
||||
// global validate fn used in callback below
|
||||
this._validateInput = options && options.validateInput;
|
||||
return this._proxy.$input(options, options && typeof options.validateInput === 'function');
|
||||
|
||||
const promise = this._proxy.$input(options, typeof this._validateInput === 'function');
|
||||
return wireCancellationToken(token, promise, true);
|
||||
}
|
||||
|
||||
$validateInput(input: string): TPromise<string> {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {asWinJsPromise} from 'vs/base/common/async';
|
||||
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
|
||||
import {IQuickOpenService, IPickOptions, IInputOptions} from 'vs/workbench/services/quickopen/common/quickOpenService';
|
||||
import {InputBoxOptions} from 'vscode';
|
||||
@@ -46,7 +47,7 @@ export class MainThreadQuickOpen extends MainThreadQuickOpenShape {
|
||||
};
|
||||
});
|
||||
|
||||
return this._quickOpenService.pick(this._contents, options).then(item => {
|
||||
return asWinJsPromise(token => this._quickOpenService.pick(this._contents, options, token)).then(item => {
|
||||
if (item) {
|
||||
return item.handle;
|
||||
}
|
||||
@@ -73,7 +74,7 @@ export class MainThreadQuickOpen extends MainThreadQuickOpenShape {
|
||||
|
||||
// ---- input
|
||||
|
||||
$input(options: InputBoxOptions, validateInput: boolean): Thenable<string> {
|
||||
$input(options: InputBoxOptions, validateInput: boolean): TPromise<string> {
|
||||
|
||||
const inputOptions: IInputOptions = Object.create(null);
|
||||
|
||||
@@ -90,6 +91,6 @@ export class MainThreadQuickOpen extends MainThreadQuickOpenShape {
|
||||
};
|
||||
}
|
||||
|
||||
return this._quickOpenService.input(inputOptions);
|
||||
return asWinJsPromise(token => this._quickOpenService.input(inputOptions, token));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user