Add dialog close validation (#1704)

This commit is contained in:
Matt Irvine
2018-06-21 16:55:47 -07:00
committed by GitHub
parent 1871fd383e
commit 6c5fac997f
8 changed files with 84 additions and 5 deletions

View File

@@ -120,11 +120,13 @@ export class DialogModal extends Modal {
this.show();
}
public done(): void {
public async done(): Promise<void> {
if (this._dialog.okButton.enabled) {
this._onDone.fire();
this.dispose();
this.hide();
if (await this._dialog.validateClose()) {
this._onDone.fire();
this.dispose();
this.hide();
}
}
}

View File

@@ -49,6 +49,7 @@ export class Dialog extends ModelViewPane {
private _onMessageChange = new Emitter<DialogMessage>();
public readonly onMessageChange = this._onMessageChange.event;
private _message: DialogMessage;
private _closeValidator: () => boolean | Thenable<boolean>;
constructor(public title: string, content?: string | DialogTab[]) {
super();
@@ -67,6 +68,18 @@ export class Dialog extends ModelViewPane {
this._onMessageChange.fire(this._message);
}
}
public registerCloseValidator(validator: () => boolean | Thenable<boolean>): void {
this._closeValidator = validator;
}
public validateClose(): Thenable<boolean> {
if (this._closeValidator) {
return Promise.resolve(this._closeValidator());
} else {
return Promise.resolve(true);
}
}
}
export class DialogButton implements sqlops.window.modelviewdialog.Button {