Clean-up
This commit is contained in:
parent
a9701d8651
commit
5ba467555e
|
@ -15,7 +15,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 {KeybindingService2} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
|
||||
import {KeybindingService} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
|
||||
import {IOSupport} from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import {IKeybindingItem} from 'vs/platform/keybinding/common/keybinding';
|
||||
import {IContextKeyService} from 'vs/platform/contextkey/common/contextkey';
|
||||
|
@ -199,7 +199,7 @@ export class SimpleMessageService implements IMessageService {
|
|||
}
|
||||
}
|
||||
|
||||
export class StandaloneKeybindingService2 extends KeybindingService2 {
|
||||
export class StandaloneKeybindingService extends KeybindingService {
|
||||
private static LAST_GENERATED_ID = 0;
|
||||
|
||||
private _dynamicKeybindings: IKeybindingItem[];
|
||||
|
@ -221,7 +221,7 @@ export class StandaloneKeybindingService2 extends KeybindingService2 {
|
|||
|
||||
public addDynamicKeybinding(keybinding: number, handler:ICommandHandler, when:string, commandId:string = null): string {
|
||||
if (commandId === null) {
|
||||
commandId = 'DYNAMIC_' + (++StandaloneKeybindingService2.LAST_GENERATED_ID);
|
||||
commandId = 'DYNAMIC_' + (++StandaloneKeybindingService.LAST_GENERATED_ID);
|
||||
}
|
||||
var parsedContext = IOSupport.readKeybindingWhen(when);
|
||||
this._dynamicKeybindings.push({
|
||||
|
|
|
@ -16,7 +16,7 @@ import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
|
|||
import {IActionDescriptor, ICodeEditorWidgetCreationOptions, IDiffEditorOptions, IModel, IModelChangedEvent, EventType} from 'vs/editor/common/editorCommon';
|
||||
import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService';
|
||||
import {IEditorWorkerService} from 'vs/editor/common/services/editorWorkerService';
|
||||
import {StandaloneKeybindingService2} from 'vs/editor/browser/standalone/simpleServices';
|
||||
import {StandaloneKeybindingService} from 'vs/editor/browser/standalone/simpleServices';
|
||||
import {IEditorContextViewService, IEditorOverrideServices, ensureStaticPlatformServices, getOrCreateStaticServices} from 'vs/editor/browser/standalone/standaloneServices';
|
||||
import {CodeEditorWidget} from 'vs/editor/browser/widget/codeEditorWidget';
|
||||
import {DiffEditorWidget} from 'vs/editor/browser/widget/diffEditorWidget';
|
||||
|
@ -58,7 +58,7 @@ export interface IStandaloneDiffEditor extends IDiffEditor {
|
|||
|
||||
export class StandaloneEditor extends CodeEditorWidget implements IStandaloneCodeEditor {
|
||||
|
||||
private _standaloneKeybindingService: StandaloneKeybindingService2;
|
||||
private _standaloneKeybindingService: StandaloneKeybindingService;
|
||||
private _contextViewService:IEditorContextViewService;
|
||||
private _ownsModel:boolean;
|
||||
private _toDispose2: IDisposable[];
|
||||
|
@ -78,7 +78,7 @@ export class StandaloneEditor extends CodeEditorWidget implements IStandaloneCod
|
|||
options = options || {};
|
||||
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService.createScoped(domElement), telemetryService);
|
||||
|
||||
if (keybindingService instanceof StandaloneKeybindingService2) {
|
||||
if (keybindingService instanceof StandaloneKeybindingService) {
|
||||
this._standaloneKeybindingService = keybindingService;
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ export class StandaloneEditor extends CodeEditorWidget implements IStandaloneCod
|
|||
export class StandaloneDiffEditor extends DiffEditorWidget implements IStandaloneDiffEditor {
|
||||
|
||||
private _contextViewService:IEditorContextViewService;
|
||||
private _standaloneKeybindingService: StandaloneKeybindingService2;
|
||||
private _standaloneKeybindingService: StandaloneKeybindingService;
|
||||
private _toDispose2: IDisposable[];
|
||||
|
||||
constructor(
|
||||
|
@ -180,7 +180,7 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
|
|||
) {
|
||||
super(domElement, options, editorWorkerService, contextKeyService, instantiationService);
|
||||
|
||||
if (keybindingService instanceof StandaloneKeybindingService2) {
|
||||
if (keybindingService instanceof StandaloneKeybindingService) {
|
||||
this._standaloneKeybindingService = keybindingService;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,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, StandaloneKeybindingService2} from 'vs/editor/browser/standalone/simpleServices';
|
||||
import {SimpleConfigurationService, SimpleMessageService, SimpleExtensionService, StandaloneKeybindingService} 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';
|
||||
|
@ -204,7 +204,7 @@ export function ensureDynamicPlatformServices(domElement:HTMLElement, services:
|
|||
contextKeyService = services.contextKeyService;
|
||||
}
|
||||
if (typeof services.keybindingService === 'undefined') {
|
||||
let keybindingService = new StandaloneKeybindingService2(contextKeyService, services.commandService, services.messageService, domElement);
|
||||
let keybindingService = new StandaloneKeybindingService(contextKeyService, services.commandService, services.messageService, domElement);
|
||||
r.push(keybindingService);
|
||||
services.keybindingService = keybindingService;
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ export class MockCodeEditor extends CommonCodeEditor {
|
|||
}
|
||||
|
||||
export class MockScopeLocation implements IContextKeyServiceTarget {
|
||||
parentElement:IContextKeyServiceTarget = null;
|
||||
setAttribute(attr:string, value:string): void { }
|
||||
removeAttribute(attr:string): void { }
|
||||
hasAttribute(attr: string): boolean { return false; }
|
||||
|
|
|
@ -7,16 +7,18 @@
|
|||
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
|
||||
import {CommandsRegistry} from 'vs/platform/commands/common/commands';
|
||||
import {KeybindingResolver} from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import {IContextKey, IContextKeyServiceTarget, IContextKeyService, SET_CONTEXT_COMMAND_ID, KEYBINDING_CONTEXT_ATTR, ContextKeyExpr} from 'vs/platform/contextkey/common/contextkey';
|
||||
import {IContextKey, IContextKeyServiceTarget, IContextKeyService, SET_CONTEXT_COMMAND_ID, ContextKeyExpr} from 'vs/platform/contextkey/common/contextkey';
|
||||
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
|
||||
import Event, {Emitter, debounceEvent} from 'vs/base/common/event';
|
||||
|
||||
export class ContextValuesProvider {
|
||||
protected _parent: ContextValuesProvider;
|
||||
protected _value: any;
|
||||
const KEYBINDING_CONTEXT_ATTR = 'data-keybinding-context';
|
||||
|
||||
export class ContextValuesContainer {
|
||||
protected _parent: ContextValuesContainer;
|
||||
protected _value: {[key:string]:any;};
|
||||
protected _id: number;
|
||||
|
||||
constructor(id: number, parent: ContextValuesProvider) {
|
||||
constructor(id: number, parent: ContextValuesContainer) {
|
||||
this._id = id;
|
||||
this._parent = parent;
|
||||
this._value = Object.create(null);
|
||||
|
@ -54,7 +56,7 @@ export class ContextValuesProvider {
|
|||
}
|
||||
}
|
||||
|
||||
class ConfigAwareContextValuesProvider extends ContextValuesProvider {
|
||||
class ConfigAwareContextValuesContainer extends ContextValuesContainer {
|
||||
|
||||
private _emitter: Emitter<string>;
|
||||
private _subscription: IDisposable;
|
||||
|
@ -127,7 +129,7 @@ class ContextKey<T> implements IContextKey<T> {
|
|||
}
|
||||
|
||||
public get(): T {
|
||||
return this._parent.getContextValue<T>(this._key);
|
||||
return this._parent.getContextKeyValue<T>(this._key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,7 +169,7 @@ export abstract class AbstractContextKeyService {
|
|||
|
||||
public contextMatchesRules(rules: ContextKeyExpr): boolean {
|
||||
const ctx = Object.create(null);
|
||||
this.getContext(this._myContextId).fillInContext(ctx);
|
||||
this.getContextValuesContainer(this._myContextId).fillInContext(ctx);
|
||||
const result = KeybindingResolver.contextMatchesRules(ctx, rules);
|
||||
// console.group(rules.serialize() + ' -> ' + result);
|
||||
// rules.keys().forEach(key => { console.log(key, ctx[key]); });
|
||||
|
@ -175,23 +177,29 @@ export abstract class AbstractContextKeyService {
|
|||
return result;
|
||||
}
|
||||
|
||||
public getContextValue<T>(key: string): T {
|
||||
return this.getContext(this._myContextId).getValue<T>(key);
|
||||
public getContextKeyValue<T>(key: string): T {
|
||||
return this.getContextValuesContainer(this._myContextId).getValue<T>(key);
|
||||
}
|
||||
|
||||
public setContext(key: string, value: any): void {
|
||||
if(this.getContext(this._myContextId).setValue(key, value)) {
|
||||
if(this.getContextValuesContainer(this._myContextId).setValue(key, value)) {
|
||||
this._onDidChangeContextKey.fire(key);
|
||||
}
|
||||
}
|
||||
|
||||
public removeContext(key: string): void {
|
||||
if(this.getContext(this._myContextId).removeValue(key)) {
|
||||
if(this.getContextValuesContainer(this._myContextId).removeValue(key)) {
|
||||
this._onDidChangeContextKey.fire(key);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract getContext(contextId: number): ContextValuesProvider;
|
||||
public getContextValue(target: IContextKeyServiceTarget): any {
|
||||
let res = Object.create(null);
|
||||
this.getContextValuesContainer(findContextAttr(target)).fillInContext(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
public abstract getContextValuesContainer(contextId: number): ContextValuesContainer;
|
||||
public abstract createChildContext(parentContextId?: number): number;
|
||||
public abstract disposeContext(contextId: number): void;
|
||||
}
|
||||
|
@ -200,7 +208,7 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon
|
|||
|
||||
private _lastContextId: number;
|
||||
private _contexts: {
|
||||
[contextId: string]: ContextValuesProvider;
|
||||
[contextId: string]: ContextValuesContainer;
|
||||
};
|
||||
|
||||
private _toDispose: IDisposable[] = [];
|
||||
|
@ -210,7 +218,7 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon
|
|||
this._lastContextId = 0;
|
||||
this._contexts = Object.create(null);
|
||||
|
||||
const myContext = new ConfigAwareContextValuesProvider(this._myContextId, configurationService, this._onDidChangeContextKey);
|
||||
const myContext = new ConfigAwareContextValuesContainer(this._myContextId, configurationService, this._onDidChangeContextKey);
|
||||
this._contexts[String(this._myContextId)] = myContext;
|
||||
this._toDispose.push(myContext);
|
||||
|
||||
|
@ -230,13 +238,13 @@ export class ContextKeyService extends AbstractContextKeyService implements ICon
|
|||
this._toDispose = dispose(this._toDispose);
|
||||
}
|
||||
|
||||
public getContext(contextId: number): ContextValuesProvider {
|
||||
public getContextValuesContainer(contextId: number): ContextValuesContainer {
|
||||
return this._contexts[String(contextId)];
|
||||
}
|
||||
|
||||
public createChildContext(parentContextId: number = this._myContextId): number {
|
||||
let id = (++this._lastContextId);
|
||||
this._contexts[String(id)] = new ContextValuesProvider(id, this.getContext(parentContextId));
|
||||
this._contexts[String(id)] = new ContextValuesContainer(id, this.getContextValuesContainer(parentContextId));
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -267,8 +275,8 @@ class ScopedContextKeyService extends AbstractContextKeyService {
|
|||
return this._parent.onDidChangeContext;
|
||||
}
|
||||
|
||||
public getContext(contextId: number): ContextValuesProvider {
|
||||
return this._parent.getContext(contextId);
|
||||
public getContextValuesContainer(contextId: number): ContextValuesContainer {
|
||||
return this._parent.getContextValuesContainer(contextId);
|
||||
}
|
||||
|
||||
public createChildContext(parentContextId: number = this._myContextId): number {
|
||||
|
@ -280,6 +288,16 @@ class ScopedContextKeyService extends AbstractContextKeyService {
|
|||
}
|
||||
}
|
||||
|
||||
function findContextAttr(domNode: IContextKeyServiceTarget): number {
|
||||
while (domNode) {
|
||||
if (domNode.hasAttribute(KEYBINDING_CONTEXT_ATTR)) {
|
||||
return parseInt(domNode.getAttribute(KEYBINDING_CONTEXT_ATTR), 10);
|
||||
}
|
||||
domNode = domNode.parentElement;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
CommandsRegistry.registerCommand(SET_CONTEXT_COMMAND_ID, function (accessor, contextKey: any, contextValue: any) {
|
||||
accessor.get(IContextKeyService).createKey(String(contextKey), contextValue);
|
||||
});
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
import {createDecorator} from 'vs/platform/instantiation/common/instantiation';
|
||||
import Event from 'vs/base/common/event';
|
||||
|
||||
export const KEYBINDING_CONTEXT_ATTR = 'data-keybinding-context';
|
||||
|
||||
export enum ContextKeyExprType {
|
||||
Defined = 1,
|
||||
Not = 2,
|
||||
|
@ -430,7 +428,7 @@ export class RawContextKey<T> extends ContextKeyDefinedExpr {
|
|||
}
|
||||
|
||||
public getValue(target:IContextKeyService): T {
|
||||
return target.getContextValue<T>(this.key);
|
||||
return target.getContextKeyValue<T>(this.key);
|
||||
}
|
||||
|
||||
public toNegated(): ContextKeyExpr {
|
||||
|
@ -449,12 +447,11 @@ export interface IContextKey<T> {
|
|||
}
|
||||
|
||||
export interface IContextKeyServiceTarget {
|
||||
parentElement: IContextKeyServiceTarget;
|
||||
setAttribute(attr: string, value: string): void;
|
||||
removeAttribute(attr: string): void;
|
||||
}
|
||||
|
||||
export interface IContextValuesProvider {
|
||||
fillInContext(bucket: any): void;
|
||||
hasAttribute(attr: string): boolean;
|
||||
getAttribute(attr: string): string;
|
||||
}
|
||||
|
||||
export let IContextKeyService = createDecorator<IContextKeyService>('contextKeyService');
|
||||
|
@ -466,11 +463,10 @@ export interface IContextKeyService {
|
|||
onDidChangeContext: Event<string[]>;
|
||||
createKey<T>(key: string, defaultValue: T): IContextKey<T>;
|
||||
contextMatchesRules(rules: ContextKeyExpr): boolean;
|
||||
getContextValue<T>(key: string): T;
|
||||
getContextKeyValue<T>(key: string): T;
|
||||
|
||||
createScoped(domNode: IContextKeyServiceTarget): IContextKeyService;
|
||||
|
||||
getContext(contextId: number): IContextValuesProvider;
|
||||
createScoped(target: IContextKeyServiceTarget): IContextKeyService;
|
||||
getContextValue(target: IContextKeyServiceTarget): any;
|
||||
}
|
||||
|
||||
export const SET_CONTEXT_COMMAND_ID = 'setContext';
|
||||
|
|
|
@ -16,12 +16,12 @@ import {IKeyboardEvent, StandardKeyboardEvent} from 'vs/base/browser/keyboardEve
|
|||
import {ICommandService, CommandsRegistry, ICommandHandler, ICommandHandlerDescription} from 'vs/platform/commands/common/commands';
|
||||
import {KeybindingResolver} from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import {IKeybindingItem, IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
|
||||
import {IContextKeyService, KEYBINDING_CONTEXT_ATTR} from 'vs/platform/contextkey/common/contextkey';
|
||||
import {IContextKeyService} from 'vs/platform/contextkey/common/contextkey';
|
||||
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import {IStatusbarService} from 'vs/platform/statusbar/common/statusbar';
|
||||
import {IMessageService} from 'vs/platform/message/common/message';
|
||||
|
||||
export abstract class KeybindingService2 implements IKeybindingService {
|
||||
export abstract class KeybindingService implements IKeybindingService {
|
||||
public _serviceBrand: any;
|
||||
|
||||
private _toDispose: IDisposable[] = [];
|
||||
|
@ -141,8 +141,7 @@ export abstract class KeybindingService2 implements IKeybindingService {
|
|||
return;
|
||||
}
|
||||
|
||||
let contextValue = Object.create(null);
|
||||
this._contextKeyService.getContext(this._findContextAttr(e.target)).fillInContext(contextValue);
|
||||
let contextValue = this._contextKeyService.getContextValue(e.target);
|
||||
// console.log(JSON.stringify(contextValue, null, '\t'));
|
||||
|
||||
let resolveResult = this._getResolver().resolve(contextValue, this._currentChord, e.asKeybinding());
|
||||
|
@ -182,13 +181,5 @@ export abstract class KeybindingService2 implements IKeybindingService {
|
|||
}
|
||||
}
|
||||
|
||||
private _findContextAttr(domNode: HTMLElement): number {
|
||||
while (domNode) {
|
||||
if (domNode.hasAttribute(KEYBINDING_CONTEXT_ATTR)) {
|
||||
return parseInt(domNode.getAttribute(KEYBINDING_CONTEXT_ATTR), 10);
|
||||
}
|
||||
domNode = domNode.parentElement;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import {IHTMLContentElement} from 'vs/base/common/htmlContent';
|
|||
import {Keybinding} from 'vs/base/common/keyCodes';
|
||||
import Event from 'vs/base/common/event';
|
||||
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
|
||||
import {IContextKey, IContextKeyService, IContextValuesProvider, ContextKeyExpr} from 'vs/platform/contextkey/common/contextkey';
|
||||
import {IContextKey, IContextKeyService, ContextKeyExpr} from 'vs/platform/contextkey/common/contextkey';
|
||||
|
||||
class MockKeybindingContextKey<T> implements IContextKey<T> {
|
||||
private _key: string;
|
||||
|
@ -48,10 +48,10 @@ export class MockKeybindingService implements IContextKeyService {
|
|||
public get onDidChangeContext(): Event<string[]> {
|
||||
return Event.None;
|
||||
}
|
||||
public getContextValue(key: string) {
|
||||
public getContextKeyValue(key: string) {
|
||||
return;
|
||||
}
|
||||
public getContext(contextId: number): IContextValuesProvider {
|
||||
public getContextValue(domNode: HTMLElement): any {
|
||||
return null;
|
||||
}
|
||||
public createScoped(domNode: HTMLElement): IContextKeyService {
|
||||
|
|
|
@ -44,7 +44,7 @@ import {Position, Parts, IPartService} from 'vs/workbench/services/part/common/p
|
|||
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 {WorkbenchKeybindingService2} from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
|
||||
import {WorkbenchKeybindingService} from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
|
||||
import {ContextKeyService} from 'vs/platform/contextkey/browser/contextKeyService';
|
||||
import {IWorkspace, IConfiguration} from 'vs/platform/workspace/common/workspace';
|
||||
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
|
||||
|
@ -356,7 +356,7 @@ export class Workbench implements IPartService {
|
|||
this.contextKeyService = this.instantiationService.createInstance(ContextKeyService);
|
||||
serviceCollection.set(IContextKeyService, this.contextKeyService);
|
||||
|
||||
this.keybindingService = this.instantiationService.createInstance(WorkbenchKeybindingService2, <any>window);
|
||||
this.keybindingService = this.instantiationService.createInstance(WorkbenchKeybindingService, <any>window);
|
||||
serviceCollection.set(IKeybindingService, this.keybindingService);
|
||||
|
||||
// Context Menu
|
||||
|
|
|
@ -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 {KeybindingService2} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
|
||||
import {KeybindingService} 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,7 +114,7 @@ let keybindingsExtPoint = ExtensionsRegistry.registerExtensionPoint<ContributedK
|
|||
]
|
||||
});
|
||||
|
||||
export class WorkbenchKeybindingService2 extends KeybindingService2 {
|
||||
export class WorkbenchKeybindingService extends KeybindingService {
|
||||
private contextService: IWorkspaceContextService;
|
||||
private eventService: IEventService;
|
||||
private telemetryService: ITelemetryService;
|
||||
|
|
Loading…
Reference in a new issue