提交 227e98f8 编写于 作者: B Benjamin Pasero

fix #59733

上级 72fcd264
......@@ -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 } from 'vs/base/common/lifecycle';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';
import { URI, UriComponents } from 'vs/base/common/uri';
......@@ -233,11 +233,12 @@ export class SubmenuItemAction extends Action {
export class MenuItemAction extends ExecuteCommandAction {
private _options: IMenuActionOptions;
readonly item: ICommandAction;
readonly alt: MenuItemAction;
private _options: IMenuActionOptions;
private _contextListener: IDisposable;
constructor(
item: ICommandAction,
alt: ICommandAction,
......@@ -252,6 +253,19 @@ 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<string>();
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<any> {
......@@ -267,6 +281,12 @@ export class MenuItemAction extends ExecuteCommandAction {
return super.run(...runArgs);
}
dispose(): void {
this._contextListener = dispose(this._contextListener);
super.dispose();
}
}
export class SyncActionDescriptor {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册