diff --git a/src/sql/workbench/api/browser/mainThreadModelViewDialog.ts b/src/sql/workbench/api/browser/mainThreadModelViewDialog.ts index 6d7eb1cffc..4e72250f8e 100644 --- a/src/sql/workbench/api/browser/mainThreadModelViewDialog.ts +++ b/src/sql/workbench/api/browser/mainThreadModelViewDialog.ts @@ -161,19 +161,10 @@ export class MainThreadModelViewDialog extends Disposable implements MainThreadM let button = this._buttons.get(handle); if (!button) { button = new DialogButton(details.label, details.enabled); - button.position = details.position; - button.hidden = details.hidden; - button.secondary = details.secondary; button.onClick(() => this.onButtonClick(handle)); this._buttons.set(handle, button); - } else { - button.label = details.label; - button.enabled = details.enabled; - button.hidden = details.hidden; - button.focused = details.focused; - button.position = details.position; - button.secondary = details.secondary; } + button.setProperties(details); return Promise.resolve(); } diff --git a/src/sql/workbench/services/dialog/common/dialogTypes.ts b/src/sql/workbench/services/dialog/common/dialogTypes.ts index 6e2cb38cbf..a2bb22938b 100644 --- a/src/sql/workbench/services/dialog/common/dialogTypes.ts +++ b/src/sql/workbench/services/dialog/common/dialogTypes.ts @@ -100,22 +100,42 @@ export class Dialog extends ModelViewPane { } } +export interface DialogButtonProperties { + label: string; + enabled: boolean; + hidden: boolean; + focused?: boolean; + position?: azdata.window.DialogButtonPosition; + secondary?: boolean; +} + export class DialogButton implements azdata.window.Button { - private _label: string; - private _enabled: boolean; - private _hidden: boolean; - private _focused: boolean | undefined; + private _hidden: boolean = false; + private _focused?: boolean; private _position?: azdata.window.DialogButtonPosition; - private _secondary: boolean | undefined; + private _secondary?: boolean; private _onClick: Emitter = new Emitter(); public readonly onClick: Event = this._onClick.event; private _onUpdate: Emitter = new Emitter(); public readonly onUpdate: Event = this._onUpdate.event; - constructor(label: string, enabled: boolean) { - this._label = label; - this._enabled = enabled; - this._hidden = false; + constructor(private _label: string, private _enabled: boolean) { } + + /** + * Sets all the values for the dialog button and then fires the onUpdate event once - this should be + * preferred to be used when setting multiple properties to reduce overhead of event listeners having + * to process multiple events. + * Note that all current values are overwritten with the ones passed in. + * @param properties The property values to set for this dialog button + */ + public setProperties(properties: DialogButtonProperties) { + this._enabled = properties.enabled; + this._focused = properties.focused; + this._hidden = properties.hidden; + this._label = properties.label; + this._position = properties.position; + this._secondary = properties.secondary; + this._onUpdate.fire(); } public get label(): string {