mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
add support for input validation
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
|
||||
import {IQuickOpenService, IPickOpenEntry, IPickOptions} from 'vs/workbench/services/quickopen/common/quickOpenService';
|
||||
import {IQuickOpenService, IPickOpenEntry, IPickOptions, IInputOptions} from 'vs/workbench/services/quickopen/common/quickOpenService';
|
||||
import {QuickPickOptions, QuickPickItem, InputBoxOptions} from 'vscode';
|
||||
|
||||
export interface MyQuickPickItems extends IPickOpenEntry {
|
||||
@@ -20,6 +20,7 @@ export class ExtHostQuickOpen {
|
||||
|
||||
private _proxy: MainThreadQuickOpen;
|
||||
private _onDidSelectItem: (handle: number) => void;
|
||||
private _validateInput: (input: string) => string;
|
||||
|
||||
constructor(@IThreadService threadService: IThreadService) {
|
||||
this._proxy = threadService.getRemotable(MainThreadQuickOpen);
|
||||
@@ -97,8 +98,17 @@ export class ExtHostQuickOpen {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- input
|
||||
|
||||
input(options?: InputBoxOptions): Thenable<string> {
|
||||
return this._proxy.$input(options);
|
||||
this._validateInput = options.validateInput;
|
||||
return this._proxy.$input(options, typeof options.validateInput === 'function');
|
||||
}
|
||||
|
||||
$validateInput(input: string): TPromise<string> {
|
||||
if (this._validateInput) {
|
||||
return TPromise.as(this._validateInput(input));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,25 +170,25 @@ export class MainThreadQuickOpen {
|
||||
}
|
||||
}
|
||||
|
||||
$input(options?: InputBoxOptions): Thenable<string> {
|
||||
// ---- input
|
||||
|
||||
let defaultItem = 'Insert text and press Enter or Escape';
|
||||
let userValue: string;
|
||||
$input(options: InputBoxOptions, validateInput: boolean): Thenable<string> {
|
||||
|
||||
return new TPromise((resolve, reject) => {
|
||||
const inputOptions: IInputOptions = Object.create(null);
|
||||
|
||||
this._quickOpenService.pick([defaultItem], {
|
||||
placeHolder: options.placeHolder,
|
||||
autoFocus: true,
|
||||
onDidType(value) {
|
||||
userValue = value;
|
||||
// console.log('TEXT')
|
||||
}
|
||||
}).then(item => {
|
||||
resolve(item && userValue);
|
||||
}, reject);
|
||||
});
|
||||
if (options) {
|
||||
inputOptions.password = options.password;
|
||||
inputOptions.placeHolder = options.placeHolder;
|
||||
inputOptions.prompt = options.prompt;
|
||||
inputOptions.value = options.value;
|
||||
}
|
||||
|
||||
// return this._quickOpenService.input(options);
|
||||
if (validateInput) {
|
||||
inputOptions.validateInput = (value) => {
|
||||
return this._proxy.$validateInput(value);
|
||||
}
|
||||
}
|
||||
|
||||
return this._quickOpenService.input(inputOptions);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user