mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Reduce the number of onUpdate events fired for dialog buttons (#16311)
This commit is contained in:
@@ -161,19 +161,10 @@ export class MainThreadModelViewDialog extends Disposable implements MainThreadM
|
|||||||
let button = this._buttons.get(handle);
|
let button = this._buttons.get(handle);
|
||||||
if (!button) {
|
if (!button) {
|
||||||
button = new DialogButton(details.label, details.enabled);
|
button = new DialogButton(details.label, details.enabled);
|
||||||
button.position = details.position;
|
|
||||||
button.hidden = details.hidden;
|
|
||||||
button.secondary = details.secondary;
|
|
||||||
button.onClick(() => this.onButtonClick(handle));
|
button.onClick(() => this.onButtonClick(handle));
|
||||||
this._buttons.set(handle, button);
|
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();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
export class DialogButton implements azdata.window.Button {
|
||||||
private _label: string;
|
private _hidden: boolean = false;
|
||||||
private _enabled: boolean;
|
private _focused?: boolean;
|
||||||
private _hidden: boolean;
|
|
||||||
private _focused: boolean | undefined;
|
|
||||||
private _position?: azdata.window.DialogButtonPosition;
|
private _position?: azdata.window.DialogButtonPosition;
|
||||||
private _secondary: boolean | undefined;
|
private _secondary?: boolean;
|
||||||
private _onClick: Emitter<void> = new Emitter<void>();
|
private _onClick: Emitter<void> = new Emitter<void>();
|
||||||
public readonly onClick: Event<void> = this._onClick.event;
|
public readonly onClick: Event<void> = this._onClick.event;
|
||||||
private _onUpdate: Emitter<void> = new Emitter<void>();
|
private _onUpdate: Emitter<void> = new Emitter<void>();
|
||||||
public readonly onUpdate: Event<void> = this._onUpdate.event;
|
public readonly onUpdate: Event<void> = this._onUpdate.event;
|
||||||
|
|
||||||
constructor(label: string, enabled: boolean) {
|
constructor(private _label: string, private _enabled: boolean) { }
|
||||||
this._label = label;
|
|
||||||
this._enabled = enabled;
|
/**
|
||||||
this._hidden = false;
|
* 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 {
|
public get label(): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user