Skip to content

Commit a296996

Browse files
authored
restore notebook toolbar under jlab4 - fix for issue #1107 (#1109)
* the beginning of a fix for #1107 indeed with jlab4 we need to duplicate the code that creates the notebook toolbar this version is much nicer already, but still builds an incomplete toolbar * using the right config solves #1107 * minor cleanup
1 parent 6747cd6 commit a296996

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

jupytext/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Jupytext's version number"""
22

3-
__version__ = "1.15.0.dev1"
3+
__version__ = "1.15.0.dev2"

packages/labextension/src/index.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import {
77
ICommandPalette,
88
ISessionContextDialogs,
99
showErrorMessage,
10+
IToolbarWidgetRegistry,
11+
createToolbarFactory,
1012
} from "@jupyterlab/apputils";
1113

14+
import { ISettingRegistry } from '@jupyterlab/settingregistry';
15+
1216
import { IEditorServices } from "@jupyterlab/codeeditor";
1317

1418
import * as nbformat from "@jupyterlab/nbformat";
@@ -202,6 +206,11 @@ const extension: JupyterFrontEndPlugin<void> = {
202206
ISessionContextDialogs,
203207
INotebookWidgetFactory,
204208
INotebookTracker,
209+
ISettingRegistry,
210+
IToolbarWidgetRegistry,
211+
ICommandPalette,
212+
ITranslator,
213+
205214
],
206215
activate: (
207216
app: JupyterFrontEnd,
@@ -211,8 +220,10 @@ const extension: JupyterFrontEndPlugin<void> = {
211220
sessionContextDialogs: ISessionContextDialogs,
212221
notebookFactory: NotebookWidgetFactory.IFactory,
213222
notebookTracker: INotebookTracker,
223+
settingRegistry: ISettingRegistry | null,
224+
toolbarRegistry: IToolbarWidgetRegistry,
225+
palette: ICommandPalette | null,
214226
translator: ITranslator | null,
215-
palette: ICommandPalette | null
216227
) => {
217228
// https://semver.org/#semantic-versioning-specification-semver
218229
// npm semver requires pre-release versions to come with a hyphen
@@ -225,8 +236,8 @@ const extension: JupyterFrontEndPlugin<void> = {
225236
JLAB4 = parseInt(app_numbers[0]) >= 4;
226237
}
227238
}
228-
console.log("JupyterLab extension jupytext is activated!");
229-
console.debug(`JLAB4=${JLAB4}`);
239+
console.log("JupyterLab extension jupytext is activating...");
240+
console.debug(`bundled jupytext labextension: JLAB4=${JLAB4}`);
230241
const trans = (translator ?? nullTranslator).load("jupytext");
231242

232243
// Jupytext formats
@@ -492,6 +503,26 @@ const extension: JupyterFrontEndPlugin<void> = {
492503
icon: markdownIcon
493504
});
494505

506+
// the way to create the toolbar factory is different in JupyterLab 3 and 4
507+
let toolbarFactory
508+
if (! JLAB4) {
509+
toolbarFactory = notebookFactory.toolbarFactory
510+
} else {
511+
// primarily this block is copied/pasted from jlab4 code and specifically
512+
// jupyterlab/packages/notebook-extension/src/index.ts
513+
// inside the function `activateWidgetFactory` at line 1150 as of this writing
514+
//
515+
const FACTORY = 'Notebook';
516+
const PANEL_SETTINGS = '@jupyterlab/notebook-extension:panel';
517+
518+
toolbarFactory = createToolbarFactory(
519+
toolbarRegistry,
520+
settingRegistry,
521+
FACTORY,
522+
PANEL_SETTINGS,
523+
translator
524+
)
525+
}
495526
// Duplicate notebook factory to apply it on Jupytext notebooks
496527
// Mirror: https://github.com/jupyterlab/jupyterlab/blob/8a8c3752564f37493d4eb6b4c59008027fa83880/packages/notebook-extension/src/index.ts#L860
497528
const factory = new NotebookWidgetFactory({
@@ -507,7 +538,7 @@ const extension: JupyterFrontEndPlugin<void> = {
507538
notebookConfig: notebookFactory.notebookConfig,
508539
mimeTypeService: editorServices.mimeTypeService,
509540
// sessionDialogs: sessionContextDialogs,
510-
toolbarFactory: notebookFactory.toolbarFactory,
541+
toolbarFactory: toolbarFactory,
511542
// translator?: ITranslator,
512543
} as NotebookWidgetFactory.IOptions<NotebookPanel>);
513544
app.docRegistry.addWidgetFactory(factory);

0 commit comments

Comments
 (0)