mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 09:35:37 -05:00
Simplify button logic and enable button updates for custom dialogs (#1283)
This commit is contained in:
@@ -115,4 +115,5 @@ export interface IModelViewTabDetails {
|
||||
export interface IModelViewButtonDetails {
|
||||
label: string;
|
||||
enabled: boolean;
|
||||
hidden: boolean;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
|
||||
constructor(
|
||||
context: IExtHostContext,
|
||||
@IInstantiationService instatiationService: IInstantiationService
|
||||
@IInstantiationService instatiationService: IInstantiationService,
|
||||
) {
|
||||
this._proxy = context.getProxy(SqlExtHostContext.ExtHostModelViewDialog);
|
||||
this._dialogService = new CustomDialogService(instatiationService);
|
||||
@@ -40,7 +40,7 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
|
||||
public $close(handle: number): Thenable<void> {
|
||||
let dialog = this.getDialog(handle);
|
||||
dialog.close();
|
||||
this._dialogService.closeDialog(dialog);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
@@ -66,7 +66,6 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
dialog.customButtons = details.customButtons.map(buttonHandle => this.getButton(buttonHandle));
|
||||
}
|
||||
|
||||
dialog.updateContent();
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
@@ -79,8 +78,6 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
|
||||
tab.title = details.title;
|
||||
tab.content = details.content;
|
||||
|
||||
tab.updateContent();
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
@@ -88,11 +85,13 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
let button = this._buttons.get(handle);
|
||||
if (!button) {
|
||||
button = new DialogButton(details.label, details.enabled);
|
||||
button.hidden = details.hidden;
|
||||
button.onClick(() => this.onButtonClick(handle));
|
||||
this._buttons.set(handle, button);
|
||||
} else {
|
||||
button.label = details.label;
|
||||
button.enabled = details.enabled;
|
||||
button.hidden = details.hidden;
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
|
||||
@@ -293,6 +293,12 @@ export function createApiFactory(
|
||||
},
|
||||
createButton(label: string): sqlops.window.modelviewdialog.Button {
|
||||
return extHostModelViewDialog.createButton(label);
|
||||
},
|
||||
openDialog(dialog: sqlops.window.modelviewdialog.Dialog) {
|
||||
return extHostModelViewDialog.open(dialog);
|
||||
},
|
||||
closeDialog(dialog: sqlops.window.modelviewdialog.Dialog) {
|
||||
return extHostModelViewDialog.close(dialog);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user