@@ -8,11 +8,11 @@ import * as nls from 'vs/nls';
88import { Action , IActionRunner , IAction , IActionViewItemProvider } 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 , combinedDisposable } from 'vs/base/common/lifecycle' ;
11+ import { Disposable , IDisposable } 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' ;
15- import { Emitter } from 'vs/base/common/event' ;
15+ import { EventMultiplexer } from 'vs/base/common/event' ;
1616import { DropdownMenuActionViewItem } from 'vs/base/browser/ui/dropdown/dropdownActionViewItem' ;
1717import { IContextMenuProvider } from 'vs/base/browser/contextmenu' ;
1818
@@ -38,12 +38,12 @@ export class ToolBar extends Disposable {
3838 private actionBar : ActionBar ;
3939 private toggleMenuAction : ToggleMenuAction ;
4040 private toggleMenuActionViewItem : DropdownMenuActionViewItem | undefined ;
41- private toggleMenuActionViewItemDisposable : IDisposable = Disposable . None ;
4241 private hasSecondaryActions : boolean = false ;
4342 private lookupKeybindings : boolean ;
4443
45- private _onDidChangeDropdownVisibility = this . _register ( new Emitter < boolean > ( ) ) ;
44+ private _onDidChangeDropdownVisibility = this . _register ( new EventMultiplexer < boolean > ( ) ) ;
4645 readonly onDidChangeDropdownVisibility = this . _onDidChangeDropdownVisibility . event ;
46+ private dropdownMenuDisposables = new Set < IDisposable > ( ) ;
4747
4848 constructor ( container : HTMLElement , contextMenuProvider : IContextMenuProvider , options : IToolBarOptions = { orientation : ActionsOrientation . HORIZONTAL } ) {
4949 super ( ) ;
@@ -62,13 +62,7 @@ export class ToolBar extends Disposable {
6262 ariaLabel : options . ariaLabel ,
6363 actionRunner : options . actionRunner ,
6464 actionViewItemProvider : ( action : IAction ) => {
65-
66- // Return special action item for the toggle menu action
6765 if ( action . id === ToggleMenuAction . ID ) {
68-
69- this . toggleMenuActionViewItemDisposable . dispose ( ) ;
70-
71- // Create new
7266 this . toggleMenuActionViewItem = new DropdownMenuActionViewItem (
7367 action ,
7468 ( < ToggleMenuAction > action ) . menuActions ,
@@ -83,11 +77,7 @@ export class ToolBar extends Disposable {
8377 }
8478 ) ;
8579 this . toggleMenuActionViewItem . setActionContext ( this . actionBar . context ) ;
86-
87- this . toggleMenuActionViewItemDisposable = combinedDisposable (
88- this . toggleMenuActionViewItem ,
89- this . toggleMenuActionViewItem . onDidChangeVisibility ( e => this . _onDidChangeDropdownVisibility . fire ( e ) )
90- ) ;
80+ this . dropdownMenuDisposables . add ( this . _onDidChangeDropdownVisibility . add ( this . toggleMenuActionViewItem . onDidChangeVisibility ) ) ;
9181
9282 return this . toggleMenuActionViewItem ;
9383 }
@@ -129,6 +119,8 @@ export class ToolBar extends Disposable {
129119 }
130120
131121 setActions ( primaryActions : ReadonlyArray < IAction > , secondaryActions ?: ReadonlyArray < IAction > ) : void {
122+ this . clear ( ) ;
123+
132124 let primaryActionsToSet = primaryActions ? primaryActions . slice ( 0 ) : [ ] ;
133125
134126 // Inject additional action to open secondary actions if present
@@ -138,8 +130,6 @@ export class ToolBar extends Disposable {
138130 primaryActionsToSet . push ( this . toggleMenuAction ) ;
139131 }
140132
141- this . actionBar . clear ( ) ;
142-
143133 primaryActionsToSet . forEach ( action => {
144134 this . actionBar . push ( action , { icon : true , label : false , keybinding : this . getKeybindingLabel ( action ) } ) ;
145135 } ) ;
@@ -167,9 +157,18 @@ export class ToolBar extends Disposable {
167157 } ;
168158 }
169159
160+ private clear ( ) : void {
161+ for ( const disposable of this . dropdownMenuDisposables ) {
162+ disposable . dispose ( ) ;
163+ }
164+
165+ this . dropdownMenuDisposables . clear ( ) ;
166+ this . actionBar . clear ( ) ;
167+ }
168+
170169 dispose ( ) : void {
170+ this . clear ( ) ;
171171 super . dispose ( ) ;
172- this . toggleMenuActionViewItemDisposable . dispose ( ) ;
173172 }
174173}
175174
0 commit comments