From 4cba1177270fdceae2f11353b03b17e10afecff5 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 12 Aug 2016 17:18:26 +0200 Subject: [PATCH] Rename ContextKeyService type names --- .../browser/standalone/simpleServices.ts | 8 --- .../browser/standalone/standaloneServices.ts | 5 +- .../contextkey/browser/contextKeyService.ts | 50 +++++++++---------- .../workbench/electron-browser/workbench.ts | 4 +- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/vs/editor/browser/standalone/simpleServices.ts b/src/vs/editor/browser/standalone/simpleServices.ts index c509466fe65..baa62c03a20 100644 --- a/src/vs/editor/browser/standalone/simpleServices.ts +++ b/src/vs/editor/browser/standalone/simpleServices.ts @@ -10,14 +10,12 @@ import {Schemas} from 'vs/base/common/network'; import Severity from 'vs/base/common/severity'; import URI from 'vs/base/common/uri'; import {TPromise} from 'vs/base/common/winjs.base'; -import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; import {ConfigurationService, IContent, IStat} from 'vs/platform/configuration/common/configurationService'; import {IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, ITextEditorModel, Position} from 'vs/platform/editor/common/editor'; 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 {KeybindingService2} from 'vs/platform/keybinding/browser/keybindingServiceImpl'; -import {KeybindingService} from 'vs/platform/contextkey/browser/contextKeyService'; import {IOSupport} from 'vs/platform/keybinding/common/keybindingResolver'; import {IKeybindingItem} from 'vs/platform/keybinding/common/keybinding'; import {IContextKeyService} from 'vs/platform/contextkey/common/contextkey'; @@ -247,12 +245,6 @@ export class StandaloneKeybindingService2 extends KeybindingService2 { } } -export class StandaloneKeybindingService extends KeybindingService { - constructor(configurationService: IConfigurationService) { - super(configurationService); - } -} - export class SimpleExtensionService extends AbstractExtensionService { constructor() { diff --git a/src/vs/editor/browser/standalone/standaloneServices.ts b/src/vs/editor/browser/standalone/standaloneServices.ts index 4c1afc7c111..181be5964df 100644 --- a/src/vs/editor/browser/standalone/standaloneServices.ts +++ b/src/vs/editor/browser/standalone/standaloneServices.ts @@ -38,7 +38,8 @@ 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, StandaloneKeybindingService2} from 'vs/editor/browser/standalone/simpleServices'; +import {SimpleConfigurationService, SimpleMessageService, SimpleExtensionService, StandaloneKeybindingService2} from 'vs/editor/browser/standalone/simpleServices'; +import {ContextKeyService} from 'vs/platform/contextkey/browser/contextKeyService'; import {IMenuService} from 'vs/platform/actions/common/actions'; import {MenuService} from 'vs/platform/actions/common/menuService'; import {ICompatWorkerService} from 'vs/editor/common/services/compatWorkerService'; @@ -196,7 +197,7 @@ export function ensureDynamicPlatformServices(domElement:HTMLElement, services: let contextKeyService:IContextKeyService; if (typeof services.contextKeyService === 'undefined') { - contextKeyService = new StandaloneKeybindingService(services.configurationService); + contextKeyService = new ContextKeyService(services.configurationService); r.push(contextKeyService); services.contextKeyService = contextKeyService; } else { diff --git a/src/vs/platform/contextkey/browser/contextKeyService.ts b/src/vs/platform/contextkey/browser/contextKeyService.ts index c795a2932f5..0256a954d01 100644 --- a/src/vs/platform/contextkey/browser/contextKeyService.ts +++ b/src/vs/platform/contextkey/browser/contextKeyService.ts @@ -11,12 +11,12 @@ import {IContextKey, IContextKeyServiceTarget, IContextKeyService, SET_CONTEXT_C import {IConfigurationService} from 'vs/platform/configuration/common/configuration'; import Event, {Emitter, debounceEvent} from 'vs/base/common/event'; -export class KeybindingContext { - protected _parent: KeybindingContext; +export class ContextValuesProvider { + protected _parent: ContextValuesProvider; protected _value: any; protected _id: number; - constructor(id: number, parent: KeybindingContext) { + constructor(id: number, parent: ContextValuesProvider) { this._id = id; this._parent = parent; this._value = Object.create(null); @@ -54,7 +54,7 @@ export class KeybindingContext { } } -class ConfigAwareKeybindingContext extends KeybindingContext { +class ConfigAwareContextValuesProvider extends ContextValuesProvider { private _emitter: Emitter; private _subscription: IDisposable; @@ -101,13 +101,13 @@ class ConfigAwareKeybindingContext extends KeybindingContext { } } -class KeybindingContextKey implements IContextKey { +class ContextKey implements IContextKey { - private _parent: AbstractKeybindingService; + private _parent: AbstractContextKeyService; private _key: string; private _defaultValue: T; - constructor(parent: AbstractKeybindingService, key: string, defaultValue: T) { + constructor(parent: AbstractContextKeyService, key: string, defaultValue: T) { this._parent = parent; this._key = key; this._defaultValue = defaultValue; @@ -129,10 +129,9 @@ class KeybindingContextKey implements IContextKey { public get(): T { return this._parent.getContextValue(this._key); } - } -export abstract class AbstractKeybindingService { +export abstract class AbstractContextKeyService { public _serviceBrand: any; protected _onDidChangeContext: Event; @@ -145,7 +144,7 @@ export abstract class AbstractKeybindingService { } public createKey(key: string, defaultValue: T): IContextKey { - return new KeybindingContextKey(this, key, defaultValue); + return new ContextKey(this, key, defaultValue); } public get onDidChangeContext(): Event { @@ -163,7 +162,7 @@ export abstract class AbstractKeybindingService { } public createScoped(domNode: IContextKeyServiceTarget): IContextKeyService { - return new ScopedKeybindingService(this, this._onDidChangeContextKey, domNode); + return new ScopedContextKeyService(this, this._onDidChangeContextKey, domNode); } public contextMatchesRules(rules: ContextKeyExpr): boolean { @@ -192,17 +191,16 @@ export abstract class AbstractKeybindingService { } } - public abstract getContext(contextId: number): KeybindingContext; + public abstract getContext(contextId: number): ContextValuesProvider; public abstract createChildContext(parentContextId?: number): number; public abstract disposeContext(contextId: number): void; - } -export class KeybindingService extends AbstractKeybindingService implements IContextKeyService { +export class ContextKeyService extends AbstractContextKeyService implements IContextKeyService { private _lastContextId: number; private _contexts: { - [contextId: string]: KeybindingContext; + [contextId: string]: ContextValuesProvider; }; private _toDispose: IDisposable[] = []; @@ -212,7 +210,7 @@ export class KeybindingService extends AbstractKeybindingService implements ICon this._lastContextId = 0; this._contexts = Object.create(null); - const myContext = new ConfigAwareKeybindingContext(this._myContextId, configurationService, this._onDidChangeContextKey); + const myContext = new ConfigAwareContextValuesProvider(this._myContextId, configurationService, this._onDidChangeContextKey); this._contexts[String(this._myContextId)] = myContext; this._toDispose.push(myContext); @@ -232,13 +230,13 @@ export class KeybindingService extends AbstractKeybindingService implements ICon this._toDispose = dispose(this._toDispose); } - public getContext(contextId: number): KeybindingContext { + public getContext(contextId: number): ContextValuesProvider { return this._contexts[String(contextId)]; } public createChildContext(parentContextId: number = this._myContextId): number { let id = (++this._lastContextId); - this._contexts[String(id)] = new KeybindingContext(id, this.getContext(parentContextId)); + this._contexts[String(id)] = new ContextValuesProvider(id, this.getContext(parentContextId)); return id; } @@ -247,16 +245,12 @@ export class KeybindingService extends AbstractKeybindingService implements ICon } } -CommandsRegistry.registerCommand(SET_CONTEXT_COMMAND_ID, function (accessor, contextKey: any, contextValue: any) { - accessor.get(IContextKeyService).createKey(String(contextKey), contextValue); -}); - -class ScopedKeybindingService extends AbstractKeybindingService { +class ScopedContextKeyService extends AbstractContextKeyService { - private _parent: AbstractKeybindingService; + private _parent: AbstractContextKeyService; private _domNode: IContextKeyServiceTarget; - constructor(parent: AbstractKeybindingService, emitter: Emitter, domNode: IContextKeyServiceTarget) { + constructor(parent: AbstractContextKeyService, emitter: Emitter, domNode: IContextKeyServiceTarget) { super(parent.createChildContext()); this._parent = parent; this._onDidChangeContextKey = emitter; @@ -273,7 +267,7 @@ class ScopedKeybindingService extends AbstractKeybindingService { return this._parent.onDidChangeContext; } - public getContext(contextId: number): KeybindingContext { + public getContext(contextId: number): ContextValuesProvider { return this._parent.getContext(contextId); } @@ -285,3 +279,7 @@ class ScopedKeybindingService extends AbstractKeybindingService { this._parent.disposeContext(contextId); } } + +CommandsRegistry.registerCommand(SET_CONTEXT_COMMAND_ID, function (accessor, contextKey: any, contextValue: any) { + accessor.get(IContextKeyService).createKey(String(contextKey), contextValue); +}); diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index 56d18811220..674b440e6fb 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -45,7 +45,7 @@ import {IWorkspaceContextService as IWorkbenchWorkspaceContextService} from 'vs/ import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage'; import {ContextMenuService} from 'vs/workbench/services/contextview/electron-browser/contextmenuService'; import {WorkbenchKeybindingService2} from 'vs/workbench/services/keybinding/electron-browser/keybindingService'; -import {KeybindingService} from 'vs/platform/contextkey/browser/contextKeyService'; +import {ContextKeyService} from 'vs/platform/contextkey/browser/contextKeyService'; import {IWorkspace, IConfiguration} from 'vs/platform/workspace/common/workspace'; import {IKeybindingService2} from 'vs/platform/keybinding/common/keybinding'; import {ContextKeyExpr, RawContextKey, IContextKeyService, IContextKey} from 'vs/platform/contextkey/common/contextkey'; @@ -353,7 +353,7 @@ export class Workbench implements IPartService { serviceCollection.set(IStatusbarService, this.statusbarPart); // Keybindings - this.contextKeyService = this.instantiationService.createInstance(KeybindingService); + this.contextKeyService = this.instantiationService.createInstance(ContextKeyService); serviceCollection.set(IContextKeyService, this.contextKeyService); this.keybindingService2 = this.instantiationService.createInstance(WorkbenchKeybindingService2, window); -- GitLab