@@ -10,7 +10,7 @@ import { IApplicationShell, ICommandManager } from '../../common/application/typ
10
10
import { IDisposable } from '../../common/types' ;
11
11
import { Commands } from '../constants' ;
12
12
import { ExportFormat , ExportManager , IExportManager } from '../export/exportManager' ;
13
- import { INotebookEditorProvider } from '../types' ;
13
+ import { INotebookModel } from '../types' ;
14
14
15
15
interface IExportQuickPickItem extends QuickPickItem {
16
16
handler ( ) : void ;
@@ -22,14 +22,13 @@ export class ExportCommands implements IDisposable {
22
22
constructor (
23
23
@inject ( ICommandManager ) private readonly commandManager : ICommandManager ,
24
24
@inject ( IExportManager ) private exportManager : ExportManager ,
25
- @inject ( INotebookEditorProvider ) private notebookEditorProvider : INotebookEditorProvider ,
26
25
@inject ( IApplicationShell ) private readonly applicationShell : IApplicationShell
27
26
) { }
28
27
public register ( ) {
29
- this . registerCommand ( Commands . ExportAsPythonScript , ( ) => this . export ( ExportFormat . python ) ) ;
30
- this . registerCommand ( Commands . ExportToHTML , ( ) => this . export ( ExportFormat . html ) ) ;
31
- this . registerCommand ( Commands . ExportToPDF , ( ) => this . export ( ExportFormat . pdf ) ) ;
32
- this . registerCommand ( Commands . Export , this . export ) ;
28
+ this . registerCommand ( Commands . ExportAsPythonScript , ( model ) => this . export ( model , ExportFormat . python ) ) ;
29
+ this . registerCommand ( Commands . ExportToHTML , ( model ) => this . export ( model , ExportFormat . html ) ) ;
30
+ this . registerCommand ( Commands . ExportToPDF , ( model ) => this . export ( model , ExportFormat . pdf ) ) ;
31
+ this . registerCommand ( Commands . Export , ( model ) => this . export ( model ) ) ;
33
32
}
34
33
35
34
public dispose ( ) {
@@ -45,37 +44,31 @@ export class ExportCommands implements IDisposable {
45
44
this . disposables . push ( disposable ) ;
46
45
}
47
46
48
- private async export ( exportMethod ?: ExportFormat ) {
49
- // get notebook provider
50
- const model = this . notebookEditorProvider . activeEditor ?. model ;
51
- if ( ! model ) {
52
- throw Error ( 'No active editor found.' ) ;
53
- }
54
-
47
+ private async export ( model : INotebookModel , exportMethod ?: ExportFormat ) {
55
48
if ( exportMethod ) {
56
49
await this . exportManager . export ( exportMethod , model ) ;
57
50
} else {
58
- const pickedItem = await this . showExportQuickPickMenu ( ) . then ( ( item ) => item ) ;
51
+ const pickedItem = await this . showExportQuickPickMenu ( model ) . then ( ( item ) => item ) ;
59
52
if ( pickedItem !== undefined ) {
60
53
pickedItem . handler ( ) ;
61
54
}
62
55
}
63
56
}
64
57
65
- private getExportQuickPickItems ( ) : IExportQuickPickItem [ ] {
58
+ private getExportQuickPickItems ( model : INotebookModel ) : IExportQuickPickItem [ ] {
66
59
return [
67
60
{
68
61
label : 'Python Script' ,
69
62
picked : true ,
70
- handler : ( ) => this . commandManager . executeCommand ( Commands . ExportAsPythonScript )
63
+ handler : ( ) => this . commandManager . executeCommand ( Commands . ExportAsPythonScript , model )
71
64
}
72
65
//{ label: 'HTML', picked: false, handler: () => this.commandManager.executeCommand(Commands.ExportToHTML) },
73
66
//{ label: 'PDF', picked: false, handler: () => this.commandManager.executeCommand(Commands.ExportToPDF) }
74
67
] ;
75
68
}
76
69
77
- private async showExportQuickPickMenu ( ) : Promise < IExportQuickPickItem | undefined > {
78
- const items = this . getExportQuickPickItems ( ) ;
70
+ private async showExportQuickPickMenu ( model : INotebookModel ) : Promise < IExportQuickPickItem | undefined > {
71
+ const items = this . getExportQuickPickItems ( model ) ;
79
72
80
73
const options : QuickPickOptions = {
81
74
ignoreFocusOut : false ,
0 commit comments