diff --git a/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts b/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts index 5417b8aa62..68d5ad5e77 100644 --- a/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts +++ b/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts @@ -9,6 +9,8 @@ import * as azdata from 'azdata'; import * as vscode from 'vscode'; import * as os from 'os'; import { SchemaCompareResult } from '../schemaCompareResult'; +import { isNullOrUndefined } from 'util'; +import { existsSync } from 'fs'; const localize = nls.loadMessageBundle(); const OkButtonText: string = localize('schemaCompareDialog.ok', 'Ok'); @@ -76,6 +78,7 @@ export class SchemaCompareDialog { this.initializeDialog(); this.dialog.okButton.label = OkButtonText; + this.dialog.okButton.enabled = false; this.dialog.okButton.onClick(async () => await this.execute()); this.dialog.cancelButton.label = CancelButtonText; @@ -147,10 +150,18 @@ export class SchemaCompareDialog { width: 275 }).component(); + this.sourceTextBox.onTextChanged((e) => { + this.dialog.okButton.enabled = this.shouldEnableOkayButton(); + }); + this.targetTextBox = view.modelBuilder.inputBox().withProperties({ width: 275 }).component(); + this.targetTextBox.onTextChanged(() => { + this.dialog.okButton.enabled = this.shouldEnableOkayButton(); + }); + this.sourceServerComponent = await this.createSourceServerDropdown(view); await this.populateServerDropdown(false); @@ -288,6 +299,7 @@ export class SchemaCompareDialog { this.formBuilder.removeFormItem(this.sourceServerComponent); this.formBuilder.removeFormItem(this.sourceDatabaseComponent); this.formBuilder.insertFormItem(this.sourceDacpacComponent, 2, { horizontal: true, titleFontSize: titleFontSize }); + this.dialog.okButton.enabled = this.shouldEnableOkayButton(); }); // show server and db dropdowns or 'No active connections' text @@ -300,6 +312,7 @@ export class SchemaCompareDialog { this.formBuilder.insertFormItem(this.sourceNoActiveConnectionsText, 2, { horizontal: true, titleFontSize: titleFontSize }); } this.formBuilder.removeFormItem(this.sourceDacpacComponent); + this.dialog.okButton.enabled = this.shouldEnableOkayButton(); }); if (this.database) { @@ -340,6 +353,7 @@ export class SchemaCompareDialog { this.formBuilder.removeFormItem(this.targetServerComponent); this.formBuilder.removeFormItem(this.targetDatabaseComponent); this.formBuilder.addFormItem(this.targetDacpacComponent, { horizontal: true, titleFontSize: titleFontSize }); + this.dialog.okButton.enabled = this.shouldEnableOkayButton(); }); // show server and db dropdowns or 'No active connections' text @@ -352,6 +366,7 @@ export class SchemaCompareDialog { } else { this.formBuilder.addFormItem(this.targetNoActiveConnectionsText, { horizontal: true, titleFontSize: titleFontSize }); } + this.dialog.okButton.enabled = this.shouldEnableOkayButton(); }); dacpacRadioButton.checked = true; @@ -367,6 +382,17 @@ export class SchemaCompareDialog { }; } + private shouldEnableOkayButton(): boolean { + let sourcefilled = (this.sourceIsDacpac && this.existsDacpac(this.sourceTextBox.value)) || (!this.sourceIsDacpac && !isNullOrUndefined(this.sourceDatabaseDropdown.value)); + let targetfilled = (this.targetIsDacpac && this.existsDacpac(this.targetTextBox.value)) || (!this.targetIsDacpac && !isNullOrUndefined(this.targetDatabaseDropdown.value)); + + return sourcefilled && targetfilled; + } + + private existsDacpac(filename: string): boolean { + return !isNullOrUndefined(filename) && existsSync(filename) && (filename.toLocaleLowerCase().endsWith('.dacpac')); + } + protected async createSourceServerDropdown(view: azdata.ModelView): Promise { this.sourceServerDropdown = view.modelBuilder.dropDown().component(); this.sourceServerDropdown.onValueChanged(async () => { @@ -454,6 +480,9 @@ export class SchemaCompareDialog { protected async createSourceDatabaseDropdown(view: azdata.ModelView): Promise { this.sourceDatabaseDropdown = view.modelBuilder.dropDown().component(); + this.sourceDatabaseDropdown.onValueChanged(() => { + this.dialog.okButton.enabled = this.shouldEnableOkayButton(); + }); return { component: this.sourceDatabaseDropdown, @@ -463,6 +492,9 @@ export class SchemaCompareDialog { protected async createTargetDatabaseDropdown(view: azdata.ModelView): Promise { this.targetDatabaseDropdown = view.modelBuilder.dropDown().component(); + this.targetDatabaseDropdown.onValueChanged(() => { + this.dialog.okButton.enabled = this.shouldEnableOkayButton(); + }); return { component: this.targetDatabaseDropdown,