@@ -24,9 +24,11 @@ import {
2424 IWidgetTracker
2525} from '@jupyterlab/apputils' ;
2626
27- import { IMainMenu , JupyterLabMenu } from '@jupyterlab/mainmenu' ;
27+ import { IMainMenu } from '@jupyterlab/mainmenu' ;
2828
29- import { IFileBrowserFactory } from '@jupyterlab/filebrowser' ;
29+ import { RankedMenu } from '@jupyterlab/ui-components' ;
30+
31+ import { IFileBrowserFactory , IDefaultFileBrowser } from '@jupyterlab/filebrowser' ;
3032
3133import { ILauncher } from '@jupyterlab/launcher' ;
3234
@@ -73,9 +75,15 @@ const extension: JupyterFrontEndPlugin<IDrawioTracker> = {
7375
7476export default extension ;
7577
78+ namespace CommandIDs {
79+ export const redo = 'drawio:command/redo' ;
80+ export const undo = 'drawio:command/undo' ;
81+ }
82+
7683function activate (
7784 app : JupyterFrontEnd ,
78- browserFactory : IFileBrowserFactory ,
85+ // browserFactory: IFileBrowserFactory,
86+ defaultBrowser :IDefaultFileBrowser ,
7987 restorer : ILayoutRestorer ,
8088 menu : IMainMenu ,
8189 palette : ICommandPalette ,
@@ -101,7 +109,7 @@ function activate(
101109 } ) ;
102110
103111 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
105113
106114 // Notify the instance tracker if restore data needs to update.
107115 widget . context . pathChanged . connect ( ( ) => {
@@ -128,7 +136,7 @@ function activate(
128136 iconClass : 'jp-MaterialIcon jp-ImageIcon' ,
129137 caption : 'Create a new diagram file' ,
130138 execute : ( ) => {
131- const cwd = browserFactory . defaultBrowser . model . path ;
139+ const cwd = defaultBrowser . model . path ;
132140 commands
133141 . execute ( 'docmanager:new-untitled' , {
134142 path : cwd ,
@@ -151,7 +159,7 @@ function activate(
151159 tracker . currentWidget !== null &&
152160 tracker . currentWidget === app . shell . currentWidget ,
153161 execute : ( ) => {
154- const cwd = browserFactory . defaultBrowser . model . path ;
162+ const cwd = defaultBrowser . model . path ;
155163 commands
156164 . execute ( 'docmanager:new-untitled' , {
157165 path : cwd ,
@@ -177,7 +185,7 @@ function activate(
177185 }
178186
179187 if ( menu ) {
180- addMenus ( commands , menu , tracker ) ;
188+ addMenus ( app , commands , menu , tracker ) ;
181189 }
182190
183191 addCommands ( app , tracker ) ;
@@ -195,18 +203,19 @@ function activate(
195203}
196204
197205function addMenus (
206+ app : JupyterFrontEnd ,
198207 commands : CommandRegistry ,
199208 menu : IMainMenu ,
200209 tracker : IDrawioTracker
201210) : 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' ;
204213
205214 // FILE MENU
206215 // Add new text file creation to the file menu.
207216 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' ;
210219 fileMenu . addGroup ( [ { command : 'drawio:create-new' } ] , 0 ) ;
211220 fileMenu . addGroup (
212221 [
@@ -216,18 +225,18 @@ function addMenus(
216225 ] ,
217226 1
218227 ) ;
228+ const isEnabled = ( ) =>
229+ tracker . currentWidget !== null &&
230+ tracker . currentWidget === app . shell . currentWidget ;
219231
220232 // 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} ) ;
226235
227- const editMenu = new JupyterLabMenu ( { commands } ) ;
228- editMenu . menu . title . label = 'Edit' ;
236+ const editMenu = new RankedMenu ( { commands } ) ;
237+ editMenu . rootMenu . title . label = 'Edit' ;
229238 editMenu . addGroup (
230- [ { command : 'drawio:command/ undo' } , { command : 'drawio:command/ redo' } ] ,
239+ [ { command : CommandIDs . undo } , { command : CommandIDs . redo } ] ,
231240 0
232241 ) ;
233242 editMenu . addGroup (
@@ -268,8 +277,8 @@ function addMenus(
268277 editMenu . addGroup ( [ { command : 'drawio:command/lockUnlock' } ] , 7 ) ;
269278
270279 // 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' ;
273282 viewMenu . addGroup (
274283 [
275284 { command : 'drawio:command/formatPanel' } ,
@@ -313,8 +322,8 @@ function addMenus(
313322 ) ;
314323
315324 // 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' ;
318327 arrangeMenu . addGroup (
319328 [
320329 { command : 'drawio:command/toFront' } ,
@@ -323,23 +332,23 @@ function addMenus(
323332 0
324333 ) ;
325334
326- const direction = new JupyterLabMenu ( { commands } ) ;
327- direction . menu . title . label = 'Direction' ;
335+ const direction = new RankedMenu ( { commands } ) ;
336+ direction . rootMenu . title . label = 'Direction' ;
328337 direction . addGroup (
329338 [ { command : 'drawio:command/flipH' } , { command : 'drawio:command/flipV' } ] ,
330339 0
331340 ) ;
332341 direction . addGroup ( [ { command : 'drawio:command/rotation' } ] , 1 ) ;
333342 arrangeMenu . addGroup (
334343 [
335- { type : 'submenu' , submenu : direction . menu } ,
344+ { type : 'submenu' , submenu : direction . rootMenu } ,
336345 { command : 'drawio:command/turn' }
337346 ] ,
338347 1
339348 ) ;
340349
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' ;
343352 align . addGroup (
344353 [
345354 { command : 'drawio:command/alignCellsLeft' } ,
@@ -357,8 +366,8 @@ function addMenus(
357366 1
358367 ) ;
359368
360- const distribute = new JupyterLabMenu ( { commands } ) ;
361- distribute . menu . title . label = 'Distribute' ;
369+ const distribute = new RankedMenu ( { commands } ) ;
370+ distribute . rootMenu . title . label = 'Distribute' ;
362371 distribute . addGroup (
363372 [
364373 { command : 'drawio:command/horizontal' } ,
@@ -368,14 +377,14 @@ function addMenus(
368377 ) ;
369378 arrangeMenu . addGroup (
370379 [
371- { type : 'submenu' , submenu : align . menu } ,
372- { type : 'submenu' , submenu : distribute . menu }
380+ { type : 'submenu' , submenu : align . rootMenu } ,
381+ { type : 'submenu' , submenu : distribute . rootMenu }
373382 ] ,
374383 2
375384 ) ;
376385
377- const navigation = new JupyterLabMenu ( { commands } ) ;
378- navigation . menu . title . label = 'Navigation' ;
386+ const navigation = new RankedMenu ( { commands } ) ;
387+ navigation . rootMenu . title . label = 'Navigation' ;
379388 navigation . addGroup ( [ { command : 'drawio:command/home' } ] , 0 ) ;
380389 navigation . addGroup (
381390 [
@@ -393,8 +402,8 @@ function addMenus(
393402 ) ;
394403 navigation . addGroup ( [ { command : 'drawio:command/collapsible' } ] , 3 ) ;
395404
396- const insert = new JupyterLabMenu ( { commands } ) ;
397- insert . menu . title . label = 'Insert' ;
405+ const insert = new RankedMenu ( { commands } ) ;
406+ insert . rootMenu . title . label = 'Insert' ;
398407 insert . addGroup (
399408 [
400409 { command : 'drawio:command/insertLink' } ,
@@ -403,8 +412,8 @@ function addMenus(
403412 0
404413 ) ;
405414
406- const layout = new JupyterLabMenu ( { commands } ) ;
407- layout . menu . title . label = 'Layout' ;
415+ const layout = new RankedMenu ( { commands } ) ;
416+ layout . rootMenu . title . label = 'Layout' ;
408417 layout . addGroup (
409418 [
410419 { command : 'drawio:command/horizontalFlow' } ,
@@ -429,9 +438,9 @@ function addMenus(
429438 ) ;
430439 arrangeMenu . addGroup (
431440 [
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 }
435444 ] ,
436445 3
437446 ) ;
@@ -454,8 +463,8 @@ function addMenus(
454463 ) ;
455464
456465 // 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' ;
459468 extrasMenu . addGroup (
460469 [
461470 { command : 'drawio:command/copyConnect' } ,
@@ -467,16 +476,16 @@ function addMenus(
467476
468477 diagram . addGroup (
469478 [
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 } ,
475484 { command : 'drawio:command/about' }
476485 ] ,
477486 0
478487 ) ;
479- menu . addMenu ( diagram . menu , { rank : 60 } ) ;
488+ menu . addMenu ( diagram . rootMenu , true , { rank : 60 } ) ;
480489}
481490
482491function addCommands ( app : JupyterFrontEnd , tracker : IDrawioTracker ) : void {
@@ -571,7 +580,7 @@ function addCommands(app: JupyterFrontEnd, tracker: IDrawioTracker): void {
571580 }
572581 } ) ;
573582 } ) ;
574- app . commands . addCommand ( 'drawio:command/ undo' , {
583+ app . commands . addCommand ( CommandIDs . undo , {
575584 label : 'Undo' ,
576585 caption : 'Undo (Ctrl+Z)' ,
577586 icon : undoIcon ,
@@ -596,7 +605,7 @@ function addCommands(app: JupyterFrontEnd, tracker: IDrawioTracker): void {
596605 }
597606 }
598607 } ) ;
599- app . commands . addCommand ( 'drawio:command/ redo' , {
608+ app . commands . addCommand ( CommandIDs . redo , {
600609 label : 'Redo' ,
601610 caption : 'Redo (Ctrl+Shift+Z)' ,
602611 icon : redoIcon ,
0 commit comments