Skip to content

Commit e3dae15

Browse files
committed
removed notebookeditorprovider as dependency
1 parent 8b65f32 commit e3dae15

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

src/client/common/application/commands.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { CancellationToken, Position, TextDocument, Uri } from 'vscode';
77
import { Commands as LSCommands } from '../../activation/languageServer/constants';
88
import { Commands as DSCommands } from '../../datascience/constants';
9-
import { INotebook } from '../../datascience/types';
9+
import { INotebook, INotebookModel } from '../../datascience/types';
1010
import { CommandSource } from '../../testing/common/constants';
1111
import { TestFunction, TestsToRun } from '../../testing/common/types';
1212
import { TestDataItem, TestWorkspaceFolder } from '../../testing/types';
@@ -168,10 +168,10 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
168168
[DSCommands.RunCurrentCellAndAddBelow]: [string];
169169
[DSCommands.ScrollToCell]: [string, string];
170170
[DSCommands.ViewJupyterOutput]: [];
171-
[DSCommands.ExportAsPythonScript]: [];
172-
[DSCommands.ExportToHTML]: [];
173-
[DSCommands.ExportToPDF]: [];
174-
[DSCommands.Export]: [];
171+
[DSCommands.ExportAsPythonScript]: [INotebookModel];
172+
[DSCommands.ExportToHTML]: [INotebookModel];
173+
[DSCommands.ExportToPDF]: [INotebookModel];
174+
[DSCommands.Export]: [INotebookModel];
175175
[DSCommands.SwitchJupyterKernel]: [INotebook | undefined, 'raw' | 'jupyter'];
176176
[DSCommands.SelectJupyterCommandLine]: [undefined | Uri];
177177
[DSCommands.SaveNotebookNonCustomEditor]: [Uri];

src/client/datascience/commands/exportCommands.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { IApplicationShell, ICommandManager } from '../../common/application/typ
1010
import { IDisposable } from '../../common/types';
1111
import { Commands } from '../constants';
1212
import { ExportFormat, ExportManager, IExportManager } from '../export/exportManager';
13-
import { INotebookEditorProvider } from '../types';
13+
import { INotebookModel } from '../types';
1414

1515
interface IExportQuickPickItem extends QuickPickItem {
1616
handler(): void;
@@ -22,14 +22,13 @@ export class ExportCommands implements IDisposable {
2222
constructor(
2323
@inject(ICommandManager) private readonly commandManager: ICommandManager,
2424
@inject(IExportManager) private exportManager: ExportManager,
25-
@inject(INotebookEditorProvider) private notebookEditorProvider: INotebookEditorProvider,
2625
@inject(IApplicationShell) private readonly applicationShell: IApplicationShell
2726
) {}
2827
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));
3332
}
3433

3534
public dispose() {
@@ -45,37 +44,31 @@ export class ExportCommands implements IDisposable {
4544
this.disposables.push(disposable);
4645
}
4746

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) {
5548
if (exportMethod) {
5649
await this.exportManager.export(exportMethod, model);
5750
} else {
58-
const pickedItem = await this.showExportQuickPickMenu().then((item) => item);
51+
const pickedItem = await this.showExportQuickPickMenu(model).then((item) => item);
5952
if (pickedItem !== undefined) {
6053
pickedItem.handler();
6154
}
6255
}
6356
}
6457

65-
private getExportQuickPickItems(): IExportQuickPickItem[] {
58+
private getExportQuickPickItems(model: INotebookModel): IExportQuickPickItem[] {
6659
return [
6760
{
6861
label: 'Python Script',
6962
picked: true,
70-
handler: () => this.commandManager.executeCommand(Commands.ExportAsPythonScript)
63+
handler: () => this.commandManager.executeCommand(Commands.ExportAsPythonScript, model)
7164
}
7265
//{ label: 'HTML', picked: false, handler: () => this.commandManager.executeCommand(Commands.ExportToHTML) },
7366
//{ label: 'PDF', picked: false, handler: () => this.commandManager.executeCommand(Commands.ExportToPDF) }
7467
];
7568
}
7669

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);
7972

8073
const options: QuickPickOptions = {
8174
ignoreFocusOut: false,

src/client/datascience/export/exportManagerFileOpener.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class ExportManagerFileOpener implements IExportManager {
1515
) {}
1616

1717
public async export(format: ExportFormat, model: INotebookModel): Promise<Uri | undefined> {
18-
const reporter = this.progressReporter.createProgressIndicator(`Exporting to ${format}`); // TODO: need to localize
18+
const reporter = this.progressReporter.createProgressIndicator(`Exporting to ${format}`); // need to localize
1919
let uri: Uri | undefined;
2020
try {
2121
uri = await this.manager.export(format, model);
@@ -25,7 +25,7 @@ export class ExportManagerFileOpener implements IExportManager {
2525
} finally {
2626
reporter.dispose();
2727
}
28-
// maybe prompt
28+
// maybe prompt before exporting
2929
if (format === ExportFormat.python) {
3030
await this.openPythonFile(uri);
3131
} else {

src/client/datascience/interactive-ipynb/nativeEditor.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,11 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
684684
}
685685

686686
private async exportAs(): Promise<void> {
687-
this.commandManager.executeCommand(Commands.Export);
687+
const activeEditor = this.editorProvider.activeEditor;
688+
if (!activeEditor || !activeEditor.model) {
689+
return;
690+
}
691+
this.commandManager.executeCommand(Commands.Export, activeEditor.model);
688692
}
689693

690694
private logNativeCommand(args: INativeCommand) {

src/test/datascience/nativeEditor.functional.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,11 @@ df.head()`;
613613
// Click export and wait for a document to change
614614
const commandFired = createDeferred();
615615
const commandManager = TypeMoq.Mock.ofType<ICommandManager>();
616+
const editor = TypeMoq.Mock.ofType<INotebookEditorProvider>().object.activeEditor;
617+
const model = editor!.model!;
616618
ioc.serviceManager.rebindInstance<ICommandManager>(ICommandManager, commandManager.object);
617619
commandManager
618-
.setup((cmd) => cmd.executeCommand(Commands.Export))
620+
.setup((cmd) => cmd.executeCommand(Commands.Export, model))
619621
.returns(() => {
620622
commandFired.resolve();
621623
return Promise.resolve();

0 commit comments

Comments
 (0)