提交 7b9368eb 编写于 作者: J Joao Moreno

change to validateInput

上级 888f7449
......@@ -523,7 +523,7 @@ export class Repository implements Disposable {
this._sourceControl.inputBox.placeholder = localize('commitMessage', "Message (press {0} to commit)");
this._sourceControl.acceptInputCommand = { command: 'git.commitWithInput', title: localize('commit', "Commit"), arguments: [this._sourceControl] };
this._sourceControl.quickDiffProvider = this;
this._sourceControl.inputBox.validationProvider = this;
this._sourceControl.inputBox.validateInput = this.validateInput.bind(this);
this.disposables.push(this._sourceControl);
this._mergeGroup = this._sourceControl.createResourceGroup('merge', localize('merge changes', "Merge Changes"));
......
......@@ -5986,56 +5986,6 @@ declare module 'vscode' {
export function setLanguageConfiguration(language: string, configuration: LanguageConfiguration): Disposable;
}
/**
* Represents the validation type of the Source Control input.
*/
export enum SourceControlInputBoxValidationType {
/**
* Something not allowed by the rules of a language or other means.
*/
Error = 0,
/**
* Something suspicious but allowed.
*/
Warning = 1,
/**
* Something to inform about but not a problem.
*/
Information = 2
}
export interface SourceControlInputBoxValidation {
/**
* The validation message to display.
*/
readonly message: string;
/**
* The validation type.
*/
readonly type: SourceControlInputBoxValidationType;
}
/**
* A validation provider which can validate Source Control input.
*/
export interface SourceControlInputBoxValidationProvider {
/**
* A function that will be called to validate input and give a hint to the user.
*
* @param value The current value of the input box.
* @param cursorPosition The cusror position within the input box.
* @return A human readable string which is presented as diagnostic message.
* Return `undefined`, `null`, or the empty string when 'value' is valid.
*/
validateInput(value: string, cursorPosition: number): ProviderResult<SourceControlInputBoxValidation | undefined | null>;
}
/**
* Represents the input box in the Source Control viewlet.
*/
......@@ -6050,12 +6000,6 @@ declare module 'vscode' {
* A string to show as place holder in the input box to guide the user.
*/
placeholder: string;
/**
* A validation provider for the input box. It's possible to change
* the validation provider simply by setting this property to a different value.
*/
validationProvider: SourceControlInputBoxValidationProvider;
}
interface QuickDiffProvider {
......
......@@ -394,4 +394,50 @@ declare module 'vscode' {
*/
logger: Logger;
}
/**
* Represents the validation type of the Source Control input.
*/
export enum SourceControlInputBoxValidationType {
/**
* Something not allowed by the rules of a language or other means.
*/
Error = 0,
/**
* Something suspicious but allowed.
*/
Warning = 1,
/**
* Something to inform about but not a problem.
*/
Information = 2
}
export interface SourceControlInputBoxValidation {
/**
* The validation message to display.
*/
readonly message: string;
/**
* The validation type.
*/
readonly type: SourceControlInputBoxValidationType;
}
/**
* Represents the input box in the Source Control viewlet.
*/
export interface SourceControlInputBox {
/**
* A validation function for the input box. It's possible to change
* the validation provider simply by setting this property to a different function.
*/
validateInput?(value: string, cursorPosition: number): ProviderResult<SourceControlInputBoxValidation | undefined | null>;
}
}
......@@ -110,6 +110,10 @@ function compareResourceStates(a: vscode.SourceControlResourceState, b: vscode.S
return result;
}
export interface IValidateInput {
(value: string, cursorPosition: number): vscode.ProviderResult<vscode.SourceControlInputBoxValidation | undefined | null>;
}
export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
private _value: string = '';
......@@ -140,23 +144,31 @@ export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
this._placeholder = placeholder;
}
private _validationProvider: vscode.SourceControlInputBoxValidationProvider;
private _validateInput: IValidateInput;
get validationProvider(): vscode.SourceControlInputBoxValidationProvider {
return this._validationProvider;
get validateInput(): IValidateInput {
if (!this._extension.enableProposedApi) {
throw new Error(`[${this._extension.id}]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ${this._extension.id}`);
}
set validationProvider(provider: vscode.SourceControlInputBoxValidationProvider) {
if (!provider || typeof provider.validateInput !== 'function') {
console.warn('INVALID SCM input box validation provider');
return this._validateInput;
}
set validateInput(fn: IValidateInput) {
if (!this._extension.enableProposedApi) {
throw new Error(`[${this._extension.id}]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ${this._extension.id}`);
}
if (fn && typeof fn !== 'function') {
console.warn('Invalid SCM input box validation function');
return;
}
this._validationProvider = provider;
this._proxy.$setValidationProviderIsEnabled(this._sourceControlHandle, true);
this._validateInput = fn;
this._proxy.$setValidationProviderIsEnabled(this._sourceControlHandle, !!fn);
}
constructor(private _proxy: MainThreadSCMShape, private _sourceControlHandle: number) {
constructor(private _extension: IExtensionDescription, private _proxy: MainThreadSCMShape, private _sourceControlHandle: number) {
// noop
}
......@@ -386,13 +398,14 @@ class ExtHostSourceControl implements vscode.SourceControl {
private handle: number = ExtHostSourceControl._handlePool++;
constructor(
_extension: IExtensionDescription,
private _proxy: MainThreadSCMShape,
private _commands: ExtHostCommands,
private _id: string,
private _label: string,
private _rootUri?: vscode.Uri
) {
this._inputBox = new ExtHostSCMInputBox(this._proxy, this.handle);
this._inputBox = new ExtHostSCMInputBox(_extension, this._proxy, this.handle);
this._proxy.$registerSourceControl(this.handle, _id, _label, _rootUri && _rootUri.toString());
}
......@@ -508,7 +521,7 @@ export class ExtHostSCM implements ExtHostSCMShape {
this.logService.trace('ExtHostSCM#createSourceControl', extension.id, id, label, rootUri);
const handle = ExtHostSCM._handlePool++;
const sourceControl = new ExtHostSourceControl(this._proxy, this._commands, id, label, rootUri);
const sourceControl = new ExtHostSourceControl(extension, this._proxy, this._commands, id, label, rootUri);
this._sourceControls.set(handle, sourceControl);
const sourceControls = this._sourceControlsByExtension.get(extension.id) || [];
......@@ -582,7 +595,11 @@ export class ExtHostSCM implements ExtHostSCMShape {
return TPromise.as(undefined);
}
const result = await sourceControl.inputBox.validationProvider.validateInput(value, cursorPosition);
if (!sourceControl.inputBox.validateInput) {
return TPromise.as(undefined);
}
const result = await sourceControl.inputBox.validateInput(value, cursorPosition);
if (!result) {
return TPromise.as(undefined);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册