diff --git a/src/vs/platform/actions/common/menuService.ts b/src/vs/platform/actions/common/menuService.ts index 87cd2e9814d..e0ee881b773 100644 --- a/src/vs/platform/actions/common/menuService.ts +++ b/src/vs/platform/actions/common/menuService.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Emitter, Event } from 'vs/base/common/event'; -import { DisposableStore } from 'vs/base/common/lifecycle'; +import { Disposable } from 'vs/base/common/lifecycle'; import { IMenu, IMenuActionOptions, IMenuItem, IMenuService, isIMenuItem, ISubmenuItem, MenuId, MenuItemAction, MenuRegistry, SubmenuItemAction } from 'vs/platform/actions/common/actions'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { ContextKeyExpr, IContextKeyService, IContextKeyChangeEvent } from 'vs/platform/contextkey/common/contextkey'; @@ -27,10 +27,9 @@ export class MenuService implements IMenuService { type MenuItemGroup = [string, Array]; -class Menu implements IMenu { +class Menu extends Disposable implements IMenu { - private readonly _onDidChange = new Emitter(); - private readonly _dispoables = new DisposableStore(); + private readonly _onDidChange = this._register(new Emitter()); private _menuGroups: MenuItemGroup[]; private _contextKeys: Set; @@ -40,11 +39,12 @@ class Menu implements IMenu { @ICommandService private readonly _commandService: ICommandService, @IContextKeyService private readonly _contextKeyService: IContextKeyService ) { + super(); this._build(); // rebuild this menu whenever the menu registry reports an // event for this MenuId - this._dispoables.add(Event.debounce( + this._register(Event.debounce( Event.filter(MenuRegistry.onDidChangeMenu, menuId => menuId === this._id), () => { }, 50 @@ -52,18 +52,13 @@ class Menu implements IMenu { // when context keys change we need to check if the menu also // has changed - this._dispoables.add(Event.debounce( + this._register(Event.debounce( this._contextKeyService.onDidChangeContext, (last, event) => last || event.affectsSome(this._contextKeys), 50 )(e => e && this._onDidChange.fire(undefined), this)); } - dispose(): void { - this._dispoables.dispose(); - this._onDidChange.dispose(); - } - private _build(): void { // reset