提交 bb3c3f0b 编写于 作者: A Alex Dima

Extract USLayoutResolvedKeybinding to its own file

上级 47ee1eff
......@@ -11,7 +11,8 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { IConfigurationService, IConfigurationServiceEvent, IConfigurationValue, getConfigurationValue, IConfigurationKeys } from 'vs/platform/configuration/common/configuration';
import { IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, Position } from 'vs/platform/editor/common/editor';
import { ICommandService, ICommand, ICommandEvent, ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { USLayoutResolvedKeybinding, AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
import { IKeybindingEvent, IKeybindingItem, KeybindingSource } from 'vs/platform/keybinding/common/keybinding';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
......
......@@ -5,9 +5,7 @@
'use strict';
import * as nls from 'vs/nls';
import { IHTMLContentElement } from 'vs/base/common/htmlContent';
import { ResolvedKeybinding, SimpleKeybinding, Keybinding, KeyCode, KeyCodeUtils, USER_SETTINGS } from 'vs/base/common/keyCodes';
import { PrintableKeypress, UILabelProvider, AriaLabelProvider, ElectronAcceleratorLabelProvider, UserSettingsLabelProvider } from 'vs/platform/keybinding/common/keybindingLabels';
import { ResolvedKeybinding, SimpleKeybinding, Keybinding } from 'vs/base/common/keyCodes';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import Severity from 'vs/base/common/severity';
import { ICommandService } from 'vs/platform/commands/common/commands';
......@@ -17,155 +15,6 @@ import { IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contex
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { IMessageService } from 'vs/platform/message/common/message';
import Event, { Emitter } from 'vs/base/common/event';
import { OperatingSystem } from 'vs/base/common/platform';
/**
* Do not instantiate. Use KeybindingService to get a ResolvedKeybinding seeded with information about the current kb layout.
*/
export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
private readonly _actual: Keybinding;
private readonly _os: OperatingSystem;
constructor(actual: Keybinding, os: OperatingSystem) {
super();
this._actual = actual;
this._os = os;
}
private static _usKeyCodeToUILabel(keyCode: KeyCode, OS: OperatingSystem): string {
if (OS === OperatingSystem.Macintosh) {
switch (keyCode) {
case KeyCode.LeftArrow:
return '';
case KeyCode.UpArrow:
return '';
case KeyCode.RightArrow:
return '';
case KeyCode.DownArrow:
return '';
}
}
return KeyCodeUtils.toString(keyCode);
}
private static _usKeyCodeToAriaLabel(keyCode: KeyCode, OS: OperatingSystem): string {
return KeyCodeUtils.toString(keyCode);
}
public getLabel(): string {
const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToUILabel, this._os);
return UILabelProvider.toLabel2(firstPart, chordPart, this._os);
}
public getAriaLabel(): string {
const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToAriaLabel, this._os);
return AriaLabelProvider.toLabel2(firstPart, chordPart, this._os);
}
public getHTMLLabel(): IHTMLContentElement[] {
const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToUILabel, this._os);
return UILabelProvider.toHTMLLabel2(firstPart, chordPart, this._os);
}
private static _usKeyCodeToElectronAccelerator(keyCode: KeyCode, OS: OperatingSystem): string {
switch (keyCode) {
case KeyCode.UpArrow:
return 'Up';
case KeyCode.DownArrow:
return 'Down';
case KeyCode.LeftArrow:
return 'Left';
case KeyCode.RightArrow:
return 'Right';
}
return KeyCodeUtils.toString(keyCode);
}
public getElectronAccelerator(): string {
if (this._actual.isChord()) {
// Electron cannot handle chords
return null;
}
let keyCode = this._actual.getKeyCode();
if (keyCode >= KeyCode.NUMPAD_0 && keyCode <= KeyCode.NUMPAD_DIVIDE) {
// Electron cannot handle numpad keys
return null;
}
const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToElectronAccelerator, this._os);
return ElectronAcceleratorLabelProvider.toLabel2(firstPart, chordPart, this._os);
}
private static _usKeyCodeToUserSettings(keyCode: KeyCode, OS: OperatingSystem): string {
return USER_SETTINGS.fromKeyCode(keyCode);
}
public getUserSettingsLabel(): string {
const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToUserSettings, this._os);
let result = UserSettingsLabelProvider.toLabel2(firstPart, chordPart, this._os);
return result.toLowerCase();
}
public isChord(): boolean {
return this._actual.isChord();
}
public hasCtrlModifier(): boolean {
if (this._actual.isChord()) {
return false;
}
if (this._os === OperatingSystem.Macintosh) {
return this._actual.hasWinCtrl();
} else {
return this._actual.hasCtrlCmd();
}
}
public hasShiftModifier(): boolean {
if (this._actual.isChord()) {
return false;
}
return this._actual.hasShift();
}
public hasAltModifier(): boolean {
if (this._actual.isChord()) {
return false;
}
return this._actual.hasAlt();
}
public hasMetaModifier(): boolean {
if (this._actual.isChord()) {
return false;
}
if (this._os === OperatingSystem.Macintosh) {
return this._actual.hasCtrlCmd();
} else {
return this._actual.hasWinCtrl();
}
}
public getDispatchParts(): [string, string] {
let keypressFirstPart: string;
let keypressChordPart: string;
if (this._actual === null) {
keypressFirstPart = null;
keypressChordPart = null;
} else if (this._actual.isChord()) {
keypressFirstPart = this._actual.extractFirstPart().value.toString();
keypressChordPart = this._actual.extractChordPart().value.toString();
} else {
keypressFirstPart = this._actual.value.toString();
keypressChordPart = null;
}
return [keypressFirstPart, keypressChordPart];
}
}
interface CurrentChord {
keypress: string;
......
/*---------------------------------------------------------------------------------------------
* 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 { IHTMLContentElement } from 'vs/base/common/htmlContent';
import { ResolvedKeybinding, Keybinding, KeyCode, KeyCodeUtils, USER_SETTINGS } from 'vs/base/common/keyCodes';
import { PrintableKeypress, UILabelProvider, AriaLabelProvider, ElectronAcceleratorLabelProvider, UserSettingsLabelProvider } from 'vs/platform/keybinding/common/keybindingLabels';
import { OperatingSystem } from 'vs/base/common/platform';
/**
* Do not instantiate. Use KeybindingService to get a ResolvedKeybinding seeded with information about the current kb layout.
*/
export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
private readonly _actual: Keybinding;
private readonly _os: OperatingSystem;
constructor(actual: Keybinding, os: OperatingSystem) {
super();
this._actual = actual;
this._os = os;
}
private static _usKeyCodeToUILabel(keyCode: KeyCode, OS: OperatingSystem): string {
if (OS === OperatingSystem.Macintosh) {
switch (keyCode) {
case KeyCode.LeftArrow:
return '';
case KeyCode.UpArrow:
return '';
case KeyCode.RightArrow:
return '';
case KeyCode.DownArrow:
return '';
}
}
return KeyCodeUtils.toString(keyCode);
}
private static _usKeyCodeToAriaLabel(keyCode: KeyCode, OS: OperatingSystem): string {
return KeyCodeUtils.toString(keyCode);
}
public getLabel(): string {
const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToUILabel, this._os);
return UILabelProvider.toLabel2(firstPart, chordPart, this._os);
}
public getAriaLabel(): string {
const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToAriaLabel, this._os);
return AriaLabelProvider.toLabel2(firstPart, chordPart, this._os);
}
public getHTMLLabel(): IHTMLContentElement[] {
const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToUILabel, this._os);
return UILabelProvider.toHTMLLabel2(firstPart, chordPart, this._os);
}
private static _usKeyCodeToElectronAccelerator(keyCode: KeyCode, OS: OperatingSystem): string {
switch (keyCode) {
case KeyCode.UpArrow:
return 'Up';
case KeyCode.DownArrow:
return 'Down';
case KeyCode.LeftArrow:
return 'Left';
case KeyCode.RightArrow:
return 'Right';
}
return KeyCodeUtils.toString(keyCode);
}
public getElectronAccelerator(): string {
if (this._actual.isChord()) {
// Electron cannot handle chords
return null;
}
let keyCode = this._actual.getKeyCode();
if (keyCode >= KeyCode.NUMPAD_0 && keyCode <= KeyCode.NUMPAD_DIVIDE) {
// Electron cannot handle numpad keys
return null;
}
const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToElectronAccelerator, this._os);
return ElectronAcceleratorLabelProvider.toLabel2(firstPart, chordPart, this._os);
}
private static _usKeyCodeToUserSettings(keyCode: KeyCode, OS: OperatingSystem): string {
return USER_SETTINGS.fromKeyCode(keyCode);
}
public getUserSettingsLabel(): string {
const [firstPart, chordPart] = PrintableKeypress.fromKeybinding(this._actual, USLayoutResolvedKeybinding._usKeyCodeToUserSettings, this._os);
let result = UserSettingsLabelProvider.toLabel2(firstPart, chordPart, this._os);
return result.toLowerCase();
}
public isChord(): boolean {
return this._actual.isChord();
}
public hasCtrlModifier(): boolean {
if (this._actual.isChord()) {
return false;
}
if (this._os === OperatingSystem.Macintosh) {
return this._actual.hasWinCtrl();
} else {
return this._actual.hasCtrlCmd();
}
}
public hasShiftModifier(): boolean {
if (this._actual.isChord()) {
return false;
}
return this._actual.hasShift();
}
public hasAltModifier(): boolean {
if (this._actual.isChord()) {
return false;
}
return this._actual.hasAlt();
}
public hasMetaModifier(): boolean {
if (this._actual.isChord()) {
return false;
}
if (this._os === OperatingSystem.Macintosh) {
return this._actual.hasCtrlCmd();
} else {
return this._actual.hasWinCtrl();
}
}
public getDispatchParts(): [string, string] {
let keypressFirstPart: string;
let keypressChordPart: string;
if (this._actual === null) {
keypressFirstPart = null;
keypressChordPart = null;
} else if (this._actual.isChord()) {
keypressFirstPart = this._actual.extractFirstPart().value.toString();
keypressChordPart = this._actual.extractChordPart().value.toString();
} else {
keypressFirstPart = this._actual.value.toString();
keypressChordPart = null;
}
return [keypressFirstPart, keypressChordPart];
}
}
......@@ -6,7 +6,8 @@
import * as assert from 'assert';
import { ResolvedKeybinding, Keybinding, SimpleKeybinding, createKeybinding, KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { USLayoutResolvedKeybinding, AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { IDisposable } from 'vs/base/common/lifecycle';
import Severity from 'vs/base/common/severity';
import { ICommandService } from 'vs/platform/commands/common/commands';
......
......@@ -7,7 +7,7 @@
import * as assert from 'assert';
import { createKeybinding, KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { IHTMLContentElement } from 'vs/base/common/htmlContent';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { OperatingSystem } from 'vs/base/common/platform';
suite('KeybindingLabels', () => {
......
......@@ -9,7 +9,7 @@ import { createKeybinding, SimpleKeybinding, KeyCode, KeyMod, KeyChord } from 'v
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
import { ContextKeyAndExpr, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { OS } from 'vs/base/common/platform';
suite('KeybindingResolver', () => {
......
......@@ -9,7 +9,7 @@ import Event from 'vs/base/common/event';
import { IKeybindingService, IKeybindingEvent, IKeybindingItem2 } from 'vs/platform/keybinding/common/keybinding';
import { IContextKey, IContextKeyService, IContextKeyServiceTarget, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { OS } from 'vs/base/common/platform';
class MockKeybindingContextKey<T> implements IContextKey<T> {
......
......@@ -24,7 +24,7 @@ import { CodeSnippet } from 'vs/editor/contrib/snippet/common/snippet';
import { SnippetController } from 'vs/editor/contrib/snippet/common/snippetController';
import { SmartSnippetInserter } from 'vs/workbench/parts/preferences/common/smartSnippetInserter';
import { DefineKeybindingOverlayWidget } from 'vs/workbench/parts/preferences/browser/keybindingWidgets';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { OS } from 'vs/base/common/platform';
import EditorContextKeys = editorCommon.EditorContextKeys;
......
......@@ -17,7 +17,7 @@ import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { IModelService } from 'vs/editor/common/services/modelService';
import { Tree } from 'vs/base/parts/tree/browser/treeImpl';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { OS } from 'vs/base/common/platform';
suite('Search Actions', () => {
......
......@@ -13,7 +13,8 @@ import { OS, OperatingSystem } from 'vs/base/common/platform';
import { toDisposable } from 'vs/base/common/lifecycle';
import { ExtensionMessageCollector, ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
import { Extensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { AbstractKeybindingService, USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver';
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
......
......@@ -9,7 +9,7 @@ import { createKeybinding, KeyCode, KeyMod, KeyChord, KeyCodeUtils } from 'vs/ba
import { KeybindingIO } from 'vs/workbench/services/keybinding/common/keybindingIO';
import { OS, OperatingSystem } from 'vs/base/common/platform';
import { IUserFriendlyKeybinding } from 'vs/platform/keybinding/common/keybinding';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
suite('keybindingIO', () => {
test('getUserSettingsKeybindingRegex', () => {
......
......@@ -10,7 +10,7 @@ import { KeyMod, KeyCode, SimpleKeybinding, createKeybinding, Keybinding } from
import { KeyboardMapper, IKeyboardMapping } from 'vs/workbench/services/keybinding/common/keyboardMapper';
import { OperatingSystem } from 'vs/base/common/platform';
import { UserSettingsLabelProvider, PrintableKeypress } from 'vs/platform/keybinding/common/keybindingLabels';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
import { KeyboardEventCodeUtils } from 'vs/workbench/services/keybinding/common/keyboardEventCode';
import { IHTMLContentElement } from 'vs/base/common/htmlContent';
import { readFile, writeFile } from 'vs/base/node/pfs';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册