@@ -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+
1216import { IEditorServices } from "@jupyterlab/codeeditor" ;
1317
1418import * 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