44'use strict' ;
55
66import { inject , injectable } from 'inversify' ;
7- import { QuickPickItem , QuickPickOptions } from 'vscode' ;
7+ import { QuickPickItem , QuickPickOptions , Uri } from 'vscode' ;
88import { getLocString } from '../../../datascience-ui/react-common/locReactSide' ;
99import { ICommandNameArgumentTypeMapping } from '../../common/application/commands' ;
1010import { IApplicationShell , ICommandManager } from '../../common/application/types' ;
11+ import { IFileSystem } from '../../common/platform/types' ;
1112import { IDisposable } from '../../common/types' ;
1213import { DataScience } from '../../common/utils/localize' ;
14+ import { isUri } from '../../common/utils/misc' ;
1315import { sendTelemetryEvent } from '../../telemetry' ;
1416import { Commands , Telemetry } from '../constants' ;
1517import { ExportManager } from '../export/exportManager' ;
@@ -27,7 +29,8 @@ export class ExportCommands implements IDisposable {
2729 @inject ( ICommandManager ) private readonly commandManager : ICommandManager ,
2830 @inject ( IExportManager ) private exportManager : ExportManager ,
2931 @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
3134 ) { }
3235 public register ( ) {
3336 this . registerCommand ( Commands . ExportAsPythonScript , ( model ) => this . export ( model , ExportFormat . python ) ) ;
@@ -55,9 +58,22 @@ export class ExportCommands implements IDisposable {
5558 this . disposables . push ( disposable ) ;
5659 }
5760
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+ }
5975 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 ,
6177 // so we need to get the active editor
6278 const activeEditor = this . notebookProvider . activeEditor ;
6379 if ( ! activeEditor || ! activeEditor . model ) {
0 commit comments