diff --git a/extensions/dacpac/src/wizard/api/dacFxConfigPage.ts b/extensions/dacpac/src/wizard/api/dacFxConfigPage.ts index c6e0e9f7ca..ab8eef71fa 100644 --- a/extensions/dacpac/src/wizard/api/dacFxConfigPage.ts +++ b/extensions/dacpac/src/wizard/api/dacFxConfigPage.ts @@ -6,6 +6,7 @@ import * as azdata from 'azdata'; import * as nls from 'vscode-nls'; +import * as vscode from 'vscode'; import * as os from 'os'; import * as path from 'path'; import { DataTierApplicationWizard } from '../dataTierApplicationWizard'; @@ -101,7 +102,7 @@ export abstract class DacFxConfigPage extends BasePage { // Handle database changes this.databaseDropdown.onValueChanged(async () => { this.model.database = (this.databaseDropdown.value).name; - this.fileTextBox.value = this.generateFilePath(); + this.fileTextBox.value = this.generateFilePathFromDatabaseAndTimestamp(); this.model.filePath = this.fileTextBox.value; }); @@ -124,7 +125,7 @@ export abstract class DacFxConfigPage extends BasePage { let values = await this.getDatabaseValues(); this.model.database = values[0].name; - this.model.filePath = this.generateFilePath(); + this.model.filePath = this.generateFilePathFromDatabaseAndTimestamp(); this.fileTextBox.value = this.model.filePath; this.databaseDropdown.updateProperties({ @@ -145,10 +146,18 @@ export abstract class DacFxConfigPage extends BasePage { }).component(); } - protected generateFilePath(): string { + protected generateFilePathFromDatabaseAndTimestamp(): string { + return path.join(this.getRootPath(), this.model.database + '-' + this.getDateTime() + this.fileExtension); + } + + protected getDateTime(): string { let now = new Date(); - let datetime = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes(); - return path.join(os.homedir(), this.model.database + '-' + datetime + this.fileExtension); + return now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes(); + } + + protected getRootPath(): string { + // return rootpath of opened folder in file explorer if one is open, otherwise default to user home directory + return vscode.workspace.rootPath ? vscode.workspace.rootPath : os.homedir(); } } diff --git a/extensions/dacpac/src/wizard/pages/deployActionPage.ts b/extensions/dacpac/src/wizard/pages/deployActionPage.ts index 661f7d3881..2d0346faaa 100644 --- a/extensions/dacpac/src/wizard/pages/deployActionPage.ts +++ b/extensions/dacpac/src/wizard/pages/deployActionPage.ts @@ -167,9 +167,7 @@ export class DeployActionPage extends DacFxConfigPage { } private setDefaultScriptFilePath(): void { - let now = new Date(); - let datetime = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes(); - this.fileTextBox.value = path.join(os.homedir(), this.model.database + '_UpgradeDACScript_' + datetime + '.sql'); + this.fileTextBox.value = path.join(this.getRootPath(), this.model.database + '_UpgradeDACScript_' + this.getDateTime() + '.sql'); this.model.scriptFilePath = this.fileTextBox.value; } diff --git a/extensions/dacpac/src/wizard/pages/deployConfigPage.ts b/extensions/dacpac/src/wizard/pages/deployConfigPage.ts index ce43f314d0..535dc5d360 100644 --- a/extensions/dacpac/src/wizard/pages/deployConfigPage.ts +++ b/extensions/dacpac/src/wizard/pages/deployConfigPage.ts @@ -72,7 +72,7 @@ export class DeployConfigPage extends DacFxConfigPage { canSelectFiles: true, canSelectFolders: false, canSelectMany: false, - defaultUri: vscode.Uri.file(os.homedir()), + defaultUri: vscode.Uri.file(this.getRootPath()), openLabel: localize('dacFxDeploy.openFile', 'Open'), filters: { 'dacpac Files': ['dacpac'], diff --git a/extensions/dacpac/src/wizard/pages/exportConfigPage.ts b/extensions/dacpac/src/wizard/pages/exportConfigPage.ts index 2962cd9772..5f7b574652 100644 --- a/extensions/dacpac/src/wizard/pages/exportConfigPage.ts +++ b/extensions/dacpac/src/wizard/pages/exportConfigPage.ts @@ -65,7 +65,7 @@ export class ExportConfigPage extends DacFxConfigPage { this.createFileBrowserParts(); // default filepath - this.fileTextBox.value = this.generateFilePath(); + this.fileTextBox.value = this.generateFilePathFromDatabaseAndTimestamp(); this.model.filePath = this.fileTextBox.value; this.fileButton.onDidClick(async (click) => { diff --git a/extensions/dacpac/src/wizard/pages/extractConfigPage.ts b/extensions/dacpac/src/wizard/pages/extractConfigPage.ts index cce5356580..790fbb6995 100644 --- a/extensions/dacpac/src/wizard/pages/extractConfigPage.ts +++ b/extensions/dacpac/src/wizard/pages/extractConfigPage.ts @@ -68,7 +68,7 @@ export class ExtractConfigPage extends DacFxConfigPage { this.createFileBrowserParts(); // default filepath - this.fileTextBox.value = this.generateFilePath(); + this.fileTextBox.value = this.generateFilePathFromDatabaseAndTimestamp(); this.model.filePath = this.fileTextBox.value; this.fileButton.onDidClick(async (click) => { diff --git a/extensions/dacpac/src/wizard/pages/importConfigPage.ts b/extensions/dacpac/src/wizard/pages/importConfigPage.ts index 1e8699d1c1..3a5e5f7c46 100644 --- a/extensions/dacpac/src/wizard/pages/importConfigPage.ts +++ b/extensions/dacpac/src/wizard/pages/importConfigPage.ts @@ -62,7 +62,7 @@ export class ImportConfigPage extends DacFxConfigPage { canSelectFiles: true, canSelectFolders: false, canSelectMany: false, - defaultUri: vscode.Uri.file(os.homedir()), + defaultUri: vscode.Uri.file(this.getRootPath()), openLabel: localize('dacFxImport.openFile', 'Open'), filters: { 'bacpac Files': ['bacpac'], diff --git a/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts b/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts index 8dd507b3c1..5e49b71ace 100644 --- a/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts +++ b/extensions/schema-compare/src/dialogs/schemaCompareDialog.ts @@ -208,12 +208,13 @@ export class SchemaCompareDialog { let currentButton = isTarget ? this.targetFileButton : this.sourceFileButton; currentButton.onDidClick(async (click) => { + let rootPath = vscode.workspace.rootPath ? vscode.workspace.rootPath : os.homedir(); let fileUris = await vscode.window.showOpenDialog( { canSelectFiles: true, canSelectFolders: false, canSelectMany: false, - defaultUri: vscode.Uri.file(os.homedir()), + defaultUri: vscode.Uri.file(rootPath), openLabel: localize('schemaCompare.openFile', 'Open'), filters: { 'dacpac Files': ['dacpac'], diff --git a/extensions/schema-compare/src/schemaCompareResult.ts b/extensions/schema-compare/src/schemaCompareResult.ts index eef825174d..db44596301 100644 --- a/extensions/schema-compare/src/schemaCompareResult.ts +++ b/extensions/schema-compare/src/schemaCompareResult.ts @@ -291,7 +291,8 @@ export class SchemaCompareResult { // get file path let now = new Date(); let datetime = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes() + '-' + now.getSeconds(); - let defaultFilePath = path.join(os.homedir(), this.targetName + '_Update_' + datetime + '.sql'); + let rootPath = vscode.workspace.rootPath ? vscode.workspace.rootPath : os.homedir(); + let defaultFilePath = path.join(rootPath, this.targetName + '_Update_' + datetime + '.sql'); let fileUri = await vscode.window.showSaveDialog( { defaultUri: vscode.Uri.file(defaultFilePath),