Skip to content

Commit

Permalink
restore notebook toolbar under jlab4 - fix for issue #1107 (#1109)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
parmentelat authored Jul 28, 2023
1 parent 6747cd6 commit a296996
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jupytext/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Jupytext's version number"""

__version__ = "1.15.0.dev1"
__version__ = "1.15.0.dev2"
39 changes: 35 additions & 4 deletions packages/labextension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import {
ICommandPalette,
ISessionContextDialogs,
showErrorMessage,
IToolbarWidgetRegistry,
createToolbarFactory,
} from "@jupyterlab/apputils";

import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { IEditorServices } from "@jupyterlab/codeeditor";

import * as nbformat from "@jupyterlab/nbformat";
Expand Down Expand Up @@ -202,6 +206,11 @@ const extension: JupyterFrontEndPlugin<void> = {
ISessionContextDialogs,
INotebookWidgetFactory,
INotebookTracker,
ISettingRegistry,
IToolbarWidgetRegistry,
ICommandPalette,
ITranslator,

],
activate: (
app: JupyterFrontEnd,
Expand All @@ -211,8 +220,10 @@ const extension: JupyterFrontEndPlugin<void> = {
sessionContextDialogs: ISessionContextDialogs,
notebookFactory: NotebookWidgetFactory.IFactory,
notebookTracker: INotebookTracker,
settingRegistry: ISettingRegistry | null,
toolbarRegistry: IToolbarWidgetRegistry,
palette: ICommandPalette | null,
translator: ITranslator | null,
palette: ICommandPalette | null
) => {
// https://semver.org/#semantic-versioning-specification-semver
// npm semver requires pre-release versions to come with a hyphen
Expand All @@ -225,8 +236,8 @@ const extension: JupyterFrontEndPlugin<void> = {
JLAB4 = parseInt(app_numbers[0]) >= 4;
}
}
console.log("JupyterLab extension jupytext is activated!");
console.debug(`JLAB4=${JLAB4}`);
console.log("JupyterLab extension jupytext is activating...");
console.debug(`bundled jupytext labextension: JLAB4=${JLAB4}`);
const trans = (translator ?? nullTranslator).load("jupytext");

// Jupytext formats
Expand Down Expand Up @@ -492,6 +503,26 @@ const extension: JupyterFrontEndPlugin<void> = {
icon: markdownIcon
});

// the way to create the toolbar factory is different in JupyterLab 3 and 4
let toolbarFactory
if (! JLAB4) {
toolbarFactory = notebookFactory.toolbarFactory
} else {
// primarily this block is copied/pasted from jlab4 code and specifically
// jupyterlab/packages/notebook-extension/src/index.ts
// inside the function `activateWidgetFactory` at line 1150 as of this writing
//
const FACTORY = 'Notebook';
const PANEL_SETTINGS = '@jupyterlab/notebook-extension:panel';

toolbarFactory = createToolbarFactory(
toolbarRegistry,
settingRegistry,
FACTORY,
PANEL_SETTINGS,
translator
)
}
// Duplicate notebook factory to apply it on Jupytext notebooks
// Mirror: https://github.com/jupyterlab/jupyterlab/blob/8a8c3752564f37493d4eb6b4c59008027fa83880/packages/notebook-extension/src/index.ts#L860
const factory = new NotebookWidgetFactory({
Expand All @@ -507,7 +538,7 @@ const extension: JupyterFrontEndPlugin<void> = {
notebookConfig: notebookFactory.notebookConfig,
mimeTypeService: editorServices.mimeTypeService,
// sessionDialogs: sessionContextDialogs,
toolbarFactory: notebookFactory.toolbarFactory,
toolbarFactory: toolbarFactory,
// translator?: ITranslator,
} as NotebookWidgetFactory.IOptions<NotebookPanel>);
app.docRegistry.addWidgetFactory(factory);
Expand Down

0 comments on commit a296996

Please sign in to comment.