From d848101d9dcdfefa839e3fe194686b78132ced58 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Tue, 2 Oct 2018 10:09:19 +0200 Subject: [PATCH] different fix for #59733 --- src/vs/platform/actions/common/actions.ts | 22 +--------------------- src/vs/platform/actions/common/menu.ts | 5 +++++ 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index e2a4e3f4848cd..0e190518c587b 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -11,7 +11,7 @@ import { IConstructorSignature2, createDecorator } from 'vs/platform/instantiati import { IKeybindings } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { ICommandService } from 'vs/platform/commands/common/commands'; -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { IDisposable } from 'vs/base/common/lifecycle'; import { Event } from 'vs/base/common/event'; import { URI, UriComponents } from 'vs/base/common/uri'; @@ -237,7 +237,6 @@ export class MenuItemAction extends ExecuteCommandAction { readonly alt: MenuItemAction; private _options: IMenuActionOptions; - private _contextListener: IDisposable; constructor( item: ICommandAction, @@ -253,19 +252,6 @@ export class MenuItemAction extends ExecuteCommandAction { this.item = item; this.alt = alt ? new MenuItemAction(alt, undefined, this._options, contextKeyService, commandService) : undefined; - - if (item.precondition) { - const preconditionKeysSet = new Set(); - for (let key of item.precondition.keys()) { - preconditionKeysSet.add(key); - } - - this._contextListener = contextKeyService.onDidChangeContext(event => { - if (event.affectsSome(preconditionKeysSet)) { - this._setEnabled(contextKeyService.contextMatchesRules(item.precondition)); - } - }); - } } run(...args: any[]): TPromise { @@ -281,12 +267,6 @@ export class MenuItemAction extends ExecuteCommandAction { return super.run(...runArgs); } - - dispose(): void { - this._contextListener = dispose(this._contextListener); - - super.dispose(); - } } export class SyncActionDescriptor { diff --git a/src/vs/platform/actions/common/menu.ts b/src/vs/platform/actions/common/menu.ts index 37c1431664057..e92546f3bf92c 100644 --- a/src/vs/platform/actions/common/menu.ts +++ b/src/vs/platform/actions/common/menu.ts @@ -44,6 +44,11 @@ export class Menu implements IMenu { // keep keys for eventing Menu._fillInKbExprKeys(item.when, keysFilter); + + // keep precondition keys for event if applicable + if (isIMenuItem(item) && item.command.precondition) { + Menu._fillInKbExprKeys(item.command.precondition, keysFilter); + } } // subscribe to context changes