55
66import 'vs/css!./toolbar' ;
77import * as nls from 'vs/nls' ;
8- import { Action , IActionRunner , IAction , IActionViewItemProvider } from 'vs/base/common/actions' ;
8+ import { Action , IActionRunner , IAction , IActionViewItemProvider , SubmenuAction } from 'vs/base/common/actions' ;
99import { ActionBar , ActionsOrientation } from 'vs/base/browser/ui/actionbar/actionbar' ;
1010import { ResolvedKeybinding } from 'vs/base/common/keyCodes' ;
11- import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
11+ import { Disposable , DisposableStore } from 'vs/base/common/lifecycle' ;
1212import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview' ;
1313import { withNullAsUndefined } from 'vs/base/common/types' ;
1414import { Codicon , registerIcon } from 'vs/base/common/codicons' ;
@@ -38,12 +38,13 @@ export class ToolBar extends Disposable {
3838 private actionBar : ActionBar ;
3939 private toggleMenuAction : ToggleMenuAction ;
4040 private toggleMenuActionViewItem : DropdownMenuActionViewItem | undefined ;
41+ private submenuActionViewItems : DropdownMenuActionViewItem [ ] = [ ] ;
4142 private hasSecondaryActions : boolean = false ;
4243 private lookupKeybindings : boolean ;
4344
4445 private _onDidChangeDropdownVisibility = this . _register ( new EventMultiplexer < boolean > ( ) ) ;
4546 readonly onDidChangeDropdownVisibility = this . _onDidChangeDropdownVisibility . event ;
46- private dropdownMenuDisposables = new Set < IDisposable > ( ) ;
47+ private disposables = new DisposableStore ( ) ;
4748
4849 constructor ( container : HTMLElement , contextMenuProvider : IContextMenuProvider , options : IToolBarOptions = { orientation : ActionsOrientation . HORIZONTAL } ) {
4950 super ( ) ;
@@ -62,6 +63,28 @@ export class ToolBar extends Disposable {
6263 ariaLabel : options . ariaLabel ,
6364 actionRunner : options . actionRunner ,
6465 actionViewItemProvider : ( action : IAction ) => {
66+ if ( action instanceof SubmenuAction ) {
67+ const actions = Array . isArray ( action . actions ) ? action . actions : action . actions ( ) ;
68+ const result = new DropdownMenuActionViewItem (
69+ action ,
70+ actions ,
71+ contextMenuProvider ,
72+ {
73+ actionViewItemProvider : this . options . actionViewItemProvider ,
74+ actionRunner : this . actionRunner ,
75+ keybindingProvider : this . options . getKeyBinding ,
76+ clazz : action . class ,
77+ anchorAlignmentProvider : this . options . anchorAlignmentProvider ,
78+ menuAsChild : true
79+ }
80+ ) ;
81+ result . setActionContext ( this . actionBar . context ) ;
82+ this . submenuActionViewItems . push ( result ) ;
83+ this . disposables . add ( this . _onDidChangeDropdownVisibility . add ( result . onDidChangeVisibility ) ) ;
84+
85+ return result ;
86+ }
87+
6588 if ( action . id === ToggleMenuAction . ID ) {
6689 this . toggleMenuActionViewItem = new DropdownMenuActionViewItem (
6790 action ,
@@ -77,7 +100,7 @@ export class ToolBar extends Disposable {
77100 }
78101 ) ;
79102 this . toggleMenuActionViewItem . setActionContext ( this . actionBar . context ) ;
80- this . dropdownMenuDisposables . add ( this . _onDidChangeDropdownVisibility . add ( this . toggleMenuActionViewItem . onDidChangeVisibility ) ) ;
103+ this . disposables . add ( this . _onDidChangeDropdownVisibility . add ( this . toggleMenuActionViewItem . onDidChangeVisibility ) ) ;
81104
82105 return this . toggleMenuActionViewItem ;
83106 }
@@ -100,6 +123,9 @@ export class ToolBar extends Disposable {
100123 if ( this . toggleMenuActionViewItem ) {
101124 this . toggleMenuActionViewItem . setActionContext ( context ) ;
102125 }
126+ for ( const actionViewItem of this . submenuActionViewItems ) {
127+ actionViewItem . setActionContext ( context ) ;
128+ }
103129 }
104130
105131 getContainer ( ) : HTMLElement {
@@ -142,11 +168,8 @@ export class ToolBar extends Disposable {
142168 }
143169
144170 private clear ( ) : void {
145- for ( const disposable of this . dropdownMenuDisposables ) {
146- disposable . dispose ( ) ;
147- }
148-
149- this . dropdownMenuDisposables . clear ( ) ;
171+ this . submenuActionViewItems = [ ] ;
172+ this . disposables . clear ( ) ;
150173 this . actionBar . clear ( ) ;
151174 }
152175
0 commit comments