提交 3698d323 编写于 作者: J Johannes Rieken

remove ICommand#precondition, #41103

上级 a17bdc15
......@@ -10,7 +10,6 @@ import { ICommandService, ICommandEvent, CommandsRegistry } from 'vs/platform/co
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
import Event, { Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ILogService } from 'vs/platform/log/common/log';
export class CommandService extends Disposable implements ICommandService {
......@@ -25,7 +24,6 @@ export class CommandService extends Disposable implements ICommandService {
constructor(
@IInstantiationService private _instantiationService: IInstantiationService,
@IExtensionService private _extensionService: IExtensionService,
@IContextKeyService private _contextKeyService: IContextKeyService,
@ILogService private _logService: ILogService
) {
super();
......@@ -53,12 +51,6 @@ export class CommandService extends Disposable implements ICommandService {
if (!command) {
return TPromise.wrapError(new Error(`command '${id}' not found`));
}
if (command.precondition && !this._contextKeyService.contextMatchesRules(command.precondition)) {
// not enabled
return TPromise.wrapError(new Error('NOT_ENABLED'));
}
try {
this._onWillExecuteCommand.fire({ commandId: id });
const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
......
......@@ -9,7 +9,6 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import { TypeConstraint, validateConstraints } from 'vs/base/common/types';
import { ServicesAccessor, createDecorator } from 'vs/platform/instantiation/common/instantiation';
import Event from 'vs/base/common/event';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { LinkedList } from 'vs/base/common/linkedList';
export const ICommandService = createDecorator<ICommandService>('commandService');
......@@ -35,7 +34,6 @@ export interface ICommandHandler {
export interface ICommand {
id: string;
handler: ICommandHandler;
precondition?: ContextKeyExpr;
description?: ICommandHandlerDescription;
}
......
......@@ -12,9 +12,6 @@ import { CommandService } from 'vs/platform/commands/common/commandService';
import { IExtensionService, ExtensionPointContribution, IExtensionDescription, IExtensionHostInformation, ProfileSession } from 'vs/platform/extensions/common/extensions';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { IExtensionPoint } from 'vs/platform/extensions/common/extensionsRegistry';
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
import { SimpleConfigurationService } from 'vs/editor/standalone/browser/simpleServices';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import Event, { Emitter } from 'vs/base/common/event';
import { NullLogService } from 'vs/platform/log/common/log';
......@@ -75,7 +72,7 @@ suite('CommandService', function () {
lastEvent = activationEvent;
return super.activateByEvent(activationEvent);
}
}, new ContextKeyService(new SimpleConfigurationService()), new NullLogService());
}, new NullLogService());
return service.executeCommand('foo').then(() => {
assert.ok(lastEvent, 'onCommand:foo');
......@@ -93,7 +90,7 @@ suite('CommandService', function () {
activateByEvent(activationEvent: string): TPromise<void> {
return TPromise.wrapError<void>(new Error('bad_activate'));
}
}, new ContextKeyService(new SimpleConfigurationService()), new NullLogService());
}, new NullLogService());
return service.executeCommand('foo').then(() => assert.ok(false), err => {
assert.equal(err.message, 'bad_activate');
......@@ -109,7 +106,7 @@ suite('CommandService', function () {
whenInstalledExtensionsRegistered() {
return new TPromise<boolean>(_resolve => { /*ignore*/ });
}
}, new ContextKeyService(new SimpleConfigurationService()), new NullLogService());
}, new NullLogService());
service.executeCommand('bar');
assert.equal(callCounter, 1);
......@@ -126,7 +123,7 @@ suite('CommandService', function () {
whenInstalledExtensionsRegistered() {
return new TPromise<boolean>(_resolve => { resolveFunc = _resolve; });
}
}, new ContextKeyService(new SimpleConfigurationService()), new NullLogService());
}, new NullLogService());
let r = service.executeCommand('bar');
assert.equal(callCounter, 0);
......@@ -139,32 +136,4 @@ suite('CommandService', function () {
assert.equal(callCounter, 1);
});
});
test('honor command-precondition', function () {
let contextKeyService = new ContextKeyService(new SimpleConfigurationService());
let commandService = new CommandService(
new InstantiationService(),
new SimpleExtensionService(),
contextKeyService,
new NullLogService()
);
let counter = 0;
let reg = CommandsRegistry.registerCommand({
id: 'bar',
handler: () => { counter += 1; },
precondition: ContextKeyExpr.has('foocontext')
});
return commandService.executeCommand('bar').then(() => {
assert.throws(() => { });
}, () => {
contextKeyService.setContext('foocontext', true);
return commandService.executeCommand('bar');
}).then(() => {
assert.equal(counter, 1);
reg.dispose();
});
});
});
......@@ -6,7 +6,6 @@
import * as assert from 'assert';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
suite('Command Tests', function () {
......@@ -77,21 +76,4 @@ suite('Command Tests', function () {
assert.equal(CommandsRegistry.getCommands()['test3'].handler.apply(undefined, [undefined, 1]), true);
});
test('CommandsRegistry with precondition', function () {
let r1 = CommandsRegistry.registerCommand('foo', () => { });
const precondition = new RawContextKey<boolean>('ddd', false);
let r2 = CommandsRegistry.registerCommand({
id: 'bar',
handler: () => { },
precondition
});
assert.ok(CommandsRegistry.getCommand('bar').precondition === precondition);
assert.equal(CommandsRegistry.getCommand('foo').precondition, undefined);
r1.dispose();
r2.dispose();
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册