Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/gulpfile.vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var baseModules = [
'https', 'https-proxy-agent', 'iconv-lite', 'ipc', 'menu', 'menu-item', 'net',
'original-fs', 'os', 'path', 'readline', 'remote', 'sax', 'screen', 'semver',
'shell', 'stream', 'string_decoder', 'url', 'vscode-textmate', 'web-frame', 'winreg',
'yauzl'
'yauzl', 'native-keymap'
];

// Build
Expand Down
5 changes: 5 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"sax": "^1.1.1",
"semver": "^4.2.0",
"vscode-textmate": "^1.0.8",
"native-keymap": "^0.0.2",
"winreg": "0.0.12",
"yauzl": "^2.3.1"
},
Expand Down
18 changes: 18 additions & 0 deletions src/typings/native-keymap.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module 'native-keymap' {

export interface INativeKeyMap {
key_code: string;
value: string;
withShift: string;
withAltGr: string;
withShiftAltGr: string;
}

export function getKeyMap(): INativeKeyMap[];

}
37 changes: 28 additions & 9 deletions src/vs/base/common/keyCodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ export enum KeyCode {
/**
* For the US standard keyboard, the ''"' key
*/
US_QUOTE
US_QUOTE,

/**
* Placed last to cover the length of the enum.
*/
MAX_VALUE
}

let TO_STRING_MAP: string[] = [];
Expand Down Expand Up @@ -365,15 +370,22 @@ export class Keybinding {
/**
* Format the binding to a format appropiate for rendering in the UI
*/
public static toLabel(value:number): string {
private static _toUSLabel(value:number): string {
return _asString(value, (Platform.isMacintosh ? MacUIKeyLabelProvider.INSTANCE : ClassicUIKeyLabelProvider.INSTANCE));
}

/**
* Format the binding to a format appropiate for rendering in the UI
*/
private static _toCustomLabel(value:number, labelProvider:IKeyBindingLabelProvider): string {
return _asString(value, labelProvider);
}

/**
* This prints the binding in a format suitable for electron's accelerators.
* See https://github.com/atom/electron/blob/master/docs/api/accelerator.md
*/
public static toElectronAccelerator(value:number): string {
private static _toElectronAccelerator(value:number): string {
if (BinaryKeybindings.hasChord(value)) {
// Electron cannot handle chords
return null;
Expand Down Expand Up @@ -426,16 +438,23 @@ export class Keybinding {
/**
* Format the binding to a format appropiate for rendering in the UI
*/
public toLabel(): string {
return Keybinding.toLabel(this.value);
public _toUSLabel(): string {
return Keybinding._toUSLabel(this.value);
}

/**
* Format the binding to a format appropiate for rendering in the UI
*/
public toCustomLabel(labelProvider:IKeyBindingLabelProvider): string {
return Keybinding._toCustomLabel(this.value, labelProvider);
}

/**
* This prints the binding in a format suitable for electron's accelerators.
* See https://github.com/atom/electron/blob/master/docs/api/accelerator.md
*/
public toElectronAccelerator(): string {
return Keybinding.toElectronAccelerator(this.value);
return Keybinding._toElectronAccelerator(this.value);
}

/**
Expand All @@ -447,7 +466,7 @@ export class Keybinding {

}

interface IKeyBindingLabelProvider {
export interface IKeyBindingLabelProvider {
ctrlKeyLabel:string;
shiftKeyLabel:string;
altKeyLabel:string;
Expand Down Expand Up @@ -489,7 +508,7 @@ class ElectronAcceleratorLabelProvider implements IKeyBindingLabelProvider {
/**
* Print for Mac UI
*/
class MacUIKeyLabelProvider implements IKeyBindingLabelProvider {
export class MacUIKeyLabelProvider implements IKeyBindingLabelProvider {
public static INSTANCE = new MacUIKeyLabelProvider();

private static leftArrowUnicodeLabel = String.fromCharCode(8592);
Expand Down Expand Up @@ -523,7 +542,7 @@ class MacUIKeyLabelProvider implements IKeyBindingLabelProvider {
/**
* Print for Windows, Linux UI
*/
class ClassicUIKeyLabelProvider implements IKeyBindingLabelProvider {
export class ClassicUIKeyLabelProvider implements IKeyBindingLabelProvider {
public static INSTANCE = new ClassicUIKeyLabelProvider();

public ctrlKeyLabel = nls.localize('ctrlKey', "Ctrl");
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/contextmenu/browser/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class ContextMenuController implements EditorCommon.IEditorContribution {
getActionItem: (action) => {
var keybinding = this._keybindingFor(action);
if (keybinding) {
return new ActionBar.ActionItem(action, action, { label: true, keybinding: keybinding.toLabel() });
return new ActionBar.ActionItem(action, action, { label: true, keybinding: this.keybindingService.getLabelFor(keybinding) });
}

var customActionItem = <any>action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DefineKeybindingLauncherWidget implements EditorBrowser.IOverlayWidget {
let keybinding = keybindingService.lookupKeybindings(DefineKeybindingAction.ID);
let extra = '';
if (keybinding.length > 0) {
extra += ' ('+keybinding[0].toLabel()+')';
extra += ' ('+keybindingService.getLabelFor(keybinding[0])+')';
}
this._domNode.appendChild(document.createTextNode(NLS_LAUNCH_MESSAGE + extra));

Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/quickOpen/browser/quickCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class QuickCommandAction extends EditorQuickOpen.BaseEditorQuickOpenActio
continue; // do not show actions that are not supported in this context
}

var keys = this._keybindingService.lookupKeybindings(editorAction.id).map(k => k.toLabel());
var keys = this._keybindingService.lookupKeybindings(editorAction.id).map(k => this._keybindingService.getLabelFor(k));

if (action.label) {
var highlights = Filters.matchesFuzzy(searchValue, action.label);
Expand Down
18 changes: 15 additions & 3 deletions src/vs/platform/keybinding/browser/keybindingServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export class AbstractKeybindingService {
this.getContext(this._myContextId).removeValue(key);
}

public getLabelFor(keybinding:Keybinding): string {
throw new Error('Not implemented');
}

public customKeybindingsCount(): number {
throw new Error('Not implemented');
}
Expand Down Expand Up @@ -181,6 +185,10 @@ export class KeybindingService extends AbstractKeybindingService implements IKey
this._toDispose = null;
}

public getLabelFor(keybinding:Keybinding): string {
return keybinding._toUSLabel();
}

protected updateResolver(): void {
this._createOrUpdateResolver(false);
}
Expand Down Expand Up @@ -234,16 +242,16 @@ export class KeybindingService extends AbstractKeybindingService implements IKey
e.preventDefault();
this._currentChord = resolveResult.enterChord;
if (this._messageService) {
let firstPartLabel = Keybinding.toLabel(this._currentChord);
let firstPartLabel = this.getLabelFor(new Keybinding(this._currentChord));
this._currentChordStatusMessage = this._messageService.setStatusMessage(nls.localize('first.chord', "({0}) was pressed. Waiting for second key of chord...", firstPartLabel));
}
return;
}

if (this._messageService && this._currentChord) {
if (!resolveResult || !resolveResult.commandId) {
let firstPartLabel = Keybinding.toLabel(this._currentChord);
let chordPartLabel = Keybinding.toLabel(e.asKeybinding());
let firstPartLabel = this.getLabelFor(new Keybinding(this._currentChord));
let chordPartLabel = this.getLabelFor(new Keybinding(e.asKeybinding()));
this._messageService.setStatusMessage(nls.localize('missing.chord', "The key combination ({0}, {1}) is not a command.", firstPartLabel, chordPartLabel), 10 * 1000 /* 10s */);
e.preventDefault();
}
Expand Down Expand Up @@ -330,6 +338,10 @@ class ScopedKeybindingService extends AbstractKeybindingService {
this._domNode.removeAttribute(KEYBINDING_CONTEXT_ATTR);
}

public getLabelFor(keybinding:Keybinding): string {
return this._parent.getLabelFor(keybinding);
}

public getDefaultKeybindings(): string {
return this._parent.getDefaultKeybindings();
}
Expand Down
2 changes: 2 additions & 0 deletions src/vs/platform/keybinding/common/keybindingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export interface IKeybindingService {
lookupKeybindings(commandId: string): Keybinding[];
customKeybindingsCount(): number;

getLabelFor(keybinding:Keybinding): string;

executeCommand<T>(commandId: string, args?: any): TPromise<T>;
executeCommand(commandId: string, args?: any): TPromise<any>;
}
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/activitybar/activitybarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class ActivitybarPart extends Part implements IActivityService {
let action = this.instantiationService.createInstance(ViewletActivityAction, viewlet.id + '.activity-bar-action', viewlet);

let keybinding: string = null;
let keys = this.keybindingService.lookupKeybindings(viewlet.id).map(k => k.toLabel());
let keys = this.keybindingService.lookupKeybindings(viewlet.id).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) {
keybinding = keys[0];
}
Expand Down Expand Up @@ -202,7 +202,7 @@ export class ActivitybarPart extends Part implements IActivityService {
return actions.map((action: Action) => {
if (primary) {
let keybinding: string = null;
let keys = this.keybindingService.lookupKeybindings(action.id).map(k => k.toLabel());
let keys = this.keybindingService.lookupKeybindings(action.id).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) {
keybinding = keys[0];
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/sidebar/sidebarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class SidebarPart extends Part implements IViewletService {
}

let keybinding: string = null;
let keys = this.keybindingService.lookupKeybindings(viewletId).map(k => k.toLabel());
let keys = this.keybindingService.lookupKeybindings(viewletId).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) {
keybinding = keys[0];
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/electron-browser/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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/browser/pluginKeybindingService';
import PluginWorkbenchKeybindingService from 'vs/workbench/services/keybinding/electron-browser/pluginKeybindingService';
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';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/debug/browser/debugActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AbstractDebugAction extends actions.Action {
this.toDispose.push(this.debugService.addListener2(debug.ServiceEvents.STATE_CHANGED, () => this.updateEnablement()));

var keybinding: string = null;
var keys = this.keybindingService.lookupKeybindings(id).map(k => k.toLabel());
var keys = this.keybindingService.lookupKeybindings(id).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) {
keybinding = keys[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {DerivedFrameEditorInput} from 'vs/workbench/parts/files/browser/editors/
import {KeybindingsUtils} from 'vs/platform/keybinding/common/keybindingsUtils';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {FileStat} from 'vs/workbench/parts/files/browser/views/explorerViewModel';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';

Expand All @@ -28,7 +29,8 @@ class FilesViewerActionContributor extends ActionBarContributor {

constructor(
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IKeybindingService private keybindingService: IKeybindingService
) {
super();
}
Expand Down Expand Up @@ -130,7 +132,7 @@ class FilesViewerActionContributor extends ActionBarContributor {
// Any other item with keybinding
let keybinding = keybindingForAction(action.id);
if (keybinding) {
return new ActionItem(context, action, { label: true, keybinding: keybinding.toLabel() });
return new ActionItem(context, action, { label: true, keybinding: this.keybindingService.getLabelFor(keybinding) });
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/parts/quickopen/browser/commandsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class CommandsHandler extends QuickOpenHandler {

for (let i = 0; i < actionDescriptors.length; i++) {
let actionDescriptor = actionDescriptors[i];
let keys = this.keybindingService.lookupKeybindings(actionDescriptor.id).map(k => k.toLabel());
let keys = this.keybindingService.lookupKeybindings(actionDescriptor.id).map(k => this.keybindingService.getLabelFor(k));

if (actionDescriptor.label) {
let label = actionDescriptor.label;
Expand Down Expand Up @@ -272,7 +272,7 @@ export class CommandsHandler extends QuickOpenHandler {
continue; // do not show actions that are not supported in this context
}

let keys = this.keybindingService.lookupKeybindings(editorAction.id).map(k => k.toLabel());
let keys = this.keybindingService.lookupKeybindings(editorAction.id).map(k => this.keybindingService.getLabelFor(k));

if (action.label) {
let highlights = filters.matchesFuzzy(searchValue, action.label);
Expand All @@ -289,7 +289,7 @@ export class CommandsHandler extends QuickOpenHandler {
let entries: ActionCommandEntry[] = [];

for (let action of actions) {
let keys = this.keybindingService.lookupKeybindings(action.id).map(k => k.toLabel());
let keys = this.keybindingService.lookupKeybindings(action.id).map(k => this.keybindingService.getLabelFor(k));
let highlights = filters.matchesFuzzy(searchValue, action.label);
if (highlights) {
entries.push(this.instantiationService.createInstance(ActionCommandEntry, keys.join(', '), action.label, highlights, action));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {IOSupport} from 'vs/platform/keybinding/common/commonKeybindingResolver'
import * as JSONContributionRegistry from 'vs/languages/json/common/jsonContributionRegistry';
import {IJSONSchema} from 'vs/base/common/jsonSchema';

export class WorkbenchKeybindingService extends KeybindingService {
export abstract class WorkbenchKeybindingService extends KeybindingService {
private contextService: IWorkspaceContextService;
private eventService: IEventService;
private telemetryService: ITelemetryService;
Expand Down
Loading