mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 09:59:47 -05:00
Enable basic wizard API (#1450)
This commit is contained in:
@@ -11,9 +11,9 @@ import { IExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
import { MainThreadModelViewDialogShape, SqlMainContext, ExtHostModelViewDialogShape, SqlExtHostContext } from 'sql/workbench/api/node/sqlExtHost.protocol';
|
||||
import { Dialog, DialogTab, DialogButton } from 'sql/platform/dialog/dialogTypes';
|
||||
import { Dialog, DialogTab, DialogButton, WizardPage, Wizard } from 'sql/platform/dialog/dialogTypes';
|
||||
import { CustomDialogService } from 'sql/platform/dialog/customDialogService';
|
||||
import { IModelViewDialogDetails, IModelViewTabDetails, IModelViewButtonDetails } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { IModelViewDialogDetails, IModelViewTabDetails, IModelViewButtonDetails, IModelViewWizardPageDetails, IModelViewWizardDetails } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { ModelViewInput } from 'sql/parts/modelComponents/modelEditor/modelViewInput';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
@@ -24,6 +24,9 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
private readonly _dialogs = new Map<number, Dialog>();
|
||||
private readonly _tabs = new Map<number, DialogTab>();
|
||||
private readonly _buttons = new Map<number, DialogButton>();
|
||||
private readonly _wizardPages = new Map<number, WizardPage>();
|
||||
private readonly _wizardPageHandles = new Map<WizardPage, number>();
|
||||
private readonly _wizards = new Map<number, Wizard>();
|
||||
private _dialogService: CustomDialogService;
|
||||
|
||||
constructor(
|
||||
@@ -55,13 +58,13 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
});
|
||||
}
|
||||
|
||||
public $open(handle: number): Thenable<void> {
|
||||
public $openDialog(handle: number): Thenable<void> {
|
||||
let dialog = this.getDialog(handle);
|
||||
this._dialogService.showDialog(dialog);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public $close(handle: number): Thenable<void> {
|
||||
public $closeDialog(handle: number): Thenable<void> {
|
||||
let dialog = this.getDialog(handle);
|
||||
this._dialogService.closeDialog(dialog);
|
||||
return Promise.resolve();
|
||||
@@ -75,7 +78,7 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
let cancelButton = this.getButton(details.cancelButton);
|
||||
dialog.okButton = okButton;
|
||||
dialog.cancelButton = cancelButton;
|
||||
dialog.onValidityChanged(valid => this._proxy.$onDialogValidityChanged(handle, valid));
|
||||
dialog.onValidityChanged(valid => this._proxy.$onPanelValidityChanged(handle, valid));
|
||||
this._dialogs.set(handle, dialog);
|
||||
}
|
||||
|
||||
@@ -97,6 +100,7 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
let tab = this._tabs.get(handle);
|
||||
if (!tab) {
|
||||
tab = new DialogTab(details.title);
|
||||
tab.onValidityChanged(valid => this._proxy.$onPanelValidityChanged(handle, valid));
|
||||
this._tabs.set(handle, tab);
|
||||
}
|
||||
|
||||
@@ -121,12 +125,91 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public $setWizardPageDetails(handle: number, details: IModelViewWizardPageDetails): Thenable<void> {
|
||||
let page = this._wizardPages.get(handle);
|
||||
if (!page) {
|
||||
page = new WizardPage(details.title, details.content);
|
||||
page.onValidityChanged(valid => this._proxy.$onPanelValidityChanged(handle, valid));
|
||||
this._wizardPages.set(handle, page);
|
||||
this._wizardPageHandles.set(page, handle);
|
||||
}
|
||||
|
||||
page.title = details.title;
|
||||
page.content = details.content;
|
||||
page.enabled = details.enabled;
|
||||
if (details.customButtons !== undefined) {
|
||||
page.customButtons = details.customButtons.map(buttonHandle => this.getButton(buttonHandle));
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public $setWizardDetails(handle: number, details: IModelViewWizardDetails): Thenable<void> {
|
||||
let wizard = this._wizards.get(handle);
|
||||
if (!wizard) {
|
||||
wizard = new Wizard(details.title);
|
||||
wizard.backButton = this.getButton(details.backButton);
|
||||
wizard.cancelButton = this.getButton(details.cancelButton);
|
||||
wizard.generateScriptButton = this.getButton(details.generateScriptButton);
|
||||
wizard.doneButton = this.getButton(details.doneButton);
|
||||
wizard.nextButton = this.getButton(details.nextButton);
|
||||
wizard.onPageChanged(info => this._proxy.$onWizardPageChanged(handle, info));
|
||||
wizard.onPageAdded(() => this.handleWizardPageAddedOrRemoved(handle));
|
||||
wizard.onPageRemoved(() => this.handleWizardPageAddedOrRemoved(handle));
|
||||
this._wizards.set(handle, wizard);
|
||||
}
|
||||
|
||||
wizard.title = details.title;
|
||||
wizard.pages = details.pages.map(handle => this.getWizardPage(handle));
|
||||
if (details.currentPage !== undefined) {
|
||||
wizard.setCurrentPage(details.currentPage);
|
||||
}
|
||||
if (details.customButtons !== undefined) {
|
||||
wizard.customButtons = details.customButtons.map(buttonHandle => this.getButton(buttonHandle));
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public $addWizardPage(wizardHandle: number, pageHandle: number, pageIndex?: number): Thenable<void> {
|
||||
if (pageIndex === null) {
|
||||
pageIndex = undefined;
|
||||
}
|
||||
let wizard = this.getWizard(wizardHandle);
|
||||
let page = this.getWizardPage(pageHandle);
|
||||
wizard.addPage(page, pageIndex);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public $removeWizardPage(wizardHandle: number, pageIndex: number): Thenable<void> {
|
||||
let wizard = this.getWizard(wizardHandle);
|
||||
wizard.removePage(pageIndex);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public $setWizardPage(wizardHandle: number, pageIndex: number): Thenable<void> {
|
||||
let wizard = this.getWizard(wizardHandle);
|
||||
wizard.setCurrentPage(pageIndex);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public $openWizard(handle: number): Thenable<void> {
|
||||
let wizard = this.getWizard(handle);
|
||||
this._dialogService.showWizard(wizard);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public $closeWizard(handle: number): Thenable<void> {
|
||||
let wizard = this.getWizard(handle);
|
||||
this._dialogService.closeWizard(wizard);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
private getDialog(handle: number): Dialog {
|
||||
let dialog = this._dialogs.get(handle);
|
||||
if (!dialog) {
|
||||
throw new Error('No dialog matching the given handle');
|
||||
}
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@@ -135,7 +218,6 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
if (!tab) {
|
||||
throw new Error('No tab matching the given handle');
|
||||
}
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
@@ -144,11 +226,31 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
if (!button) {
|
||||
throw new Error('No button matching the given handle');
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private onButtonClick(handle: number): void {
|
||||
this._proxy.$onButtonClick(handle);
|
||||
}
|
||||
|
||||
private getWizardPage(handle: number): WizardPage {
|
||||
let page = this._wizardPages.get(handle);
|
||||
if (!page) {
|
||||
throw new Error('No page matching the given handle');
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
private getWizard(handle: number): Wizard {
|
||||
let wizard = this._wizards.get(handle);
|
||||
if (!wizard) {
|
||||
throw new Error('No wizard matching the given handle');
|
||||
}
|
||||
return wizard;
|
||||
}
|
||||
|
||||
private handleWizardPageAddedOrRemoved(handle: number): void {
|
||||
let wizard = this._wizards.get(handle);
|
||||
this._proxy.$updateWizardPageInfo(handle, wizard.pages.map(page => this._wizardPageHandles.get(page)), wizard.currentPage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user