@@ -105,20 +105,20 @@ export class BrowserMainMenuFactory implements MenuWidgetFactory {
105105 const menuCommandRegistry = new LuminoCommandRegistry ( ) ;
106106 for ( const menu of menuModel . children ) {
107107 if ( CompoundMenuNode . is ( menu ) && RenderedMenuNode . is ( menu ) ) {
108- const menuWidget = this . createMenuWidget ( MAIN_MENU_BAR , menu , this . contextKeyService , { commands : menuCommandRegistry } ) ;
108+ const menuWidget = this . createMenuWidget ( [ ] , menu , this . contextKeyService , { commands : menuCommandRegistry } ) ;
109109 menuBar . addMenu ( menuWidget ) ;
110110 }
111111 }
112112 }
113113
114114 createContextMenu ( effectiveMenuPath : MenuPath , menuModel : CompoundMenuNode , contextMatcher : ContextMatcher , args ?: unknown [ ] , context ?: HTMLElement ) : MenuWidget {
115115 const menuCommandRegistry = new LuminoCommandRegistry ( ) ;
116- const contextMenu = this . createMenuWidget ( effectiveMenuPath , menuModel , contextMatcher , { commands : menuCommandRegistry , context } , args ) ;
116+ const contextMenu = this . createMenuWidget ( [ ] , menuModel , contextMatcher , { commands : menuCommandRegistry , context } , args ) ;
117117 return contextMenu ;
118118 }
119119
120- createMenuWidget ( parentPath : MenuPath , menu : CompoundMenuNode , contextMatcher : ContextMatcher , options : BrowserMenuOptions , args ?: unknown [ ] ) : DynamicMenuWidget {
121- return new DynamicMenuWidget ( parentPath , menu , options , contextMatcher , this . services , args ) ;
120+ createMenuWidget ( parentChain : CompoundMenuNode [ ] , menu : CompoundMenuNode , contextMatcher : ContextMatcher , options : BrowserMenuOptions , args ?: unknown [ ] ) : DynamicMenuWidget {
121+ return new DynamicMenuWidget ( parentChain , menu , options , contextMatcher , this . services , args ) ;
122122 }
123123
124124 protected get services ( ) : MenuServices {
@@ -212,7 +212,7 @@ export class MenuServices {
212212}
213213
214214export interface MenuWidgetFactory {
215- createMenuWidget ( effectiveMenuPath : MenuPath , menu : Submenu , contextMatcher : ContextMatcher , options : BrowserMenuOptions ) : MenuWidget ;
215+ createMenuWidget ( parentChain : CompoundMenuNode [ ] , menu : Submenu , contextMatcher : ContextMatcher , options : BrowserMenuOptions , args ?: unknown [ ] ) : MenuWidget ;
216216}
217217
218218/**
@@ -226,7 +226,7 @@ export class DynamicMenuWidget extends MenuWidget {
226226 protected previousFocusedElement : HTMLElement | undefined ;
227227
228228 constructor (
229- protected readonly effectiveMenuPath : MenuPath ,
229+ protected readonly parentChain : CompoundMenuNode [ ] ,
230230 protected menu : CompoundMenuNode ,
231231 protected options : BrowserMenuOptions ,
232232 protected contextMatcher : ContextMatcher ,
@@ -242,7 +242,7 @@ export class DynamicMenuWidget extends MenuWidget {
242242 this . title . iconClass = this . menu . icon ;
243243 }
244244 }
245- this . updateSubMenus ( this . effectiveMenuPath , this , this . menu , this . options . commands , this . contextMatcher , this . options . context ) ;
245+ this . updateSubMenus ( [ ... this . parentChain , this . menu ] , this , this . menu , this . options . commands , this . contextMatcher , this . options . context ) ;
246246 }
247247
248248 protected override onAfterAttach ( msg : Message ) : void {
@@ -291,7 +291,7 @@ export class DynamicMenuWidget extends MenuWidget {
291291 this . preserveFocusedElement ( previousFocusedElement ) ;
292292 this . clearItems ( ) ;
293293 this . runWithPreservedFocusContext ( ( ) => {
294- this . updateSubMenus ( this . effectiveMenuPath , this , this . menu , this . options . commands , this . contextMatcher , this . options . context ) ;
294+ this . updateSubMenus ( [ this . menu ] , this , this . menu , this . options . commands , this . contextMatcher , this . options . context ) ;
295295 } ) ;
296296 }
297297
@@ -305,9 +305,9 @@ export class DynamicMenuWidget extends MenuWidget {
305305 super . open ( x , y , options ) ;
306306 }
307307
308- protected updateSubMenus ( parentPath : MenuPath , parent : MenuWidget , menu : CompoundMenuNode , commands : LuminoCommandRegistry ,
308+ protected updateSubMenus ( parentChain : CompoundMenuNode [ ] , parent : MenuWidget , menu : CompoundMenuNode , commands : LuminoCommandRegistry ,
309309 contextMatcher : ContextMatcher , context ?: HTMLElement | undefined ) : void {
310- const items = this . createItems ( parentPath , menu . children , commands , contextMatcher , context ) ;
310+ const items = this . createItems ( parentChain , menu . children , commands , contextMatcher , context ) ;
311311 while ( items [ items . length - 1 ] ?. type === 'separator' ) {
312312 items . pop ( ) ;
313313 }
@@ -316,21 +316,20 @@ export class DynamicMenuWidget extends MenuWidget {
316316 }
317317 }
318318
319- protected createItems ( parentPath : MenuPath , nodes : MenuNode [ ] , phCommandRegistry : LuminoCommandRegistry ,
319+ protected createItems ( parentChain : CompoundMenuNode [ ] , nodes : MenuNode [ ] , phCommandRegistry : LuminoCommandRegistry ,
320320 contextMatcher : ContextMatcher , context ?: HTMLElement ) : MenuWidget . IItemOptions [ ] {
321321 const result : MenuWidget . IItemOptions [ ] = [ ] ;
322322
323323 for ( const node of nodes ) {
324- const nodePath = [ ...parentPath , node . id ] ;
325- if ( node . isVisible ( nodePath , contextMatcher , context , ...( this . args || [ ] ) ) ) {
324+ if ( node . isVisible ( parentChain , contextMatcher , context , ...( this . args || [ ] ) ) ) {
326325 if ( CompoundMenuNode . is ( node ) ) {
327326 if ( RenderedMenuNode . is ( node ) ) {
328- const submenu = this . services . menuWidgetFactory . createMenuWidget ( nodePath , node , this . contextMatcher , this . options ) ;
327+ const submenu = this . services . menuWidgetFactory . createMenuWidget ( [ ... parentChain , node ] , node , this . contextMatcher , this . options , this . args ) ;
329328 if ( submenu . items . length > 0 ) {
330329 result . push ( { type : 'submenu' , submenu } ) ;
331330 }
332331 } else if ( node . id !== 'inline' ) {
333- const items = this . createItems ( nodePath , node . children , phCommandRegistry , contextMatcher , context ) ;
332+ const items = this . createItems ( [ ... parentChain , node ] , node . children , phCommandRegistry , contextMatcher , context ) ;
334333 if ( items . length > 0 ) {
335334 if ( result [ result . length - 1 ] ?. type !== 'separator' ) {
336335 result . push ( { type : 'separator' } ) ;
@@ -343,9 +342,9 @@ export class DynamicMenuWidget extends MenuWidget {
343342 } else if ( CommandMenu . is ( node ) ) {
344343 const id = ! phCommandRegistry . hasCommand ( node . id ) ? node . id : `${ node . id } :${ DynamicMenuWidget . nextCommmandId ++ } ` ;
345344 phCommandRegistry . addCommand ( id , {
346- execute : ( ) => { node . run ( nodePath , ...( this . args || [ ] ) ) ; } ,
347- isEnabled : ( ) => node . isEnabled ( nodePath , ...( this . args || [ ] ) ) ,
348- isToggled : ( ) => node . isToggled ? ! ! node . isToggled ( nodePath , ...( this . args || [ ] ) ) : false ,
345+ execute : ( ) => { node . run ( parentChain , ...( this . args || [ ] ) ) ; } ,
346+ isEnabled : ( ) => node . isEnabled ( parentChain , ...( this . args || [ ] ) ) ,
347+ isToggled : ( ) => node . isToggled ? ! ! node . isToggled ( parentChain , ...( this . args || [ ] ) ) : false ,
349348 isVisible : ( ) => true ,
350349 label : node . label ,
351350 iconClass : node . icon ,
0 commit comments