fix export for remote (#10934)

This commit is contained in:
Anthony Dresser
2020-06-16 12:10:05 -07:00
committed by GitHub
parent ad5c697f87
commit 381a747b62
3 changed files with 17 additions and 86 deletions

View File

@@ -1,32 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Action } from 'vs/base/common/actions';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { URI } from 'vs/base/common/uri';
// eslint-disable-next-line code-layering,code-import-patterns
import { IElectronService } from 'vs/platform/electron/electron-sandbox/electron';
export class ShowFileInFolderAction extends Action {
constructor(private path: string, label: string, @IElectronService private electronService: IElectronService) {
super('showItemInFolder.action.id', label);
}
run(): Promise<void> {
return this.electronService.showItemInFolder(this.path);
}
}
export class OpenFileInFolderAction extends Action {
constructor(private path: string, label: string, @IOpenerService private openerService: IOpenerService) {
super('openItemInFolder.action.id', label);
}
run() {
return this.openerService.open(URI.file(this.path), { openExternal: true });
}
}

View File

@@ -40,6 +40,7 @@ import { Orientation } from 'vs/base/browser/ui/splitview/splitview';
import { ToggleableAction } from 'sql/workbench/contrib/notebook/browser/notebookActions'; import { ToggleableAction } from 'sql/workbench/contrib/notebook/browser/notebookActions';
import { IInsightOptions } from 'sql/workbench/common/editor/query/chartState'; import { IInsightOptions } from 'sql/workbench/common/editor/query/chartState';
import { NotebookChangeType } from 'sql/workbench/services/notebook/common/contracts'; import { NotebookChangeType } from 'sql/workbench/services/notebook/common/contracts';
import { URI } from 'vs/base/common/uri';
@Component({ @Component({
selector: GridOutputComponent.SELECTOR, selector: GridOutputComponent.SELECTOR,
@@ -308,7 +309,7 @@ class DataResourceDataProvider implements IGridDataProvider {
return serializer.handleSerialization(this.documentUri, format, (filePath) => this.doSerialize(serializer, filePath, format, selection)); return serializer.handleSerialization(this.documentUri, format, (filePath) => this.doSerialize(serializer, filePath, format, selection));
} }
private doSerialize(serializer: ResultSerializer, filePath: string, format: SaveFormat, selection: Slick.Range[]): Promise<SaveResultsResponse | undefined> { private doSerialize(serializer: ResultSerializer, filePath: URI, format: SaveFormat, selection: Slick.Range[]): Promise<SaveResultsResponse | undefined> {
if (!this.canSerialize) { if (!this.canSerialize) {
return Promise.resolve(undefined); return Promise.resolve(undefined);
} }
@@ -346,7 +347,7 @@ class DataResourceDataProvider implements IGridDataProvider {
let serializeRequestParams: SerializeDataParams = <SerializeDataParams>assign(serializer.getBasicSaveParameters(format), <Partial<SerializeDataParams>>{ let serializeRequestParams: SerializeDataParams = <SerializeDataParams>assign(serializer.getBasicSaveParameters(format), <Partial<SerializeDataParams>>{
saveFormat: format, saveFormat: format,
columns: columns, columns: columns,
filePath: filePath, filePath: filePath.fsPath,
getRowRange: (rowStart, numberOfRows) => getRows(rowStart, numberOfRows), getRowRange: (rowStart, numberOfRows) => getRows(rowStart, numberOfRows),
rowCount: rowLength rowCount: rowLength
}); });

View File

@@ -13,15 +13,12 @@ import * as nls from 'vs/nls';
import Severity from 'vs/base/common/severity'; import Severity from 'vs/base/common/severity';
import { INotificationService, INotification } from 'vs/platform/notification/common/notification'; import { INotificationService, INotification } from 'vs/platform/notification/common/notification';
import { getBaseLabel } from 'vs/base/common/labels';
import { ShowFileInFolderAction, OpenFileInFolderAction } from 'sql/workbench/common/workspaceActions';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { getRootPath, resolveCurrentDirectory, resolveFilePath } from 'sql/platform/common/pathUtilities'; import { getRootPath, resolveCurrentDirectory } from 'sql/platform/common/pathUtilities';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IFileDialogService, FileFilter } from 'vs/platform/dialogs/common/dialogs'; import { IFileDialogService, FileFilter } from 'vs/platform/dialogs/common/dialogs';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
let prevSavePath: string; let prevSavePath: URI;
export interface ISaveRequest { export interface ISaveRequest {
format: SaveFormat; format: SaveFormat;
@@ -56,7 +53,6 @@ export enum SaveFormat {
} }
const msgSaveFailed = nls.localize('msgSaveFailed', "Failed to save results. "); const msgSaveFailed = nls.localize('msgSaveFailed', "Failed to save results. ");
const msgSaveSucceeded = nls.localize('msgSaveSucceeded', "Successfully saved results to ");
/** /**
* Handles save results request from the context menu of slickGrid * Handles save results request from the context menu of slickGrid
@@ -70,8 +66,7 @@ export class ResultSerializer {
@IEditorService private _editorService: IEditorService, @IEditorService private _editorService: IEditorService,
@IWorkspaceContextService private _contextService: IWorkspaceContextService, @IWorkspaceContextService private _contextService: IWorkspaceContextService,
@IFileDialogService private readonly fileDialogService: IFileDialogService, @IFileDialogService private readonly fileDialogService: IFileDialogService,
@INotificationService private _notificationService: INotificationService, @INotificationService private _notificationService: INotificationService
@IInstantiationService private readonly _instantiationService: IInstantiationService
) { } ) { }
/** /**
@@ -81,9 +76,6 @@ export class ResultSerializer {
const self = this; const self = this;
return this.promptForFilepath(saveRequest.format, uri).then(filePath => { return this.promptForFilepath(saveRequest.format, uri).then(filePath => {
if (filePath) { if (filePath) {
if (!path.isAbsolute(filePath)) {
filePath = resolveFilePath(uri, filePath, this.rootPath)!;
}
let saveResultsParams = this.getParameters(uri, filePath, saveRequest.batchIndex, saveRequest.resultSetNumber, saveRequest.format, saveRequest.selection ? saveRequest.selection[0] : undefined); let saveResultsParams = this.getParameters(uri, filePath, saveRequest.batchIndex, saveRequest.resultSetNumber, saveRequest.format, saveRequest.selection ? saveRequest.selection[0] : undefined);
let sendRequest = () => this.sendSaveRequestToService(saveResultsParams); let sendRequest = () => this.sendSaveRequestToService(saveResultsParams);
return self.doSave(filePath, saveRequest.format, sendRequest); return self.doSave(filePath, saveRequest.format, sendRequest);
@@ -103,14 +95,11 @@ export class ResultSerializer {
/** /**
* Handle save request by getting filename from user and sending request to service * Handle save request by getting filename from user and sending request to service
*/ */
public handleSerialization(uri: string, format: SaveFormat, sendRequest: ((filePath: string) => Promise<SaveResultsResponse | undefined>)): Thenable<void> { public handleSerialization(uri: string, format: SaveFormat, sendRequest: ((filePath: URI) => Promise<SaveResultsResponse | undefined>)): Thenable<void> {
const self = this; const self = this;
return this.promptForFilepath(format, uri).then(filePath => { return this.promptForFilepath(format, uri).then(filePath => {
if (filePath) { if (filePath) {
if (!path.isAbsolute(filePath)) { return self.doSave(filePath, format, () => sendRequest(filePath));
filePath = resolveFilePath(uri, filePath, this.rootPath)!;
}
return self.doSave(filePath, format, () => sendRequest(filePath!));
} }
return Promise.resolve(); return Promise.resolve();
}); });
@@ -120,8 +109,8 @@ export class ResultSerializer {
return getRootPath(this._contextService); return getRootPath(this._contextService);
} }
private promptForFilepath(format: SaveFormat, resourceUri: string): Promise<string | undefined> { private promptForFilepath(format: SaveFormat, resourceUri: string): Promise<URI | undefined> {
let filepathPlaceHolder = prevSavePath ? path.dirname(prevSavePath) : 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)); filepathPlaceHolder = path.join(filepathPlaceHolder, this.getResultsDefaultFilename(format));
} }
@@ -132,8 +121,8 @@ export class ResultSerializer {
filters: this.getResultsFileExtension(format) filters: this.getResultsFileExtension(format)
}).then(filePath => { }).then(filePath => {
if (filePath) { if (filePath) {
prevSavePath = filePath.fsPath; prevSavePath = filePath;
return filePath.fsPath; return filePath;
} }
return undefined; return undefined;
}); });
@@ -271,9 +260,9 @@ export class ResultSerializer {
} }
private getParameters(uri: string, filePath: string, batchIndex: number, resultSetNo: number, format: string, selection?: Slick.Range): SaveResultsRequestParams { private getParameters(uri: string, filePath: URI, batchIndex: number, resultSetNo: number, format: string, selection?: Slick.Range): SaveResultsRequestParams {
let saveResultsParams = this.getBasicSaveParameters(format); let saveResultsParams = this.getBasicSaveParameters(format);
saveResultsParams.filePath = filePath; saveResultsParams.filePath = filePath.fsPath;
saveResultsParams.ownerUri = uri; saveResultsParams.ownerUri = uri;
saveResultsParams.resultSetIndex = resultSetNo; saveResultsParams.resultSetIndex = resultSetNo;
saveResultsParams.batchIndex = batchIndex; saveResultsParams.batchIndex = batchIndex;
@@ -293,35 +282,10 @@ export class ResultSerializer {
return !!(selection && !((selection.fromCell === selection.toCell) && (selection.fromRow === selection.toRow))); return !!(selection && !((selection.fromCell === selection.toCell) && (selection.fromRow === selection.toRow)));
} }
private promptFileSavedNotification(savedFilePath: string) {
let label = getBaseLabel(path.dirname(savedFilePath));
this._notificationService.prompt(
Severity.Info,
msgSaveSucceeded + savedFilePath,
[{
label: nls.localize('openLocation', "Open file location"),
run: () => {
let action = this._instantiationService.createInstance(ShowFileInFolderAction, savedFilePath, label || path.sep);
action.run();
action.dispose();
}
}, {
label: nls.localize('openFile', "Open file"),
run: () => {
let action = this._instantiationService.createInstance(OpenFileInFolderAction, savedFilePath, label || path.sep);
action.run();
action.dispose();
}
}]
);
}
/** /**
* Send request to sql tools service to save a result set * Send request to sql tools service to save a result set
*/ */
private async doSave(filePath: string, format: string, sendRequest: () => Promise<SaveResultsResponse | undefined>): Promise<void> { private async doSave(filePath: URI, format: string, sendRequest: () => Promise<SaveResultsResponse | undefined>): Promise<void> {
const saveNotification: INotification = { const saveNotification: INotification = {
severity: Severity.Info, severity: Severity.Info,
@@ -341,7 +305,6 @@ export class ResultSerializer {
message: msgSaveFailed + (result ? result.messages : '') message: msgSaveFailed + (result ? result.messages : '')
}); });
} else { } else {
this.promptFileSavedNotification(filePath);
this.openSavedFile(filePath, format); this.openSavedFile(filePath, format);
} }
// TODO telemetry for save results // TODO telemetry for save results
@@ -360,10 +323,9 @@ export class ResultSerializer {
/** /**
* Open the saved file in a new vscode editor pane * Open the saved file in a new vscode editor pane
*/ */
private openSavedFile(filePath: string, format: string): void { private openSavedFile(filePath: URI, format: string): void {
if (format !== SaveFormat.EXCEL) { if (format !== SaveFormat.EXCEL) {
let uri = URI.file(filePath); this._editorService.openEditor({ resource: filePath }).then((result) => {
this._editorService.openEditor({ resource: uri }).then((result) => {
}, (error: any) => { }, (error: any) => {
this._notificationService.notify({ this._notificationService.notify({