mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 17:22:51 -05:00
Simplify button logic and enable button updates for custom dialogs (#1283)
This commit is contained in:
@@ -61,25 +61,33 @@ export class DialogModal extends Modal {
|
||||
if (this._dialog.customButtons) {
|
||||
this._dialog.customButtons.forEach(button => {
|
||||
let buttonElement = this.addDialogButton(button);
|
||||
buttonElement.enabled = button.enabled;
|
||||
attachButtonStyler(buttonElement, this._themeService);
|
||||
this.updateButtonElement(buttonElement, button);
|
||||
});
|
||||
}
|
||||
|
||||
this._cancelButton = this.addDialogButton(this._dialog.cancelButton, () => this.cancel());
|
||||
this._cancelButton.enabled = this._dialog.cancelButton.enabled;
|
||||
this.updateButtonElement(this._cancelButton, this._dialog.cancelButton);
|
||||
this._doneButton = this.addDialogButton(this._dialog.okButton, () => this.done());
|
||||
this._doneButton.enabled = this._dialog.okButton.enabled;
|
||||
attachButtonStyler(this._cancelButton, this._themeService);
|
||||
attachButtonStyler(this._doneButton, this._themeService);
|
||||
this.updateButtonElement(this._doneButton, this._dialog.okButton);
|
||||
}
|
||||
|
||||
private addDialogButton(button: DialogButton, onSelect: () => void = () => undefined): Button {
|
||||
let buttonElement = this.addFooterButton(button.label, onSelect);
|
||||
buttonElement.enabled = button.enabled;
|
||||
button.registerClickEvent(buttonElement.onDidClick);
|
||||
button.onUpdate(() => {
|
||||
this.updateButtonElement(buttonElement, button);
|
||||
});
|
||||
attachButtonStyler(buttonElement, this._themeService);
|
||||
return buttonElement;
|
||||
}
|
||||
|
||||
private updateButtonElement(buttonElement: Button, dialogButton: DialogButton) {
|
||||
buttonElement.label = dialogButton.label;
|
||||
buttonElement.enabled = dialogButton.enabled;
|
||||
dialogButton.hidden ? buttonElement.element.classList.add('dialogModal-hidden') : buttonElement.element.classList.remove('dialogModal-hidden');
|
||||
}
|
||||
|
||||
protected renderBody(container: HTMLElement): void {
|
||||
new Builder(container).div({ class: 'dialogModal-body' }, (bodyBuilder) => {
|
||||
this._body = bodyBuilder.getHTMLElement();
|
||||
|
||||
Reference in New Issue
Block a user