mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Added feature for opening file after exporting to CSV/XLS/JSON & query files (#2216)
* Fix #746. Added prompt for opening saved file location/file after save. This fix includes saving of JSON/CSV/Excel & saving of a new SQL file. * Changed var to let. Moved code from vs dir to sql. Removed support for showing file location after file save. (Will be moved to another PR). #746
This commit is contained in:
@@ -30,6 +30,8 @@ import { ISlickRange } from 'angular2-slickgrid';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import Severity from 'vs/base/common/severity';
|
import Severity from 'vs/base/common/severity';
|
||||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||||
|
import { getBaseLabel } from 'vs/base/common/labels';
|
||||||
|
import { ShowFileInFolderAction, OpenFileInFolderAction } from 'sql/workbench/common/workspaceActions';
|
||||||
|
|
||||||
let prevSavePath: string;
|
let prevSavePath: string;
|
||||||
|
|
||||||
@@ -289,6 +291,31 @@ 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(paths.dirname(savedFilePath));
|
||||||
|
|
||||||
|
this._notificationService.prompt(
|
||||||
|
Severity.Info,
|
||||||
|
LocalizedConstants.msgSaveSucceeded + savedFilePath,
|
||||||
|
[{
|
||||||
|
label: nls.localize('openLocation', "Open file location"),
|
||||||
|
run: () => {
|
||||||
|
let action = new ShowFileInFolderAction(savedFilePath, label || paths.sep, this._windowsService);
|
||||||
|
action.run();
|
||||||
|
action.dispose();
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
label: nls.localize('openFile', "Open file"),
|
||||||
|
run: () => {
|
||||||
|
let action = new OpenFileInFolderAction(savedFilePath, label || paths.sep, this._windowsService);
|
||||||
|
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
|
||||||
*/
|
*/
|
||||||
@@ -306,10 +333,7 @@ export class ResultSerializer {
|
|||||||
});
|
});
|
||||||
this.logToOutputChannel(LocalizedConstants.msgSaveFailed + result.messages);
|
this.logToOutputChannel(LocalizedConstants.msgSaveFailed + result.messages);
|
||||||
} else {
|
} else {
|
||||||
this._notificationService.notify({
|
this.promptFileSavedNotification(this._filePath);
|
||||||
severity: Severity.Info,
|
|
||||||
message: LocalizedConstants.msgSaveSucceeded + this._filePath
|
|
||||||
});
|
|
||||||
this.logToOutputChannel(LocalizedConstants.msgSaveSucceeded + filePath);
|
this.logToOutputChannel(LocalizedConstants.msgSaveSucceeded + filePath);
|
||||||
this.openSavedFile(this._filePath, format);
|
this.openSavedFile(this._filePath, format);
|
||||||
}
|
}
|
||||||
@@ -329,13 +353,7 @@ 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: string, format: string): void {
|
||||||
if (format === SaveFormat.EXCEL) {
|
if (format !== SaveFormat.EXCEL) {
|
||||||
// This will not open in VSCode as it's treated as binary. Use the native file opener instead
|
|
||||||
// Note: must use filePath here, URI does not open correctly
|
|
||||||
// TODO see if there is an alternative opener that includes error handling
|
|
||||||
let fileUri = URI.from({ scheme: PathUtilities.FILE_SCHEMA, path: filePath });
|
|
||||||
this._windowsService.openExternal(fileUri.toString());
|
|
||||||
} else {
|
|
||||||
let uri = URI.file(filePath);
|
let uri = URI.file(filePath);
|
||||||
this._editorService.openEditor({ resource: uri }).then((result) => {
|
this._editorService.openEditor({ resource: uri }).then((result) => {
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
@IWorkbenchEditorService private _editorService: IWorkbenchEditorService,
|
@IWorkbenchEditorService private _editorService: IWorkbenchEditorService,
|
||||||
@IEditorGroupService private _editorGroupService: IEditorGroupService,
|
@IEditorGroupService private _editorGroupService: IEditorGroupService,
|
||||||
@INotificationService private _notificationService: INotificationService,
|
@INotificationService private _notificationService: INotificationService,
|
||||||
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService
|
||||||
) {
|
) {
|
||||||
QueryEditorService.editorService = _editorService;
|
QueryEditorService.editorService = _editorService;
|
||||||
QueryEditorService.instantiationService = _instantiationService;
|
QueryEditorService.instantiationService = _instantiationService;
|
||||||
|
|||||||
25
src/sql/workbench/common/workspaceActions.ts
Normal file
25
src/sql/workbench/common/workspaceActions.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { TPromise } from 'vs/base/common/winjs.base';
|
||||||
|
import { Action } from 'vs/base/common/actions';
|
||||||
|
import { IWindowsService } from 'vs/platform/windows/common/windows';
|
||||||
|
|
||||||
|
export class ShowFileInFolderAction extends Action {
|
||||||
|
|
||||||
|
constructor(private path: string, label: string, private windowsService: IWindowsService) {
|
||||||
|
super('showItemInFolder.action.id', label);
|
||||||
|
}
|
||||||
|
|
||||||
|
run(): TPromise<void> {
|
||||||
|
return this.windowsService.showItemInFolder(this.path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OpenFileInFolderAction extends Action {
|
||||||
|
|
||||||
|
constructor(private path: string, label: string, private windowsService: IWindowsService) {
|
||||||
|
super('showItemInFolder.action.id', label);
|
||||||
|
}
|
||||||
|
|
||||||
|
run() {
|
||||||
|
return this.windowsService.openExternal(this.path);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user