提交 815b26e0 编写于 作者: A Alex Dima

Simplify StandaloneCommandService

上级 97570d91
......@@ -11,8 +11,8 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { IConfigurationService, IConfigurationServiceEvent, IConfigurationValue, getConfigurationValue, IConfigurationKeys } from 'vs/platform/configuration/common/configuration';
import { IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, Position } from 'vs/platform/editor/common/editor';
import { AbstractExtensionService, ActivatedExtension } from 'vs/platform/extensions/common/abstractExtensionService';
import { IExtensionDescription, IExtensionService } from 'vs/platform/extensions/common/extensions';
import { ICommandService, ICommand, ICommandHandler } from 'vs/platform/commands/common/commands';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { ICommandService, ICommand, ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { KeybindingResolver, IOSupport } from 'vs/platform/keybinding/common/keybindingResolver';
import { IKeybindingEvent, IKeybindingItem, KeybindingSource } from 'vs/platform/keybinding/common/keybinding';
......@@ -23,7 +23,6 @@ import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { Selection } from 'vs/editor/common/core/selection';
import Event, { Emitter } from 'vs/base/common/event';
import { getDefaultValues as getDefaultConfiguration } from 'vs/platform/configuration/common/model';
import { CommandService } from 'vs/platform/commands/common/commandService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
import { ITextModelResolverService, ITextModelContentProvider, ITextEditorModel } from 'vs/editor/common/services/resolverService';
......@@ -263,16 +262,14 @@ export class SimpleMessageService implements IMessageService {
}
}
export class StandaloneCommandService extends CommandService {
export class StandaloneCommandService implements ICommandService {
_serviceBrand: any;
private readonly _instantiationService: IInstantiationService;
private _dynamicCommands: { [id: string]: ICommand; };
constructor(
instantiationService: IInstantiationService,
extensionService: IExtensionService
) {
super(instantiationService, extensionService);
constructor(instantiationService: IInstantiationService) {
this._instantiationService = instantiationService;
this._dynamicCommands = Object.create(null);
}
......@@ -280,8 +277,18 @@ export class StandaloneCommandService extends CommandService {
this._dynamicCommands[id] = command;
}
protected _getCommand(id: string): ICommand {
return super._getCommand(id) || this._dynamicCommands[id];
public executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
const command = (CommandsRegistry.getCommand(id) || this._dynamicCommands[id]);
if (!command) {
return TPromise.wrapError(new Error(`command '${id}' not found`));
}
try {
const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
return TPromise.as(result);
} catch (err) {
return TPromise.wrapError(err);
}
}
}
......
......@@ -175,7 +175,7 @@ export class DynamicStandaloneServices extends Disposable {
let contextKeyService = ensure(IContextKeyService, () => this._register(new ContextKeyService(configurationService)));
let commandService = ensure(ICommandService, () => new StandaloneCommandService(this._instantiationService, extensionService));
let commandService = ensure(ICommandService, () => new StandaloneCommandService(this._instantiationService));
ensure(IKeybindingService, () => this._register(new StandaloneKeybindingService(contextKeyService, commandService, messageService, domElement)));
......
......@@ -6,7 +6,7 @@
import * as assert from 'assert';
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
import { SimpleConfigurationService, SimpleMessageService, SimpleExtensionService, StandaloneKeybindingService, StandaloneCommandService } from 'vs/editor/browser/standalone/simpleServices';
import { SimpleConfigurationService, SimpleMessageService, StandaloneKeybindingService, StandaloneCommandService } from 'vs/editor/browser/standalone/simpleServices';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { Keybinding, KeyCode } from 'vs/base/common/keyCodes';
......@@ -32,9 +32,7 @@ suite('StandaloneKeybindingService', () => {
let contextKeyService = new ContextKeyService(configurationService);
let extensionService = new SimpleExtensionService();
let commandService = new StandaloneCommandService(instantiationService, extensionService);
let commandService = new StandaloneCommandService(instantiationService);
let messageService = new SimpleMessageService();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册