Fire done/cancel click events when dialog is closed (#1379)

This commit is contained in:
Matt Irvine
2018-05-09 13:17:02 -07:00
committed by GitHub
parent 80a9c82813
commit f4cfb4a5ef

View File

@@ -26,9 +26,8 @@ import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
export class DialogModal extends Modal { export class DialogModal extends Modal {
private _dialogPane: DialogPane; private _dialogPane: DialogPane;
private _onDone = new Emitter<void>();
// Wizard HTML elements private _onCancel = new Emitter<void>();
private _body: HTMLElement;
// Buttons // Buttons
private _cancelButton: Button; private _cancelButton: Button;
@@ -67,16 +66,20 @@ export class DialogModal extends Modal {
}); });
} }
this._cancelButton = this.addDialogButton(this._dialog.cancelButton, () => this.cancel()); this._cancelButton = this.addDialogButton(this._dialog.cancelButton, () => this.cancel(), false);
this.updateButtonElement(this._cancelButton, this._dialog.cancelButton); this.updateButtonElement(this._cancelButton, this._dialog.cancelButton);
this._doneButton = this.addDialogButton(this._dialog.okButton, () => this.done()); this._dialog.cancelButton.registerClickEvent(this._onCancel.event);
this._doneButton = this.addDialogButton(this._dialog.okButton, () => this.done(), false);
this.updateButtonElement(this._doneButton, this._dialog.okButton); this.updateButtonElement(this._doneButton, this._dialog.okButton);
this._dialog.okButton.registerClickEvent(this._onDone.event);
} }
private addDialogButton(button: DialogButton, onSelect: () => void = () => undefined): Button { private addDialogButton(button: DialogButton, onSelect: () => void = () => undefined, registerClickEvent: boolean = true): Button {
let buttonElement = this.addFooterButton(button.label, onSelect); let buttonElement = this.addFooterButton(button.label, onSelect);
buttonElement.enabled = button.enabled; buttonElement.enabled = button.enabled;
if (registerClickEvent) {
button.registerClickEvent(buttonElement.onDidClick); button.registerClickEvent(buttonElement.onDidClick);
}
button.onUpdate(() => { button.onUpdate(() => {
this.updateButtonElement(buttonElement, button); this.updateButtonElement(buttonElement, button);
}); });
@@ -91,12 +94,13 @@ export class DialogModal extends Modal {
} }
protected renderBody(container: HTMLElement): void { protected renderBody(container: HTMLElement): void {
let body: HTMLElement;
new Builder(container).div({ class: 'dialogModal-body' }, (bodyBuilder) => { new Builder(container).div({ class: 'dialogModal-body' }, (bodyBuilder) => {
this._body = bodyBuilder.getHTMLElement(); body = bodyBuilder.getHTMLElement();
}); });
this._dialogPane = new DialogPane(this._dialog, this._bootstrapService); this._dialogPane = new DialogPane(this._dialog, this._bootstrapService);
this._dialogPane.createBody(this._body); this._dialogPane.createBody(body);
} }
public open(): void { public open(): void {
@@ -105,12 +109,14 @@ export class DialogModal extends Modal {
public done(): void { public done(): void {
if (this._dialog.okButton.enabled) { if (this._dialog.okButton.enabled) {
this._onDone.fire();
this.dispose(); this.dispose();
this.hide(); this.hide();
} }
} }
public cancel(): void { public cancel(): void {
this._onCancel.fire();
this.dispose(); this.dispose();
this.hide(); this.hide();
} }