Simplify button logic and enable button updates for custom dialogs (#1283)

This commit is contained in:
Matt Irvine
2018-04-27 16:29:18 -07:00
committed by GitHub
parent 886717d330
commit 24e8c20511
11 changed files with 119 additions and 72 deletions

View File

@@ -26,18 +26,6 @@ class DialogImpl implements sqlops.window.modelviewdialog.Dialog {
this.okButton = this._extHostModelViewDialog.createButton(nls.localize('dialogOkLabel', 'Done'));
this.cancelButton = this._extHostModelViewDialog.createButton(nls.localize('dialogCancelLabel', 'Cancel'));
}
public open(): void {
this._extHostModelViewDialog.open(this);
}
public close(): void {
this._extHostModelViewDialog.close(this);
}
public updateContent(): void {
this._extHostModelViewDialog.updateDialogContent(this);
}
}
class TabImpl implements sqlops.window.modelviewdialog.DialogTab {
@@ -45,21 +33,19 @@ class TabImpl implements sqlops.window.modelviewdialog.DialogTab {
public content: string;
constructor(private _extHostModelViewDialog: ExtHostModelViewDialog) { }
public updateContent(): void {
this._extHostModelViewDialog.updateTabContent(this);
}
}
class ButtonImpl implements sqlops.window.modelviewdialog.Button {
private _label: string;
private _enabled: boolean;
private _hidden: boolean;
private _onClick = new Emitter<void>();
public onClick = this._onClick.event;
constructor(private _extHostModelViewDialog: ExtHostModelViewDialog) {
this._enabled = true;
this._hidden = false;
}
public get label(): string {
@@ -80,6 +66,15 @@ class ButtonImpl implements sqlops.window.modelviewdialog.Button {
this._extHostModelViewDialog.updateButton(this);
}
public get hidden(): boolean {
return this._hidden;
}
public set hidden(hidden: boolean) {
this._hidden = hidden;
this._extHostModelViewDialog.updateButton(this);
}
public getOnClickCallback(): () => void {
return () => this._onClick.fire();
}
@@ -154,7 +149,7 @@ export class ExtHostModelViewDialog implements ExtHostModelViewDialogShape {
let handle = this.getDialogHandle(dialog);
let tabs = dialog.content;
if (tabs && typeof tabs !== 'string') {
tabs.forEach(tab => tab.updateContent());
tabs.forEach(tab => this.updateTabContent(tab));
}
if (dialog.customButtons) {
dialog.customButtons.forEach(button => this.updateButton(button));
@@ -182,7 +177,8 @@ export class ExtHostModelViewDialog implements ExtHostModelViewDialogShape {
let handle = this.getButtonHandle(button);
this._proxy.$setButtonDetails(handle, {
label: button.label,
enabled: button.enabled
enabled: button.enabled,
hidden: button.hidden
});
}