提交 1d2b103b 编写于 作者: A Alex Dima 提交者: Johannes Rieken

Merge WorkbenchKeybindingService into PluginWorkbenchKeybindingService

上级 5d6e7682
......@@ -40,7 +40,7 @@ import {ConfigurationService} from 'vs/workbench/services/configuration/node/con
import {FileService} from 'vs/workbench/services/files/electron-browser/fileService';
import {SearchService} from 'vs/workbench/services/search/node/searchService';
import {LifecycleService} from 'vs/workbench/services/lifecycle/electron-browser/lifecycleService';
import PluginWorkbenchKeybindingService from 'vs/workbench/services/keybinding/electron-browser/pluginKeybindingService';
import {WorkbenchKeybindingService} from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
import {MainThreadService} from 'vs/workbench/services/thread/electron-browser/threadService';
import {MarkerService} from 'vs/platform/markers/common/markerService';
import {IActionsService} from 'vs/platform/actions/common/actions';
......@@ -164,7 +164,7 @@ export class WorkbenchShell {
private themeService: IThemeService;
private contextService: WorkspaceContextService;
private telemetryService: ElectronTelemetryService;
private keybindingService: PluginWorkbenchKeybindingService;
private keybindingService: WorkbenchKeybindingService;
private container: HTMLElement;
private toUnbind: { (): void; }[];
......@@ -275,7 +275,7 @@ export class WorkbenchShell {
let enableTelemetry = this.configuration.env.isBuilt && !this.configuration.env.pluginDevelopmentPath ? !!this.configuration.env.enableTelemetry : false;
this.telemetryService = new ElectronTelemetryService(this.storageService, { enableTelemetry: enableTelemetry, version: this.configuration.env.version, commitHash: this.configuration.env.commitHash });
this.keybindingService = new PluginWorkbenchKeybindingService(this.contextService, eventService, this.telemetryService, <any>window);
this.keybindingService = new WorkbenchKeybindingService(this.contextService, eventService, this.telemetryService, <any>window);
this.messageService = new MessageService(this.contextService, this.windowService, this.telemetryService, this.keybindingService);
this.keybindingService.setMessageService(this.messageService);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import nls = require('vs/nls');
import {Registry} from 'vs/platform/platform';
import {KeybindingService} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
import {OptionsChangeEvent, EventType} from 'vs/workbench/common/events';
import {IEventService} from 'vs/platform/event/common/event';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IKeybindingItem, IUserFriendlyKeybinding} from 'vs/platform/keybinding/common/keybindingService';
import {IOSupport} from 'vs/platform/keybinding/common/commonKeybindingResolver';
import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import {IJSONSchema} from 'vs/base/common/jsonSchema';
export abstract class WorkbenchKeybindingService extends KeybindingService {
private contextService: IWorkspaceContextService;
private eventService: IEventService;
private telemetryService: ITelemetryService;
private toDispose: Function;
constructor(contextService: IWorkspaceContextService, eventService: IEventService, telemetryService: ITelemetryService, domNode: HTMLElement) {
this.contextService = contextService;
super(domNode);
this.eventService = eventService;
this.telemetryService = telemetryService;
this.toDispose = this.eventService.addListener(EventType.WORKBENCH_OPTIONS_CHANGED, (e) => this.onOptionsChanged(e));
}
public customKeybindingsCount(): number {
let opts = this.contextService.getOptions();
if (opts.globalSettings && opts.globalSettings.keybindings && Array.isArray(opts.globalSettings.keybindings)) {
return opts.globalSettings.keybindings.length;
}
return 0;
}
protected _getExtraKeybindings(isFirstTime: boolean): IKeybindingItem[] {
let extras: IUserFriendlyKeybinding[] = [];
let opts = this.contextService.getOptions();
if (opts.globalSettings && opts.globalSettings.keybindings) {
if (!isFirstTime) {
let cnt = 0;
if (Array.isArray(opts.globalSettings.keybindings)) {
cnt = opts.globalSettings.keybindings.length;
}
this.telemetryService.publicLog('customKeybindingsChanged', {
keyCount: cnt
});
}
if (Array.isArray(opts.globalSettings.keybindings)) {
extras = opts.globalSettings.keybindings;
}
}
return extras.map((k, i) => IOSupport.readKeybindingItem(k, i));
}
private onOptionsChanged(e: OptionsChangeEvent): void {
if (e.key === 'globalSettings') {
this.updateResolver();
}
}
public dispose(): void {
this.toDispose();
}
}
let schemaId = 'local://schemas/keybindings';
let schema : IJSONSchema = {
'id': schemaId,
'type': 'array',
'title': nls.localize('keybindings.json.title', "Keybindings configuration"),
'items': {
'required': ['key'],
'type': 'object',
'default': { 'key': '{{_}}', 'command': '{{_}}', 'when': '{{_}}' },
'properties': {
'key': {
'type': 'string',
'description': nls.localize('keybindings.json.key', 'Key or key sequence (separated by space)'),
},
'command': {
'description': nls.localize('keybindings.json.command', 'Name of the command to execute'),
},
'when': {
'type': 'string',
'description': nls.localize('keybindings.json.when', 'Condition when the key is active.')
}
}
}
};
let schemaRegistry = <JSONContributionRegistry.IJSONContributionRegistry>Registry.as(JSONContributionRegistry.Extensions.JSONContribution);
schemaRegistry.registerSchema(schemaId, schema);
schemaRegistry.addSchemaFileAssociation('inmemory://defaults/keybindings.json', schemaId);
schemaRegistry.addSchemaFileAssociation('%APP_SETTINGS_HOME%/keybindings.json', schemaId);
\ No newline at end of file
......@@ -6,19 +6,23 @@
import nls = require('vs/nls');
import {TPromise} from 'vs/base/common/winjs.base';
import {IJSONSchema} from 'vs/base/common/jsonSchema';
import {IHTMLContentElement} from 'vs/base/common/htmlContent';
import {Registry} from 'vs/platform/platform';
import {IEventService} from 'vs/platform/event/common/event';
import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {PluginsRegistry, IMessageCollector} from 'vs/platform/plugins/common/pluginsRegistry';
import {IPluginService} from 'vs/platform/plugins/common/plugins';
import {IOSupport} from 'vs/platform/keybinding/common/commonKeybindingResolver';
import {WorkbenchKeybindingService} from 'vs/workbench/services/keybinding/browser/keybindingService';
import {KeybindingService} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
import {IKeybindingItem, IUserFriendlyKeybinding} from 'vs/platform/keybinding/common/keybindingService';
import {ICommandRule, KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {IJSONSchema} from 'vs/base/common/jsonSchema';
import {Keybinding, IKeyBindingLabelProvider} from 'vs/base/common/keyCodes';
import Platform = require('vs/base/common/platform');
import {IHTMLContentElement} from 'vs/base/common/htmlContent';
import {Keybinding} from 'vs/base/common/keyCodes';
import * as Platform from 'vs/base/common/platform';
import {getNativeLabelProvider} from 'vs/workbench/services/keybinding/electron-browser/nativeKeymap';
import {OptionsChangeEvent, EventType} from 'vs/workbench/common/events';
interface ContributedKeyBinding {
command: string;
......@@ -107,14 +111,21 @@ let keybindingsExtPoint = PluginsRegistry.registerExtensionPoint<ContributedKeyB
]
});
export class WorkbenchKeybindingService extends KeybindingService {
export default class PluginWorkbenchKeybindingService extends WorkbenchKeybindingService {
private contextService: IWorkspaceContextService;
private eventService: IEventService;
private telemetryService: ITelemetryService;
private toDispose: Function;
private _pluginService: IPluginService;
private _eventService: IEventService;
constructor(contextService: IWorkspaceContextService, eventService: IEventService, telemetryService: ITelemetryService, domNode: HTMLElement) {
super(contextService, eventService, telemetryService, domNode);
this.contextService = contextService;
super(domNode);
this.eventService = eventService;
this.telemetryService = telemetryService;
this.toDispose = this.eventService.addListener(EventType.WORKBENCH_OPTIONS_CHANGED, (e) => this.onOptionsChanged(e));
this._eventService = eventService;
keybindingsExtPoint.setHandler((extensions) => {
let commandAdded = false;
......@@ -133,6 +144,44 @@ export default class PluginWorkbenchKeybindingService extends WorkbenchKeybindin
this._pluginService = pluginService;
}
public customKeybindingsCount(): number {
let opts = this.contextService.getOptions();
if (opts.globalSettings && opts.globalSettings.keybindings && Array.isArray(opts.globalSettings.keybindings)) {
return opts.globalSettings.keybindings.length;
}
return 0;
}
protected _getExtraKeybindings(isFirstTime: boolean): IKeybindingItem[] {
let extras: IUserFriendlyKeybinding[] = [];
let opts = this.contextService.getOptions();
if (opts.globalSettings && opts.globalSettings.keybindings) {
if (!isFirstTime) {
let cnt = 0;
if (Array.isArray(opts.globalSettings.keybindings)) {
cnt = opts.globalSettings.keybindings.length;
}
this.telemetryService.publicLog('customKeybindingsChanged', {
keyCount: cnt
});
}
if (Array.isArray(opts.globalSettings.keybindings)) {
extras = opts.globalSettings.keybindings;
}
}
return extras.map((k, i) => IOSupport.readKeybindingItem(k, i));
}
private onOptionsChanged(e: OptionsChangeEvent): void {
if (e.key === 'globalSettings') {
this.updateResolver();
}
}
public dispose(): void {
this.toDispose();
}
public getLabelFor(keybinding:Keybinding): string {
return keybinding.toCustomLabel(getNativeLabelProvider());
}
......@@ -232,3 +281,33 @@ export default class PluginWorkbenchKeybindingService extends WorkbenchKeybindin
return desc;
}
}
let schemaId = 'local://schemas/keybindings';
let schema : IJSONSchema = {
'id': schemaId,
'type': 'array',
'title': nls.localize('keybindings.json.title', "Keybindings configuration"),
'items': {
'required': ['key'],
'type': 'object',
'default': { 'key': '{{_}}', 'command': '{{_}}', 'when': '{{_}}' },
'properties': {
'key': {
'type': 'string',
'description': nls.localize('keybindings.json.key', 'Key or key sequence (separated by space)'),
},
'command': {
'description': nls.localize('keybindings.json.command', 'Name of the command to execute'),
},
'when': {
'type': 'string',
'description': nls.localize('keybindings.json.when', 'Condition when the key is active.')
}
}
}
};
let schemaRegistry = <JSONContributionRegistry.IJSONContributionRegistry>Registry.as(JSONContributionRegistry.Extensions.JSONContribution);
schemaRegistry.registerSchema(schemaId, schema);
schemaRegistry.addSchemaFileAssociation('inmemory://defaults/keybindings.json', schemaId);
schemaRegistry.addSchemaFileAssociation('%APP_SETTINGS_HOME%/keybindings.json', schemaId);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册