@@ -9,10 +9,11 @@ import { Action, IActionRunner, IAction } from 'vs/base/common/actions';
99import { ActionBar , ActionsOrientation , IActionViewItemProvider } from 'vs/base/browser/ui/actionbar/actionbar' ;
1010import { IContextMenuProvider , DropdownMenuActionViewItem } from 'vs/base/browser/ui/dropdown/dropdown' ;
1111import { ResolvedKeybinding } from 'vs/base/common/keyCodes' ;
12- import { Disposable , MutableDisposable } from 'vs/base/common/lifecycle' ;
12+ import { Disposable , IDisposable , combinedDisposable } from 'vs/base/common/lifecycle' ;
1313import { AnchorAlignment } from 'vs/base/browser/ui/contextview/contextview' ;
1414import { withNullAsUndefined } from 'vs/base/common/types' ;
1515import { Codicon , registerIcon } from 'vs/base/common/codicons' ;
16+ import { Emitter } from 'vs/base/common/event' ;
1617
1718export const CONTEXT = 'context.toolbar' ;
1819
@@ -35,17 +36,21 @@ export class ToolBar extends Disposable {
3536 private options : IToolBarOptions ;
3637 private actionBar : ActionBar ;
3738 private toggleMenuAction : ToggleMenuAction ;
38- private toggleMenuActionViewItem = this . _register ( new MutableDisposable < DropdownMenuActionViewItem > ( ) ) ;
39+ private toggleMenuActionViewItem : DropdownMenuActionViewItem | undefined ;
40+ private toggleMenuActionViewItemDisposable : IDisposable = Disposable . None ;
3941 private hasSecondaryActions : boolean = false ;
4042 private lookupKeybindings : boolean ;
4143
44+ private _onDidChangeDropdownVisibility = this . _register ( new Emitter < boolean > ( ) ) ;
45+ readonly onDidChangeDropdownVisibility = this . _onDidChangeDropdownVisibility . event ;
46+
4247 constructor ( container : HTMLElement , contextMenuProvider : IContextMenuProvider , options : IToolBarOptions = { orientation : ActionsOrientation . HORIZONTAL } ) {
4348 super ( ) ;
4449
4550 this . options = options ;
4651 this . lookupKeybindings = typeof this . options . getKeyBinding === 'function' ;
4752
48- this . toggleMenuAction = this . _register ( new ToggleMenuAction ( ( ) => this . toggleMenuActionViewItem . value && this . toggleMenuActionViewItem . value . show ( ) , options . toggleMenuTitle ) ) ;
53+ this . toggleMenuAction = this . _register ( new ToggleMenuAction ( ( ) => this . toggleMenuActionViewItem ? .show ( ) , options . toggleMenuTitle ) ) ;
4954
5055 let element = document . createElement ( 'div' ) ;
5156 element . className = 'monaco-toolbar' ;
@@ -60,8 +65,10 @@ export class ToolBar extends Disposable {
6065 // Return special action item for the toggle menu action
6166 if ( action . id === ToggleMenuAction . ID ) {
6267
68+ this . toggleMenuActionViewItemDisposable . dispose ( ) ;
69+
6370 // Create new
64- this . toggleMenuActionViewItem . value = new DropdownMenuActionViewItem (
71+ this . toggleMenuActionViewItem = new DropdownMenuActionViewItem (
6572 action ,
6673 ( < ToggleMenuAction > action ) . menuActions ,
6774 contextMenuProvider ,
@@ -72,9 +79,14 @@ export class ToolBar extends Disposable {
7279 this . options . anchorAlignmentProvider ,
7380 true
7481 ) ;
75- this . toggleMenuActionViewItem . value . setActionContext ( this . actionBar . context ) ;
82+ this . toggleMenuActionViewItem . setActionContext ( this . actionBar . context ) ;
83+
84+ this . toggleMenuActionViewItemDisposable = combinedDisposable (
85+ this . toggleMenuActionViewItem ,
86+ this . toggleMenuActionViewItem . onDidChangeVisibility ( e => this . _onDidChangeDropdownVisibility . fire ( e ) )
87+ ) ;
7688
77- return this . toggleMenuActionViewItem . value ;
89+ return this . toggleMenuActionViewItem ;
7890 }
7991
8092 return options . actionViewItemProvider ? options . actionViewItemProvider ( action ) : undefined ;
@@ -92,8 +104,8 @@ export class ToolBar extends Disposable {
92104
93105 set context ( context : unknown ) {
94106 this . actionBar . context = context ;
95- if ( this . toggleMenuActionViewItem . value ) {
96- this . toggleMenuActionViewItem . value . setActionContext ( context ) ;
107+ if ( this . toggleMenuActionViewItem ) {
108+ this . toggleMenuActionViewItem . setActionContext ( context ) ;
97109 }
98110 }
99111
@@ -151,6 +163,11 @@ export class ToolBar extends Disposable {
151163 }
152164 } ;
153165 }
166+
167+ dispose ( ) : void {
168+ super . dispose ( ) ;
169+ this . toggleMenuActionViewItemDisposable . dispose ( ) ;
170+ }
154171}
155172
156173class ToggleMenuAction extends Action {
0 commit comments