@@ -7,8 +7,12 @@ import {
7
7
ICommandPalette ,
8
8
ISessionContextDialogs ,
9
9
showErrorMessage ,
10
+ IToolbarWidgetRegistry ,
11
+ createToolbarFactory ,
10
12
} from "@jupyterlab/apputils" ;
11
13
14
+ import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
15
+
12
16
import { IEditorServices } from "@jupyterlab/codeeditor" ;
13
17
14
18
import * as nbformat from "@jupyterlab/nbformat" ;
@@ -202,6 +206,11 @@ const extension: JupyterFrontEndPlugin<void> = {
202
206
ISessionContextDialogs ,
203
207
INotebookWidgetFactory ,
204
208
INotebookTracker ,
209
+ ISettingRegistry ,
210
+ IToolbarWidgetRegistry ,
211
+ ICommandPalette ,
212
+ ITranslator ,
213
+
205
214
] ,
206
215
activate : (
207
216
app : JupyterFrontEnd ,
@@ -211,8 +220,10 @@ const extension: JupyterFrontEndPlugin<void> = {
211
220
sessionContextDialogs : ISessionContextDialogs ,
212
221
notebookFactory : NotebookWidgetFactory . IFactory ,
213
222
notebookTracker : INotebookTracker ,
223
+ settingRegistry : ISettingRegistry | null ,
224
+ toolbarRegistry : IToolbarWidgetRegistry ,
225
+ palette : ICommandPalette | null ,
214
226
translator : ITranslator | null ,
215
- palette : ICommandPalette | null
216
227
) => {
217
228
// https://semver.org/#semantic-versioning-specification-semver
218
229
// npm semver requires pre-release versions to come with a hyphen
@@ -225,8 +236,8 @@ const extension: JupyterFrontEndPlugin<void> = {
225
236
JLAB4 = parseInt ( app_numbers [ 0 ] ) >= 4 ;
226
237
}
227
238
}
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 } ` ) ;
230
241
const trans = ( translator ?? nullTranslator ) . load ( "jupytext" ) ;
231
242
232
243
// Jupytext formats
@@ -492,6 +503,26 @@ const extension: JupyterFrontEndPlugin<void> = {
492
503
icon : markdownIcon
493
504
} ) ;
494
505
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
+ }
495
526
// Duplicate notebook factory to apply it on Jupytext notebooks
496
527
// Mirror: https://github.com/jupyterlab/jupyterlab/blob/8a8c3752564f37493d4eb6b4c59008027fa83880/packages/notebook-extension/src/index.ts#L860
497
528
const factory = new NotebookWidgetFactory ( {
@@ -507,7 +538,7 @@ const extension: JupyterFrontEndPlugin<void> = {
507
538
notebookConfig : notebookFactory . notebookConfig ,
508
539
mimeTypeService : editorServices . mimeTypeService ,
509
540
// sessionDialogs: sessionContextDialogs,
510
- toolbarFactory : notebookFactory . toolbarFactory ,
541
+ toolbarFactory : toolbarFactory ,
511
542
// translator?: ITranslator,
512
543
} as NotebookWidgetFactory . IOptions < NotebookPanel > ) ;
513
544
app . docRegistry . addWidgetFactory ( factory ) ;
0 commit comments