mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 17:22:20 -05:00
Add wizard navigation validator (#1587)
This commit is contained in:
@@ -217,6 +217,7 @@ class WizardImpl implements sqlops.window.modelviewdialog.Wizard {
|
||||
public customButtons: sqlops.window.modelviewdialog.Button[];
|
||||
private _pageChangedEmitter = new Emitter<sqlops.window.modelviewdialog.WizardPageChangeInfo>();
|
||||
public readonly onPageChanged = this._pageChangedEmitter.event;
|
||||
private _navigationValidator: (info: sqlops.window.modelviewdialog.WizardPageChangeInfo) => boolean | Thenable<boolean>;
|
||||
|
||||
constructor(public title: string, private _extHostModelViewDialog: ExtHostModelViewDialog) {
|
||||
this.doneButton = this._extHostModelViewDialog.createButton(DONE_LABEL);
|
||||
@@ -225,6 +226,7 @@ class WizardImpl implements sqlops.window.modelviewdialog.Wizard {
|
||||
this.nextButton = this._extHostModelViewDialog.createButton(NEXT_LABEL);
|
||||
this.backButton = this._extHostModelViewDialog.createButton(PREVIOUS_LABEL);
|
||||
this._extHostModelViewDialog.registerWizardPageInfoChangedCallback(this, info => this.handlePageInfoChanged(info));
|
||||
this._currentPage = 0;
|
||||
this.onPageChanged(info => this._currentPage = info.newPage);
|
||||
}
|
||||
|
||||
@@ -254,6 +256,18 @@ class WizardImpl implements sqlops.window.modelviewdialog.Wizard {
|
||||
return this._extHostModelViewDialog.closeWizard(this);
|
||||
}
|
||||
|
||||
public registerNavigationValidator(validator: (pageChangeInfo: sqlops.window.modelviewdialog.WizardPageChangeInfo) => boolean | Thenable<boolean>): void {
|
||||
this._navigationValidator = validator;
|
||||
}
|
||||
|
||||
public validateNavigation(info: sqlops.window.modelviewdialog.WizardPageChangeInfo): Thenable<boolean> {
|
||||
if (this._navigationValidator) {
|
||||
return Promise.resolve(this._navigationValidator(info));
|
||||
} else {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
|
||||
private handlePageInfoChanged(info: WizardPageEventInfo): void {
|
||||
this._currentPage = info.pageChangeInfo.newPage;
|
||||
if (info.eventType === WizardPageInfoEventType.PageAddedOrRemoved) {
|
||||
@@ -335,6 +349,11 @@ export class ExtHostModelViewDialog implements ExtHostModelViewDialogShape {
|
||||
}
|
||||
}
|
||||
|
||||
public $validateNavigation(handle: number, info: sqlops.window.modelviewdialog.WizardPageChangeInfo): Thenable<boolean> {
|
||||
let wizard = this._objectsByHandle.get(handle) as WizardImpl;
|
||||
return wizard.validateNavigation(info);
|
||||
}
|
||||
|
||||
public openDialog(dialog: sqlops.window.modelviewdialog.Dialog): void {
|
||||
let handle = this.getHandle(dialog);
|
||||
this.updateDialogContent(dialog);
|
||||
|
||||
@@ -157,6 +157,7 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
wizard.onPageChanged(info => this._proxy.$onWizardPageChanged(handle, info));
|
||||
wizard.onPageAdded(() => this.handleWizardPageAddedOrRemoved(handle));
|
||||
wizard.onPageRemoved(() => this.handleWizardPageAddedOrRemoved(handle));
|
||||
wizard.registerNavigationValidator(info => this.validateNavigation(handle, info));
|
||||
this._wizards.set(handle, wizard);
|
||||
}
|
||||
|
||||
@@ -254,4 +255,8 @@ export class MainThreadModelViewDialog implements MainThreadModelViewDialogShape
|
||||
let wizard = this._wizards.get(handle);
|
||||
this._proxy.$updateWizardPageInfo(handle, wizard.pages.map(page => this._wizardPageHandles.get(page)), wizard.currentPage);
|
||||
}
|
||||
|
||||
private validateNavigation(handle: number, info: sqlops.window.modelviewdialog.WizardPageChangeInfo): Thenable<boolean> {
|
||||
return this._proxy.$validateNavigation(handle, info);
|
||||
}
|
||||
}
|
||||
@@ -556,6 +556,7 @@ export interface ExtHostModelViewDialogShape {
|
||||
$onPanelValidityChanged(handle: number, valid: boolean): void;
|
||||
$onWizardPageChanged(handle: number, info: sqlops.window.modelviewdialog.WizardPageChangeInfo): void;
|
||||
$updateWizardPageInfo(handle: number, pageHandles: number[], currentPageIndex: number): void;
|
||||
$validateNavigation(handle: number, info: sqlops.window.modelviewdialog.WizardPageChangeInfo): Thenable<boolean>;
|
||||
}
|
||||
|
||||
export interface MainThreadModelViewDialogShape extends IDisposable {
|
||||
|
||||
Reference in New Issue
Block a user