Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"onCommand:python.viewTestOutput",
"onCommand:python.viewOutput",
"onCommand:python.datascience.viewJupyterOutput",
"onCOmmand:python.datascience.export",
"onCommand:python.datascience.exportAsPythonScript",
"onCommand:python.datascience.exportToHTML",
"onCommand:python.datascience.exportToPDF",
Expand Down Expand Up @@ -361,6 +362,15 @@
"title": "%python.command.python.datascience.viewJupyterOutput.title%",
"category": "Python"
},
{
"command": "python.datascience.export",
"title": "%DataScience.notebookExportAs%",
"category": "Python",
"icon": {
"light": "resources/light/export_to_python.svg",
"dark": "resources/dark/export_to_python.svg"
}
},
{
"command": "python.datascience.exportAsPythonScript",
"title": "%python.command.python.datascience.exportAsPythonScript.title%",
Expand Down Expand Up @@ -849,6 +859,12 @@
"title": "%python.command.python.datascience.restartkernel.title%",
"group": "navigation",
"when": "notebookEditorFocused"
},
{
"command": "python.datascience.export",
"title": "%DataScience.notebookExportAs%",
"group": "navigation",
"when": "notebookEditorFocused"
}
],
"explorer/context": [
Expand Down Expand Up @@ -1236,6 +1252,12 @@
"title": "%DataScience.gatherQuality%",
"category": "Python",
"when": "false"
},
{
"command": "python.datascience.export",
"title": "%DataScience.notebookExportAs%",
"category": "Python",
"when": "false"
}
],
"view/title": [
Expand Down
4 changes: 4 additions & 0 deletions resources/dark/export_to_python.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions resources/light/export_to_python.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/client/common/application/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
[DSCommands.ExportAsPythonScript]: [INotebookModel];
[DSCommands.ExportToHTML]: [INotebookModel, string | undefined];
[DSCommands.ExportToPDF]: [INotebookModel, string | undefined];
[DSCommands.Export]: [INotebookModel, string | undefined];
[DSCommands.Export]: [Uri | INotebookModel, string | undefined];
[DSCommands.SwitchJupyterKernel]: [INotebook | undefined, 'raw' | 'jupyter'];
[DSCommands.SelectJupyterCommandLine]: [undefined | Uri];
[DSCommands.SaveNotebookNonCustomEditor]: [Uri];
Expand Down
24 changes: 20 additions & 4 deletions src/client/datascience/commands/exportCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
'use strict';

import { inject, injectable } from 'inversify';
import { QuickPickItem, QuickPickOptions } from 'vscode';
import { QuickPickItem, QuickPickOptions, Uri } from 'vscode';
import { getLocString } from '../../../datascience-ui/react-common/locReactSide';
import { ICommandNameArgumentTypeMapping } from '../../common/application/commands';
import { IApplicationShell, ICommandManager } from '../../common/application/types';
import { IFileSystem } from '../../common/platform/types';
import { IDisposable } from '../../common/types';
import { DataScience } from '../../common/utils/localize';
import { isUri } from '../../common/utils/misc';
import { sendTelemetryEvent } from '../../telemetry';
import { Commands, Telemetry } from '../constants';
import { ExportManager } from '../export/exportManager';
Expand All @@ -27,7 +29,8 @@ export class ExportCommands implements IDisposable {
@inject(ICommandManager) private readonly commandManager: ICommandManager,
@inject(IExportManager) private exportManager: ExportManager,
@inject(IApplicationShell) private readonly applicationShell: IApplicationShell,
@inject(INotebookEditorProvider) private readonly notebookProvider: INotebookEditorProvider
@inject(INotebookEditorProvider) private readonly notebookProvider: INotebookEditorProvider,
@inject(IFileSystem) private readonly fs: IFileSystem
) {}
public register() {
this.registerCommand(Commands.ExportAsPythonScript, (model) => this.export(model, ExportFormat.python));
Expand Down Expand Up @@ -55,9 +58,22 @@ export class ExportCommands implements IDisposable {
this.disposables.push(disposable);
}

private async export(model: INotebookModel, exportMethod?: ExportFormat, defaultFileName?: string) {
private async export(modelOrUri: Uri | INotebookModel, exportMethod?: ExportFormat, defaultFileName?: string) {
defaultFileName = typeof defaultFileName === 'string' ? defaultFileName : undefined;
let model: INotebookModel | undefined;
if (modelOrUri && isUri(modelOrUri)) {
const uri = modelOrUri;
const editor = this.notebookProvider.editors.find((item) =>
this.fs.arePathsSame(item.file.fsPath, uri.fsPath)
);
if (editor && editor.model) {
model = editor.model;
}
} else {
model = modelOrUri;
}
if (!model) {
// if no model was passed then this was called from the command pallete,
// if no model was passed then this was called from the command palette,
// so we need to get the active editor
const activeEditor = this.notebookProvider.activeEditor;
if (!activeEditor || !activeEditor.model) {
Expand Down