mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-29 01:25:37 -05:00
Add dialog close validation (#1704)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user