Introduce IKeybindingService2

This commit is contained in:
Alex Dima 2016-08-12 12:48:29 +02:00
parent a8a920e2fc
commit 0ed00c698f
7 changed files with 45 additions and 27 deletions

View file

@ -16,7 +16,7 @@ import {IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, I
import {AbstractExtensionService, ActivatedExtension} from 'vs/platform/extensions/common/abstractExtensionService';
import {IExtensionDescription} from 'vs/platform/extensions/common/extensions';
import {ICommandService, ICommandHandler} from 'vs/platform/commands/common/commands';
import {KeybindingService} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
import {KeybindingService, KeybindingService2} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
import {IOSupport} from 'vs/platform/keybinding/common/keybindingResolver';
import {IKeybindingItem} from 'vs/platform/keybinding/common/keybinding';
import {IConfirmation, IMessageService} from 'vs/platform/message/common/message';
@ -197,6 +197,12 @@ export class SimpleMessageService implements IMessageService {
return window.confirm(messageText);
}
}
export class StandaloneKeybindingService2 extends KeybindingService2 {
}
export class StandaloneKeybindingService extends KeybindingService {

View file

@ -8,7 +8,6 @@
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {IContextViewService} from 'vs/platform/contextview/browser/contextView';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {AbstractKeybindingService} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
import {ICommandService} from 'vs/platform/commands/common/commands';
import {IKeybindingContextKey, IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {ICommandHandler} from 'vs/platform/commands/common/commands';
@ -74,10 +73,6 @@ export class StandaloneEditor extends CodeEditorWidget implements IStandaloneCod
@ITelemetryService telemetryService: ITelemetryService,
@IContextViewService contextViewService: IContextViewService
) {
if (keybindingService instanceof AbstractKeybindingService) {
(<AbstractKeybindingService><any>keybindingService).setInstantiationService(instantiationService);
}
options = options || {};
super(domElement, options, instantiationService, codeEditorService, commandService, keybindingService.createScoped(domElement), telemetryService);
@ -180,10 +175,6 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
@IContextViewService contextViewService: IContextViewService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService
) {
if (keybindingService instanceof AbstractKeybindingService) {
(<AbstractKeybindingService><any>keybindingService).setInstantiationService(instantiationService);
}
super(domElement, options, editorWorkerService, keybindingService, instantiationService);
if (keybindingService instanceof StandaloneKeybindingService) {

View file

@ -20,7 +20,7 @@ import {ServiceCollection} from 'vs/platform/instantiation/common/serviceCollect
import {ICommandService} from 'vs/platform/commands/common/commands';
import {CommandService} from 'vs/platform/commands/common/commandService';
import {IOpenerService} from 'vs/platform/opener/common/opener';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {IKeybindingService, IKeybindingService2} from 'vs/platform/keybinding/common/keybinding';
import {MarkerService} from 'vs/platform/markers/common/markerService';
import {IMarkerService} from 'vs/platform/markers/common/markers';
import {IMessageService} from 'vs/platform/message/common/message';
@ -37,7 +37,7 @@ import {MainThreadModeServiceImpl} from 'vs/editor/common/services/modeServiceIm
import {IModelService} from 'vs/editor/common/services/modelService';
import {ModelServiceImpl} from 'vs/editor/common/services/modelServiceImpl';
import {CodeEditorServiceImpl} from 'vs/editor/browser/services/codeEditorServiceImpl';
import {SimpleConfigurationService, SimpleMessageService, SimpleExtensionService, StandaloneKeybindingService} from 'vs/editor/browser/standalone/simpleServices';
import {SimpleConfigurationService, SimpleMessageService, SimpleExtensionService, StandaloneKeybindingService, StandaloneKeybindingService2} from 'vs/editor/browser/standalone/simpleServices';
import {IMenuService} from 'vs/platform/actions/common/actions';
import {MenuService} from 'vs/platform/actions/common/menuService';
import {ICompatWorkerService} from 'vs/editor/common/services/compatWorkerService';
@ -93,6 +93,10 @@ export interface IEditorOverrideServices {
* @internal
*/
keybindingService?:IKeybindingService;
/**
* @internal
*/
keybindingService2?:IKeybindingService2;
/**
* @internal
*/
@ -195,7 +199,11 @@ export function ensureDynamicPlatformServices(domElement:HTMLElement, services:
r.push(keybindingService);
services.keybindingService = keybindingService;
}
if (typeof services.keybindingService2 === 'undefined') {
var keybindingService2 = new StandaloneKeybindingService2();
r.push(keybindingService2);
services.keybindingService2 = keybindingService2;
}
if (typeof services.contextViewService === 'undefined') {
var contextViewService = new ContextViewService(domElement, services.telemetryService, services.messageService);
r.push(contextViewService);

View file

@ -13,10 +13,9 @@ import Severity from 'vs/base/common/severity';
import {isFalsyOrEmpty} from 'vs/base/common/arrays';
import * as dom from 'vs/base/browser/dom';
import {IKeyboardEvent, StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {ICommandService, CommandsRegistry, ICommandHandler, ICommandHandlerDescription} from 'vs/platform/commands/common/commands';
import {KeybindingResolver} from 'vs/platform/keybinding/common/keybindingResolver';
import {IKeybindingContextKey, IKeybindingItem, IKeybindingScopeLocation, IKeybindingService, SET_CONTEXT_COMMAND_ID, KbExpr} from 'vs/platform/keybinding/common/keybinding';
import {IKeybindingContextKey, IKeybindingItem, IKeybindingScopeLocation, IKeybindingService, IKeybindingService2, SET_CONTEXT_COMMAND_ID, KbExpr} from 'vs/platform/keybinding/common/keybinding';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {IStatusbarService} from 'vs/platform/statusbar/common/statusbar';
import {IMessageService} from 'vs/platform/message/common/message';
@ -146,18 +145,28 @@ class KeybindingContextKey<T> implements IKeybindingContextKey<T> {
}
export class KeybindingService2 implements IKeybindingService2 {
public _serviceBrand: any;
constructor() {
}
public dispose(): void {
}
}
export abstract class AbstractKeybindingService {
public _serviceBrand: any;
protected _onDidChangeContext: Event<string[]>;
protected _onDidChangeContextKey: Emitter<string>;
protected _myContextId: number;
protected _instantiationService: IInstantiationService;
constructor(myContextId: number) {
this._myContextId = myContextId;
this._onDidChangeContextKey = new Emitter<string>();
this._instantiationService = null;
}
public createKey<T>(key: string, defaultValue: T): IKeybindingContextKey<T> {
@ -178,10 +187,6 @@ export abstract class AbstractKeybindingService {
return this._onDidChangeContext;
}
public setInstantiationService(instantiationService: IInstantiationService): void {
this._instantiationService = instantiationService;
}
public createScoped(domNode: IKeybindingScopeLocation): IKeybindingService {
return new ScopedKeybindingService(this, this._onDidChangeContextKey, domNode);
}

View file

@ -493,4 +493,9 @@ export interface IKeybindingService {
getElectronAcceleratorFor(keybinding: Keybinding): string;
}
export let IKeybindingService2 = createDecorator<IKeybindingService2>('keybindingService2');
export interface IKeybindingService2 {
_serviceBrand: any;
}
export const SET_CONTEXT_COMMAND_ID = 'setContext';

View file

@ -38,16 +38,15 @@ import {PanelRegistry, Extensions as PanelExtensions} from 'vs/workbench/browser
import {QuickOpenController} from 'vs/workbench/browser/parts/quickopen/quickOpenController';
import {DiffEditorInput, toDiffLabel} from 'vs/workbench/common/editor/diffEditorInput';
import {getServices} from 'vs/platform/instantiation/common/extensions';
import {AbstractKeybindingService} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {WorkbenchEditorService} from 'vs/workbench/services/editor/browser/editorService';
import {Position, Parts, IPartService} from 'vs/workbench/services/part/common/partService';
import {IWorkspaceContextService as IWorkbenchWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage';
import {ContextMenuService} from 'vs/workbench/services/contextview/electron-browser/contextmenuService';
import {WorkbenchKeybindingService} from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
import {WorkbenchKeybindingService, WorkbenchKeybindingService2} from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
import {IWorkspace, IConfiguration} from 'vs/platform/workspace/common/workspace';
import {KbExpr, KbCtxKey, IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding';
import {KbExpr, KbCtxKey, IKeybindingService, IKeybindingService2, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding';
import {IActivityService} from 'vs/workbench/services/activity/common/activityService';
import {IViewletService} from 'vs/workbench/services/viewlet/common/viewletService';
import {IPanelService} from 'vs/workbench/services/panel/common/panelService';
@ -354,6 +353,8 @@ export class Workbench implements IPartService {
this.keybindingService = this.instantiationService.createInstance(WorkbenchKeybindingService, <any>window);
serviceCollection.set(IKeybindingService, this.keybindingService);
serviceCollection.set(IKeybindingService2, this.instantiationService.createInstance(WorkbenchKeybindingService2));
// Context Menu
serviceCollection.set(IContextMenuService, this.instantiationService.createInstance(ContextMenuService));
@ -401,8 +402,6 @@ export class Workbench implements IPartService {
serviceCollection.set(contributedService.id, contributedService.descriptor);
}
(<AbstractKeybindingService><any>this.keybindingService).setInstantiationService(this.instantiationService);
// Set the some services to registries that have been created eagerly
<IActionBarRegistry>Registry.as(ActionBarExtensions.Actionbar).setInstantiationService(this.instantiationService);
<IWorkbenchContributionsRegistry>Registry.as(WorkbenchExtensions.Workbench).setInstantiationService(this.instantiationService);

View file

@ -12,7 +12,7 @@ import * as platform from 'vs/base/common/platform';
import {IEventService} from 'vs/platform/event/common/event';
import {IExtensionMessageCollector, ExtensionsRegistry} from 'vs/platform/extensions/common/extensionsRegistry';
import {Extensions, IJSONContributionRegistry} from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import {KeybindingService} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
import {KeybindingService, KeybindingService2} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
import {IStatusbarService} from 'vs/platform/statusbar/common/statusbar';
import {IOSupport} from 'vs/platform/keybinding/common/keybindingResolver';
import {ICommandService} from 'vs/platform/commands/common/commands';
@ -114,6 +114,10 @@ let keybindingsExtPoint = ExtensionsRegistry.registerExtensionPoint<ContributedK
]
});
export class WorkbenchKeybindingService2 extends KeybindingService2 {
}
export class WorkbenchKeybindingService extends KeybindingService {
private contextService: IWorkspaceContextService;
private eventService: IEventService;