@@ -24,9 +24,11 @@ import {
24
24
IWidgetTracker
25
25
} from '@jupyterlab/apputils' ;
26
26
27
- import { IMainMenu , JupyterLabMenu } from '@jupyterlab/mainmenu' ;
27
+ import { IMainMenu } from '@jupyterlab/mainmenu' ;
28
28
29
- import { IFileBrowserFactory } from '@jupyterlab/filebrowser' ;
29
+ import { RankedMenu } from '@jupyterlab/ui-components' ;
30
+
31
+ import { IFileBrowserFactory , IDefaultFileBrowser } from '@jupyterlab/filebrowser' ;
30
32
31
33
import { ILauncher } from '@jupyterlab/launcher' ;
32
34
@@ -73,9 +75,15 @@ const extension: JupyterFrontEndPlugin<IDrawioTracker> = {
73
75
74
76
export default extension ;
75
77
78
+ namespace CommandIDs {
79
+ export const redo = 'drawio:command/redo' ;
80
+ export const undo = 'drawio:command/undo' ;
81
+ }
82
+
76
83
function activate (
77
84
app : JupyterFrontEnd ,
78
- browserFactory : IFileBrowserFactory ,
85
+ // browserFactory: IFileBrowserFactory,
86
+ defaultBrowser :IDefaultFileBrowser ,
79
87
restorer : ILayoutRestorer ,
80
88
menu : IMainMenu ,
81
89
palette : ICommandPalette ,
@@ -101,7 +109,7 @@ function activate(
101
109
} ) ;
102
110
103
111
factory . widgetCreated . connect ( ( sender , widget ) => {
104
- widget . title . icon = 'jp-MaterialIcon jp-ImageIcon' ; // TODO change
112
+ widget . title . iconClass = 'jp-MaterialIcon jp-ImageIcon' ; // TODO change
105
113
106
114
// Notify the instance tracker if restore data needs to update.
107
115
widget . context . pathChanged . connect ( ( ) => {
@@ -128,7 +136,7 @@ function activate(
128
136
iconClass : 'jp-MaterialIcon jp-ImageIcon' ,
129
137
caption : 'Create a new diagram file' ,
130
138
execute : ( ) => {
131
- const cwd = browserFactory . defaultBrowser . model . path ;
139
+ const cwd = defaultBrowser . model . path ;
132
140
commands
133
141
. execute ( 'docmanager:new-untitled' , {
134
142
path : cwd ,
@@ -151,7 +159,7 @@ function activate(
151
159
tracker . currentWidget !== null &&
152
160
tracker . currentWidget === app . shell . currentWidget ,
153
161
execute : ( ) => {
154
- const cwd = browserFactory . defaultBrowser . model . path ;
162
+ const cwd = defaultBrowser . model . path ;
155
163
commands
156
164
. execute ( 'docmanager:new-untitled' , {
157
165
path : cwd ,
@@ -177,7 +185,7 @@ function activate(
177
185
}
178
186
179
187
if ( menu ) {
180
- addMenus ( commands , menu , tracker ) ;
188
+ addMenus ( app , commands , menu , tracker ) ;
181
189
}
182
190
183
191
addCommands ( app , tracker ) ;
@@ -195,18 +203,19 @@ function activate(
195
203
}
196
204
197
205
function addMenus (
206
+ app : JupyterFrontEnd ,
198
207
commands : CommandRegistry ,
199
208
menu : IMainMenu ,
200
209
tracker : IDrawioTracker
201
210
) : void {
202
- const diagram = new JupyterLabMenu ( { commands } ) ;
203
- diagram . menu . title . label = 'Diagram' ;
211
+ const diagram = new RankedMenu ( { commands } ) ;
212
+ diagram . rootMenu . title . label = 'Diagram' ;
204
213
205
214
// FILE MENU
206
215
// Add new text file creation to the file menu.
207
216
menu . fileMenu . newMenu . addGroup ( [ { command : 'drawio:create-new' } ] , 40 ) ;
208
- const fileMenu = new JupyterLabMenu ( { commands } ) ;
209
- fileMenu . menu . title . label = 'File' ;
217
+ const fileMenu = new RankedMenu ( { commands } ) ;
218
+ fileMenu . rootMenu . title . label = 'File' ;
210
219
fileMenu . addGroup ( [ { command : 'drawio:create-new' } ] , 0 ) ;
211
220
fileMenu . addGroup (
212
221
[
@@ -216,18 +225,18 @@ function addMenus(
216
225
] ,
217
226
1
218
227
) ;
228
+ const isEnabled = ( ) =>
229
+ tracker . currentWidget !== null &&
230
+ tracker . currentWidget === app . shell . currentWidget ;
219
231
220
232
// Edit MENU
221
- menu . editMenu . undoers . add ( {
222
- tracker,
223
- undo : ( widget : any ) => widget . execute ( 'undo' ) ,
224
- redo : ( widget : any ) => widget . execute ( 'redo' )
225
- } as any ) ;
233
+ menu . editMenu . undoers . undo . add ( { id : CommandIDs . undo , isEnabled} ) ;
234
+ menu . editMenu . undoers . undo . add ( { id : CommandIDs . redo , isEnabled} ) ;
226
235
227
- const editMenu = new JupyterLabMenu ( { commands } ) ;
228
- editMenu . menu . title . label = 'Edit' ;
236
+ const editMenu = new RankedMenu ( { commands } ) ;
237
+ editMenu . rootMenu . title . label = 'Edit' ;
229
238
editMenu . addGroup (
230
- [ { command : 'drawio:command/ undo' } , { command : 'drawio:command/ redo' } ] ,
239
+ [ { command : CommandIDs . undo } , { command : CommandIDs . redo } ] ,
231
240
0
232
241
) ;
233
242
editMenu . addGroup (
@@ -268,8 +277,8 @@ function addMenus(
268
277
editMenu . addGroup ( [ { command : 'drawio:command/lockUnlock' } ] , 7 ) ;
269
278
270
279
// View MENU
271
- const viewMenu = new JupyterLabMenu ( { commands } ) ;
272
- viewMenu . menu . title . label = 'View' ;
280
+ const viewMenu = new RankedMenu ( { commands } ) ;
281
+ viewMenu . rootMenu . title . label = 'View' ;
273
282
viewMenu . addGroup (
274
283
[
275
284
{ command : 'drawio:command/formatPanel' } ,
@@ -313,8 +322,8 @@ function addMenus(
313
322
) ;
314
323
315
324
// Arrange MENU
316
- const arrangeMenu = new JupyterLabMenu ( { commands } ) ;
317
- arrangeMenu . menu . title . label = 'Arrange' ;
325
+ const arrangeMenu = new RankedMenu ( { commands } ) ;
326
+ arrangeMenu . rootMenu . title . label = 'Arrange' ;
318
327
arrangeMenu . addGroup (
319
328
[
320
329
{ command : 'drawio:command/toFront' } ,
@@ -323,23 +332,23 @@ function addMenus(
323
332
0
324
333
) ;
325
334
326
- const direction = new JupyterLabMenu ( { commands } ) ;
327
- direction . menu . title . label = 'Direction' ;
335
+ const direction = new RankedMenu ( { commands } ) ;
336
+ direction . rootMenu . title . label = 'Direction' ;
328
337
direction . addGroup (
329
338
[ { command : 'drawio:command/flipH' } , { command : 'drawio:command/flipV' } ] ,
330
339
0
331
340
) ;
332
341
direction . addGroup ( [ { command : 'drawio:command/rotation' } ] , 1 ) ;
333
342
arrangeMenu . addGroup (
334
343
[
335
- { type : 'submenu' , submenu : direction . menu } ,
344
+ { type : 'submenu' , submenu : direction . rootMenu } ,
336
345
{ command : 'drawio:command/turn' }
337
346
] ,
338
347
1
339
348
) ;
340
349
341
- const align = new JupyterLabMenu ( { commands } ) ;
342
- align . menu . title . label = 'Diagram Align' ;
350
+ const align = new RankedMenu ( { commands } ) ;
351
+ align . rootMenu . title . label = 'Diagram Align' ;
343
352
align . addGroup (
344
353
[
345
354
{ command : 'drawio:command/alignCellsLeft' } ,
@@ -357,8 +366,8 @@ function addMenus(
357
366
1
358
367
) ;
359
368
360
- const distribute = new JupyterLabMenu ( { commands } ) ;
361
- distribute . menu . title . label = 'Distribute' ;
369
+ const distribute = new RankedMenu ( { commands } ) ;
370
+ distribute . rootMenu . title . label = 'Distribute' ;
362
371
distribute . addGroup (
363
372
[
364
373
{ command : 'drawio:command/horizontal' } ,
@@ -368,14 +377,14 @@ function addMenus(
368
377
) ;
369
378
arrangeMenu . addGroup (
370
379
[
371
- { type : 'submenu' , submenu : align . menu } ,
372
- { type : 'submenu' , submenu : distribute . menu }
380
+ { type : 'submenu' , submenu : align . rootMenu } ,
381
+ { type : 'submenu' , submenu : distribute . rootMenu }
373
382
] ,
374
383
2
375
384
) ;
376
385
377
- const navigation = new JupyterLabMenu ( { commands } ) ;
378
- navigation . menu . title . label = 'Navigation' ;
386
+ const navigation = new RankedMenu ( { commands } ) ;
387
+ navigation . rootMenu . title . label = 'Navigation' ;
379
388
navigation . addGroup ( [ { command : 'drawio:command/home' } ] , 0 ) ;
380
389
navigation . addGroup (
381
390
[
@@ -393,8 +402,8 @@ function addMenus(
393
402
) ;
394
403
navigation . addGroup ( [ { command : 'drawio:command/collapsible' } ] , 3 ) ;
395
404
396
- const insert = new JupyterLabMenu ( { commands } ) ;
397
- insert . menu . title . label = 'Insert' ;
405
+ const insert = new RankedMenu ( { commands } ) ;
406
+ insert . rootMenu . title . label = 'Insert' ;
398
407
insert . addGroup (
399
408
[
400
409
{ command : 'drawio:command/insertLink' } ,
@@ -403,8 +412,8 @@ function addMenus(
403
412
0
404
413
) ;
405
414
406
- const layout = new JupyterLabMenu ( { commands } ) ;
407
- layout . menu . title . label = 'Layout' ;
415
+ const layout = new RankedMenu ( { commands } ) ;
416
+ layout . rootMenu . title . label = 'Layout' ;
408
417
layout . addGroup (
409
418
[
410
419
{ command : 'drawio:command/horizontalFlow' } ,
@@ -429,9 +438,9 @@ function addMenus(
429
438
) ;
430
439
arrangeMenu . addGroup (
431
440
[
432
- { type : 'submenu' , submenu : navigation . menu } ,
433
- { type : 'submenu' , submenu : insert . menu } ,
434
- { type : 'submenu' , submenu : layout . menu }
441
+ { type : 'submenu' , submenu : navigation . rootMenu } ,
442
+ { type : 'submenu' , submenu : insert . rootMenu } ,
443
+ { type : 'submenu' , submenu : layout . rootMenu }
435
444
] ,
436
445
3
437
446
) ;
@@ -454,8 +463,8 @@ function addMenus(
454
463
) ;
455
464
456
465
// Extras MENU
457
- const extrasMenu = new JupyterLabMenu ( { commands } ) ;
458
- extrasMenu . menu . title . label = 'Extras' ;
466
+ const extrasMenu = new RankedMenu ( { commands } ) ;
467
+ extrasMenu . rootMenu . title . label = 'Extras' ;
459
468
extrasMenu . addGroup (
460
469
[
461
470
{ command : 'drawio:command/copyConnect' } ,
@@ -467,16 +476,16 @@ function addMenus(
467
476
468
477
diagram . addGroup (
469
478
[
470
- { type : 'submenu' , submenu : fileMenu . menu } ,
471
- { type : 'submenu' , submenu : editMenu . menu } ,
472
- { type : 'submenu' , submenu : viewMenu . menu } ,
473
- { type : 'submenu' , submenu : arrangeMenu . menu } ,
474
- { type : 'submenu' , submenu : extrasMenu . menu } ,
479
+ { type : 'submenu' , submenu : fileMenu . rootMenu } ,
480
+ { type : 'submenu' , submenu : editMenu . rootMenu } ,
481
+ { type : 'submenu' , submenu : viewMenu . rootMenu } ,
482
+ { type : 'submenu' , submenu : arrangeMenu . rootMenu } ,
483
+ { type : 'submenu' , submenu : extrasMenu . rootMenu } ,
475
484
{ command : 'drawio:command/about' }
476
485
] ,
477
486
0
478
487
) ;
479
- menu . addMenu ( diagram . menu , { rank : 60 } ) ;
488
+ menu . addMenu ( diagram . rootMenu , true , { rank : 60 } ) ;
480
489
}
481
490
482
491
function addCommands ( app : JupyterFrontEnd , tracker : IDrawioTracker ) : void {
@@ -571,7 +580,7 @@ function addCommands(app: JupyterFrontEnd, tracker: IDrawioTracker): void {
571
580
}
572
581
} ) ;
573
582
} ) ;
574
- app . commands . addCommand ( 'drawio:command/ undo' , {
583
+ app . commands . addCommand ( CommandIDs . undo , {
575
584
label : 'Undo' ,
576
585
caption : 'Undo (Ctrl+Z)' ,
577
586
icon : undoIcon ,
@@ -596,7 +605,7 @@ function addCommands(app: JupyterFrontEnd, tracker: IDrawioTracker): void {
596
605
}
597
606
}
598
607
} ) ;
599
- app . commands . addCommand ( 'drawio:command/ redo' , {
608
+ app . commands . addCommand ( CommandIDs . redo , {
600
609
label : 'Redo' ,
601
610
caption : 'Redo (Ctrl+Shift+Z)' ,
602
611
icon : redoIcon ,
0 commit comments