4
4
'use strict' ;
5
5
6
6
import { inject , injectable } from 'inversify' ;
7
- import { QuickPickItem , QuickPickOptions } from 'vscode' ;
7
+ import { QuickPickItem , QuickPickOptions , Uri } from 'vscode' ;
8
8
import { getLocString } from '../../../datascience-ui/react-common/locReactSide' ;
9
9
import { ICommandNameArgumentTypeMapping } from '../../common/application/commands' ;
10
10
import { IApplicationShell , ICommandManager } from '../../common/application/types' ;
11
+ import { IFileSystem } from '../../common/platform/types' ;
11
12
import { IDisposable } from '../../common/types' ;
12
13
import { DataScience } from '../../common/utils/localize' ;
14
+ import { isUri } from '../../common/utils/misc' ;
13
15
import { sendTelemetryEvent } from '../../telemetry' ;
14
16
import { Commands , Telemetry } from '../constants' ;
15
17
import { ExportManager } from '../export/exportManager' ;
@@ -27,7 +29,8 @@ export class ExportCommands implements IDisposable {
27
29
@inject ( ICommandManager ) private readonly commandManager : ICommandManager ,
28
30
@inject ( IExportManager ) private exportManager : ExportManager ,
29
31
@inject ( IApplicationShell ) private readonly applicationShell : IApplicationShell ,
30
- @inject ( INotebookEditorProvider ) private readonly notebookProvider : INotebookEditorProvider
32
+ @inject ( INotebookEditorProvider ) private readonly notebookProvider : INotebookEditorProvider ,
33
+ @inject ( IFileSystem ) private readonly fs : IFileSystem
31
34
) { }
32
35
public register ( ) {
33
36
this . registerCommand ( Commands . ExportAsPythonScript , ( model ) => this . export ( model , ExportFormat . python ) ) ;
@@ -55,9 +58,22 @@ export class ExportCommands implements IDisposable {
55
58
this . disposables . push ( disposable ) ;
56
59
}
57
60
58
- private async export ( model : INotebookModel , exportMethod ?: ExportFormat , defaultFileName ?: string ) {
61
+ private async export ( modelOrUri : Uri | INotebookModel , exportMethod ?: ExportFormat , defaultFileName ?: string ) {
62
+ defaultFileName = typeof defaultFileName === 'string' ? defaultFileName : undefined ;
63
+ let model : INotebookModel | undefined ;
64
+ if ( modelOrUri && isUri ( modelOrUri ) ) {
65
+ const uri = modelOrUri ;
66
+ const editor = this . notebookProvider . editors . find ( ( item ) =>
67
+ this . fs . arePathsSame ( item . file . fsPath , uri . fsPath )
68
+ ) ;
69
+ if ( editor && editor . model ) {
70
+ model = editor . model ;
71
+ }
72
+ } else {
73
+ model = modelOrUri ;
74
+ }
59
75
if ( ! model ) {
60
- // if no model was passed then this was called from the command pallete ,
76
+ // if no model was passed then this was called from the command palette ,
61
77
// so we need to get the active editor
62
78
const activeEditor = this . notebookProvider . activeEditor ;
63
79
if ( ! activeEditor || ! activeEditor . model ) {
0 commit comments