mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-05 09:35:39 -05:00
Fix export results default save location (#18224)
* Fix export results default save location * cleanup
This commit is contained in:
@@ -9,14 +9,12 @@ import { URI } from 'vs/base/common/uri';
|
|||||||
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||||
import { Schemas } from 'vs/base/common/network';
|
import { Schemas } from 'vs/base/common/network';
|
||||||
|
|
||||||
export const FILE_SCHEMA: string = 'file';
|
|
||||||
|
|
||||||
export function resolveCurrentDirectory(uri: string, rootPath?: string): string | undefined {
|
export function resolveCurrentDirectory(uri: string, rootPath?: string): string | undefined {
|
||||||
let sqlUri = URI.parse(uri);
|
let sqlUri = URI.parse(uri);
|
||||||
let currentDirectory: string | undefined;
|
let currentDirectory: string | undefined;
|
||||||
|
|
||||||
// use current directory of the sql file if sql file is saved
|
// use current directory of the sql file if sql file is saved
|
||||||
if (sqlUri.scheme === FILE_SCHEMA) {
|
if (sqlUri.scheme === Schemas.file) {
|
||||||
currentDirectory = dirname(sqlUri.fsPath);
|
currentDirectory = dirname(sqlUri.fsPath);
|
||||||
} else if (sqlUri.scheme === Schemas.untitled) {
|
} else if (sqlUri.scheme === Schemas.untitled) {
|
||||||
// if sql file is unsaved/untitled but a workspace is open use workspace root
|
// if sql file is unsaved/untitled but a workspace is open use workspace root
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
|
|||||||
import { IFileDialogService, FileFilter } from 'vs/platform/dialogs/common/dialogs';
|
import { IFileDialogService, FileFilter } from 'vs/platform/dialogs/common/dialogs';
|
||||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||||
import { IQueryEditorConfiguration } from 'sql/platform/query/common/query';
|
import { IQueryEditorConfiguration } from 'sql/platform/query/common/query';
|
||||||
|
import { Schemas } from 'vs/base/common/network';
|
||||||
|
|
||||||
let prevSavePath: URI;
|
let prevSavePath: URI;
|
||||||
|
|
||||||
@@ -99,23 +100,23 @@ export class ResultSerializer {
|
|||||||
return getRootPath(this._contextService);
|
return getRootPath(this._contextService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private promptForFilepath(format: SaveFormat, resourceUri: string): Promise<URI | undefined> {
|
private async promptForFilepath(format: SaveFormat, resourceUri: string): Promise<URI | undefined> {
|
||||||
let filepathPlaceHolder = prevSavePath ? path.dirname(prevSavePath.fsPath) : resolveCurrentDirectory(resourceUri, this.rootPath);
|
let filepathPlaceHolder = prevSavePath ? path.dirname(prevSavePath.fsPath) : resolveCurrentDirectory(resourceUri, this.rootPath);
|
||||||
if (filepathPlaceHolder) {
|
if (!filepathPlaceHolder) {
|
||||||
filepathPlaceHolder = path.join(filepathPlaceHolder, this.getResultsDefaultFilename(format));
|
// If we haven't saved previously and there isn't a file path associated with this resource (e.g. for untitled files)
|
||||||
|
// then fall back to the system default
|
||||||
|
filepathPlaceHolder = (await this.fileDialogService.defaultFilePath(Schemas.file)).fsPath;
|
||||||
}
|
}
|
||||||
|
filepathPlaceHolder = path.join(filepathPlaceHolder, this.getResultsDefaultFilename(format));
|
||||||
return this.fileDialogService.showSaveDialog({
|
const fileUri = await this.fileDialogService.showSaveDialog({
|
||||||
title: nls.localize('resultsSerializer.saveAsFileTitle', "Choose Results File"),
|
title: nls.localize('resultsSerializer.saveAsFileTitle', "Choose Results File"),
|
||||||
defaultUri: filepathPlaceHolder ? URI.file(filepathPlaceHolder) : undefined,
|
defaultUri: filepathPlaceHolder ? URI.file(filepathPlaceHolder) : undefined,
|
||||||
filters: this.getResultsFileExtension(format)
|
filters: this.getResultsFileExtension(format)
|
||||||
}).then(filePath => {
|
|
||||||
if (filePath) {
|
|
||||||
prevSavePath = filePath;
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
});
|
});
|
||||||
|
if (fileUri) {
|
||||||
|
prevSavePath = fileUri;
|
||||||
|
}
|
||||||
|
return fileUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getResultsDefaultFilename(format: SaveFormat): string {
|
private getResultsDefaultFilename(format: SaveFormat): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user