@@ -41,6 +41,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
41
41
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
42
42
import { OpenRecentAction } from 'vs/workbench/browser/actions/windowActions' ;
43
43
import { isICommandActionToggleInfo } from 'vs/platform/action/common/action' ;
44
+ import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
44
45
45
46
export type IOpenRecentAction = IAction & { uri : URI ; remoteAuthority ?: string } ;
46
47
@@ -646,6 +647,12 @@ export class CustomMenubarControl extends MenubarControl {
646
647
this . _onVisibilityChange . fire ( visible ) ;
647
648
}
648
649
650
+ private toActionsArray ( menu : IMenu ) : IAction [ ] {
651
+ const result : IAction [ ] = [ ] ;
652
+ createAndFillInContextMenuActions ( menu , { shouldForwardArgs : true } , result ) ;
653
+ return result ;
654
+ }
655
+
649
656
private reinstallDisposables = this . _register ( new DisposableStore ( ) ) ;
650
657
private setupCustomMenubar ( firstTime : boolean ) : void {
651
658
// If there is no container, we cannot setup the menubar
@@ -704,67 +711,48 @@ export class CustomMenubarControl extends MenubarControl {
704
711
}
705
712
706
713
// Update the menu actions
707
- const updateActions = ( menu : IMenu , target : IAction [ ] , topLevelTitle : string ) => {
714
+ const updateActions = ( menuActions : readonly IAction [ ] , target : IAction [ ] , topLevelTitle : string ) => {
708
715
target . splice ( 0 ) ;
709
- const groups = menu . getActions ( ) ;
710
716
711
- for ( const group of groups ) {
712
- const [ , actions ] = group ;
713
-
714
- for ( const action of actions ) {
715
- this . insertActionsBefore ( action , target ) ;
717
+ for ( const menuItem of menuActions ) {
718
+ this . insertActionsBefore ( menuItem , target ) ;
716
719
720
+ if ( menuItem instanceof Separator ) {
721
+ target . push ( menuItem ) ;
722
+ } else if ( menuItem instanceof SubmenuItemAction || menuItem instanceof MenuItemAction ) {
717
723
// use mnemonicTitle whenever possible
718
- let title = typeof action . item . title === 'string'
719
- ? action . item . title
720
- : action . item . title . mnemonicTitle ?? action . item . title . value ;
721
-
722
- if ( action instanceof SubmenuItemAction ) {
723
- let submenu = this . menus [ action . item . submenu . id ] ;
724
- if ( ! submenu ) {
725
- submenu = this . mainMenuDisposables . add ( this . menus [ action . item . submenu . id ] = this . menuService . createMenu ( action . item . submenu , this . contextKeyService ) ) ;
726
- this . mainMenuDisposables . add ( submenu . onDidChange ( ( ) => {
727
- if ( ! this . focusInsideMenubar ) {
728
- const actions : IAction [ ] = [ ] ;
729
- updateActions ( menu , actions , topLevelTitle ) ;
730
- if ( this . menubar && this . topLevelTitles [ topLevelTitle ] ) {
731
- this . menubar . updateMenu ( { actions : actions , label : mnemonicMenuLabel ( this . topLevelTitles [ topLevelTitle ] ) } ) ;
732
- }
733
- }
734
- } , this ) ) ;
735
- }
724
+ let title = typeof menuItem . item . title === 'string'
725
+ ? menuItem . item . title
726
+ : menuItem . item . title . mnemonicTitle ?? menuItem . item . title . value ;
736
727
728
+ if ( menuItem instanceof SubmenuItemAction ) {
737
729
const submenuActions : SubmenuAction [ ] = [ ] ;
738
- updateActions ( submenu , submenuActions , topLevelTitle ) ;
730
+ updateActions ( menuItem . actions , submenuActions , topLevelTitle ) ;
739
731
740
732
if ( submenuActions . length > 0 ) {
741
- target . push ( new SubmenuAction ( action . id , mnemonicMenuLabel ( title ) , submenuActions ) ) ;
733
+ target . push ( new SubmenuAction ( menuItem . id , mnemonicMenuLabel ( title ) , submenuActions ) ) ;
742
734
}
743
735
} else {
744
- if ( isICommandActionToggleInfo ( action . item . toggled ) ) {
745
- title = action . item . toggled . mnemonicTitle ?? action . item . toggled . title ?? title ;
736
+ if ( isICommandActionToggleInfo ( menuItem . item . toggled ) ) {
737
+ title = menuItem . item . toggled . mnemonicTitle ?? menuItem . item . toggled . title ?? title ;
746
738
}
747
739
748
- const newAction = new Action ( action . id , mnemonicMenuLabel ( title ) , action . class , action . enabled , ( ) => this . commandService . executeCommand ( action . id ) ) ;
749
- newAction . tooltip = action . tooltip ;
750
- newAction . checked = action . checked ;
740
+ const newAction = new Action ( menuItem . id , mnemonicMenuLabel ( title ) , menuItem . class , menuItem . enabled , ( ) => this . commandService . executeCommand ( menuItem . id ) ) ;
741
+ newAction . tooltip = menuItem . tooltip ;
742
+ newAction . checked = menuItem . checked ;
751
743
target . push ( newAction ) ;
752
744
}
753
745
}
754
746
755
- target . push ( new Separator ( ) ) ;
756
747
}
757
748
758
749
// Append web navigation menu items to the file menu when not compact
759
- if ( menu === this . menus . File && this . currentCompactMenuMode === undefined ) {
750
+ if ( topLevelTitle === ' File' && this . currentCompactMenuMode === undefined ) {
760
751
const webActions = this . getWebNavigationActions ( ) ;
761
752
if ( webActions . length ) {
762
753
target . push ( ...webActions ) ;
763
- target . push ( new Separator ( ) ) ; // to account for pop below
764
754
}
765
755
}
766
-
767
- target . pop ( ) ;
768
756
} ;
769
757
770
758
for ( const title of Object . keys ( this . topLevelTitles ) ) {
@@ -773,7 +761,7 @@ export class CustomMenubarControl extends MenubarControl {
773
761
this . reinstallDisposables . add ( menu . onDidChange ( ( ) => {
774
762
if ( ! this . focusInsideMenubar ) {
775
763
const actions : IAction [ ] = [ ] ;
776
- updateActions ( menu , actions , title ) ;
764
+ updateActions ( this . toActionsArray ( menu ) , actions , title ) ;
777
765
this . menubar ?. updateMenu ( { actions : actions , label : mnemonicMenuLabel ( this . topLevelTitles [ title ] ) } ) ;
778
766
}
779
767
} ) ) ;
@@ -783,7 +771,7 @@ export class CustomMenubarControl extends MenubarControl {
783
771
this . reinstallDisposables . add ( this . webNavigationMenu . onDidChange ( ( ) => {
784
772
if ( ! this . focusInsideMenubar ) {
785
773
const actions : IAction [ ] = [ ] ;
786
- updateActions ( menu , actions , title ) ;
774
+ updateActions ( this . toActionsArray ( menu ) , actions , title ) ;
787
775
this . menubar ?. updateMenu ( { actions : actions , label : mnemonicMenuLabel ( this . topLevelTitles [ title ] ) } ) ;
788
776
}
789
777
} ) ) ;
@@ -792,7 +780,7 @@ export class CustomMenubarControl extends MenubarControl {
792
780
793
781
const actions : IAction [ ] = [ ] ;
794
782
if ( menu ) {
795
- updateActions ( menu , actions , title ) ;
783
+ updateActions ( this . toActionsArray ( menu ) , actions , title ) ;
796
784
}
797
785
798
786
if ( this . menubar ) {
0 commit comments