提交 a24d186d 编写于 作者: P Peng Lyu

refactor, move keyboard layout provider into keymapper factory

上级 8f3ba7e3
......@@ -33,27 +33,40 @@ export class KeyboardLayoutPickerContribution extends Disposable implements IWor
super();
let layout = this.keymapService.getCurrentKeyboardLayout();
let layoutInfo = (<any>layout).text || (<any>layout).lang || (<any>layout).model;
this.pickerElement.value = this.statusbarService.addEntry(
{
text: `Layout: ${layoutInfo}`,
// tooltip: nls.localize('keyboard.layout.tooltip', "If you are not using a Screen Reader, please change the setting `editor.accessibilitySupport` to \"off\"."),
command: KEYBOARD_LAYOUT_OPEN_PICKER
},
'status.editor.screenReaderMode',
nls.localize('status.editor.screenReaderMode', "Screen Reader Mode"),
StatusbarAlignment.RIGHT
);
if (layout) {
let layoutInfo = (<any>layout).text || (<any>layout).lang || (<any>layout).model;
this.pickerElement.value = this.statusbarService.addEntry(
{
text: `Layout: ${layoutInfo}`,
// tooltip: nls.localize('keyboard.layout.tooltip', "If you are not using a Screen Reader, please change the setting `editor.accessibilitySupport` to \"off\"."),
command: KEYBOARD_LAYOUT_OPEN_PICKER
},
'status.editor.screenReaderMode',
nls.localize('status.editor.screenReaderMode', "Screen Reader Mode"),
StatusbarAlignment.RIGHT
);
}
this._register(keymapService.onDidChangeKeyboardMapper(() => {
if (this.pickerElement.value) {
let layout = this.keymapService.getCurrentKeyboardLayout();
let layoutInfo = (<any>layout).text || (<any>layout).lang || (<any>layout).model;
let layout = this.keymapService.getCurrentKeyboardLayout();
let layoutInfo = (<any>layout).text || (<any>layout).lang || (<any>layout).model;
if (this.pickerElement.value) {
this.pickerElement.value.update({
text: `Layout: ${layoutInfo}`,
command: KEYBOARD_LAYOUT_OPEN_PICKER
});
} else {
this.pickerElement.value = this.statusbarService.addEntry(
{
text: `Layout: ${layoutInfo}`,
// tooltip: nls.localize('keyboard.layout.tooltip', "If you are not using a Screen Reader, please change the setting `editor.accessibilitySupport` to \"off\"."),
command: KEYBOARD_LAYOUT_OPEN_PICKER
},
'status.editor.screenReaderMode',
nls.localize('status.editor.screenReaderMode', "Screen Reader Mode"),
StatusbarAlignment.RIGHT
);
}
}));
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
export class KeyboardLayoutContribution {
public static readonly INSTANCE: KeyboardLayoutContribution = new KeyboardLayoutContribution();
private _layoutInfos: KeymapInfo[] = [];
get layoutInfos() {
return this._layoutInfos;
}
private constructor() {
}
registerKeyboardLayout(layout: KeymapInfo) {
this._layoutInfos.push(layout);
}
}
\ No newline at end of file
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000405', id: '', text: 'Czech' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000807', id: '', text: 'Swiss German' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.German', lang: 'de' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ model: 'pc104', layout: 'de', variant: '', options: '', rules: 'base' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000407', id: '', text: 'German' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000406', id: '', text: 'Danish' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000813', id: '', text: 'Belgian (Period)' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.USExtended', lang: 'en' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00004009', id: '', text: 'India' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.USInternational-PC', lang: 'en' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00020409', id: '0001', text: 'United States-International' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.British', lang: 'en' },
[],
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000809', id: '', text: 'United Kingdom' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.US', lang: 'en' },
[
{ id: 'com.apple.keylayout.ABC', lang: 'en' },
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ model: 'pc105', layout: 'us', variant: '', options: '', rules: 'evdev' },
[
{ model: 'pc105', layout: 'cn', variant: '', options: '', rules: 'evdev' },
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000409', id: '', text: 'US' },
[
{ name: '00000804', id: '', text: 'Chinese (Simplified) - US Keyboard' },
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '0000080A', id: '', text: 'Latin American' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.Spanish-ISO', lang: 'es' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ model: 'pc105', layout: 'es', variant: '', options: '', rules: 'evdev' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '0000040A', id: '', text: 'Spanish' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.French', lang: 'fr' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ model: 'pc104', layout: 'fr', variant: '', options: '', rules: 'base' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '0000040C', id: '', text: 'French' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '0000040E', id: '', text: 'Hungarian' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.Italian-Pro', lang: 'it' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000410', id: '', text: 'Italian' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.google.inputmethod.Japanese.Roman', lang: 'en' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.inputmethod.Kotoeri.Japanese', lang: 'ja' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.inputmethod.Korean.2SetKorean', lang: 'ko' },
[],
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000414', id: '', text: 'Norwegian' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.PolishPro', lang: 'pl' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000415', id: '', text: 'Polish (Programmers)' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000416', id: '', text: 'Portuguese (Brazilian ABNT)' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.Brazilian-Pro', lang: 'pt' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000816', id: '', text: 'Portuguese' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.Russian', lang: 'ru' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ model: 'pc104', layout: 'ru', variant: ',', options: '', rules: 'base' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '00000419', id: '', text: 'Russian' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.keylayout.Swedish-Pro', lang: 'sv' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '0000041D', id: '', text: 'Swedish' },
[
{ name: '0000040B', id: '', text: 'Finnish' }
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '0000041E', id: '', text: 'Thai Kedmanee' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout((new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout((new KeymapInfo(
{ name: '0000041F', id: '', text: 'Turkish Q' },
[],
{
......
......@@ -3,9 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(new KeyboardLayoutInfo(
KeyboardLayoutContribution.INSTANCE.registerKeyboardLayout(new KeymapInfo(
{ id: 'com.apple.inputmethod.SCIM.ITABC', lang: 'zh-Hans' },
[],
{
......
......@@ -17,7 +17,6 @@ import { IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
import { KeyCodeUtils, KeyCode } from 'vs/base/common/keyCodes';
import { IMacLinuxKeyboardMapping, MacLinuxKeyboardMapper } from 'vs/workbench/services/keybinding/common/macLinuxKeyboardMapper';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyboardLayoutProvider, KeyboardLayoutInfo } from 'vs/workbench/services/keybinding/browser/keyboardLayoutProvider';
import { URI } from 'vs/base/common/uri';
import { IFileService, FileChangesEvent, FileChangeType } from 'vs/platform/files/common/files';
import { RunOnceScheduler } from 'vs/base/common/async';
......@@ -29,25 +28,58 @@ import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as ConfigExtensions, IConfigurationRegistry, IConfigurationNode } from 'vs/platform/configuration/common/configurationRegistry';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { INavigatorWithKeyboard } from 'vs/workbench/services/keybinding/common/navigatorKeyboard';
import { KeymapInfo } from 'vs/workbench/services/keybinding/common/keymapInfo';
import { KeyboardLayoutContribution } from 'vs/workbench/services/keybinding/browser/keyboardLayouts/_.contribution';
export class BrowserKeyboardMapperFactory {
public static readonly INSTANCE = new BrowserKeyboardMapperFactory();
private _layoutInfo: IKeyboardLayoutInfo | null;
private _rawMapping: IKeyboardMapping | null;
private _keyboardMapper: IKeyboardMapper | null;
// keyboard mapper
private _initialized: boolean;
private _keyboardMapper: IKeyboardMapper | null;
private readonly _onDidChangeKeyboardMapper = new Emitter<void>();
public readonly onDidChangeKeyboardMapper: Event<void> = this._onDidChangeKeyboardMapper.event;
// keymap infos
private _keymapInfos: KeymapInfo[];
private _mru: KeymapInfo[];
private _activeKeymapInfo: KeymapInfo | null;
get keymapInfos(): KeymapInfo[] {
return this._keymapInfos;
}
get activeKeyboardLayout(): IKeyboardLayoutInfo | null {
if (!this._initialized) {
return null;
}
return this._activeKeymapInfo && this._activeKeymapInfo.layout;
}
get activeKeyMapping(): IKeyboardMapping | null {
if (!this._initialized) {
return null;
}
return this._activeKeymapInfo && this._activeKeymapInfo.mapping;
}
get keyboardLayouts(): IKeyboardLayoutInfo[] {
return this._keymapInfos.map(keymapInfo => keymapInfo.layout);
}
private constructor() {
this._layoutInfo = null;
this._rawMapping = null;
this._keyboardMapper = null;
this._initialized = false;
this._keymapInfos = [];
this._mru = [];
this._activeKeymapInfo = null;
const platform = isWindows ? 'win' : isMacintosh ? 'darwin' : 'linux';
import('vs/workbench/services/keybinding/browser/keyboardlayouts/layout.contribution.' + platform).then(() => {
import('vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.' + platform).then(() => {
this._keymapInfos.push(...KeyboardLayoutContribution.INSTANCE.layoutInfos);
this._mru = this._keymapInfos;
this._initialized = true;
this.onKeyboardLayoutChanged();
});
......@@ -55,8 +87,8 @@ export class BrowserKeyboardMapperFactory {
if ((<INavigatorWithKeyboard>navigator).keyboard && (<INavigatorWithKeyboard>navigator).keyboard.addEventListener) {
(<INavigatorWithKeyboard>navigator).keyboard.addEventListener!('layoutchange', () => {
// Update user keyboard map settings
this.getBrowserKeyMap().then((keymap: IKeyboardMapping) => {
if (KeyboardLayoutProvider.INSTANCE.isActive(keymap)) {
this._getBrowserKeyMapping().then((mapping: IKeyboardMapping) => {
if (this.isKeyMappingActive(mapping)) {
return;
}
......@@ -66,6 +98,62 @@ export class BrowserKeyboardMapperFactory {
}
}
registerKeyboardLayout(layout: KeymapInfo) {
this._keymapInfos.push(layout);
this._mru = this._keymapInfos;
}
removeKeyboardLayout(layout: KeymapInfo): void {
let index = this._mru.indexOf(layout);
this._mru.splice(index, 1);
index = this._keymapInfos.indexOf(layout);
this._keymapInfos.splice(index, 1);
}
getMatchedKeymapInfo(keyMapping: IKeyboardMapping): KeymapInfo | null {
for (let i = 0; i < this._mru.length; i++) {
if (this._mru[i].fuzzyEqual(keyMapping)) {
return this._mru[i];
}
}
return null;
}
isKeyMappingActive(keymap: IKeyboardMapping) {
return this._activeKeymapInfo && this._activeKeymapInfo.fuzzyEqual(keymap);
}
setActiveKeyMapping(keymap: IKeyboardMapping) {
this._activeKeymapInfo = this.getMatchedKeymapInfo(keymap);
if (!this._activeKeymapInfo) {
return;
}
const index = this._mru.indexOf(this._activeKeymapInfo);
this._mru.splice(index, 1);
this._mru.unshift(this._activeKeymapInfo);
this._setKeyboardData(this._activeKeymapInfo);
}
setActiveKeymapInfo(keymapInfo: KeymapInfo) {
this._activeKeymapInfo = keymapInfo;
const index = this._mru.indexOf(this._activeKeymapInfo);
if (index === 0) {
return;
}
this._mru.splice(index, 1);
this._mru.unshift(this._activeKeymapInfo);
this._setKeyboardData(this._activeKeymapInfo);
}
public onKeyboardLayoutChanged(): void {
this._updateKeyboardLayoutAsync(this._initialized);
}
......@@ -75,17 +163,12 @@ export class BrowserKeyboardMapperFactory {
return;
}
this.getBrowserKeyMap().then(keyMap => {
this._getBrowserKeyMapping().then(keyMap => {
// might be false positive
if (KeyboardLayoutProvider.INSTANCE.isActive(keyMap)) {
if (this.isKeyMappingActive(keyMap)) {
return;
}
KeyboardLayoutProvider.INSTANCE.setActive(keyMap);
let currentKeyboardLayout = KeyboardLayoutProvider.INSTANCE.activeKeyboardLayout;
if (currentKeyboardLayout) {
this._setKeyboardData(currentKeyboardLayout.layout, keyMap);
}
this.setActiveKeyMapping(keyMap);
});
}
......@@ -101,17 +184,6 @@ export class BrowserKeyboardMapperFactory {
}
public getCurrentKeyboardLayout(): IKeyboardLayoutInfo | null {
if (!this._initialized) {
return null;
}
return this._layoutInfo;
}
public getAllKeyboardLayouts(): IKeyboardLayoutInfo[] {
return KeyboardLayoutProvider.INSTANCE.getKeyboardLayouts().map(info => info.layout);
}
public validateCurrentKeyboardMapping(keyboardEvent: IKeyboardEvent): void {
if (!this._initialized) {
return;
......@@ -126,18 +198,75 @@ export class BrowserKeyboardMapperFactory {
this._updateKeyboardLayoutAsync(true);
}
public setKeyboardLayout(layoutName: string) {
let allKeyboardLayouts = this.keymapInfos;
let matchedLayouts: KeymapInfo[] = [];
if (isWindows) {
matchedLayouts = allKeyboardLayouts.filter(layout => (<IWindowsKeyboardLayoutInfo>layout.layout).name === layoutName);
}
if (isMacintosh) {
// todo, probably we should use layout.id?
matchedLayouts = allKeyboardLayouts.filter(layout => (<IMacKeyboardLayoutInfo>layout.layout).lang === layoutName);
}
if (isLinux) {
// todo, probably we should use layout.id?
matchedLayouts = allKeyboardLayouts.filter(layout => (<ILinuxKeyboardLayoutInfo>layout.layout).layout === layoutName);
}
if (matchedLayouts.length > 0) {
this.setActiveKeymapInfo(matchedLayouts[0]);
}
}
private _setKeyboardData(keymapInfo: KeymapInfo): void {
this._initialized = true;
this._keyboardMapper = new CachedKeyboardMapper(BrowserKeyboardMapperFactory._createKeyboardMapper(keymapInfo.mapping));
this._onDidChangeKeyboardMapper.fire();
}
private static _isUSStandard(rawMapping: IKeyboardMapping): boolean {
for (let key in rawMapping) {
let str = rawMapping[key].value;
let keyCode = KeyCodeUtils.fromString(str);
let usKeyCode = US_SCANCODE_MAP[key];
if (keyCode !== usKeyCode) {
return false;
}
}
return true;
}
private static _createKeyboardMapper(rawMapping: IKeyboardMapping): IKeyboardMapper {
const isUSStandard = BrowserKeyboardMapperFactory._isUSStandard(rawMapping);
if (OS === OperatingSystem.Windows) {
return new WindowsKeyboardMapper(isUSStandard, <IWindowsKeyboardMapping>rawMapping);
}
if (Object.keys(rawMapping).length === 0) {
// Looks like reading the mappings failed (most likely Mac + Japanese/Chinese keyboard layouts)
return new MacLinuxFallbackKeyboardMapper(OS);
}
return new MacLinuxKeyboardMapper(isUSStandard, <IMacLinuxKeyboardMapping>rawMapping, OS);
}
//#region Browser API
private _validateCurrentKeyboardMapping(keyboardEvent: IKeyboardEvent): boolean {
if (!this._initialized) {
return true;
}
const standardKeyboardEvent = keyboardEvent as StandardKeyboardEvent;
const currentKeymap = KeyboardLayoutProvider.INSTANCE.activeKeyboardLayout;
const currentKeymap = this._activeKeymapInfo;
if (!currentKeymap) {
return true;
}
const mapping = currentKeymap.value[standardKeyboardEvent.code];
const mapping = currentKeymap.mapping[standardKeyboardEvent.code];
if (!mapping) {
return false;
......@@ -147,8 +276,8 @@ export class BrowserKeyboardMapperFactory {
// we don't undetstand
if (keyboardEvent.ctrlKey || keyboardEvent.metaKey) {
setTimeout(() => {
this.getBrowserKeyMap().then((keymap: IKeyboardMapping) => {
if (KeyboardLayoutProvider.INSTANCE.isActive(keymap)) {
this._getBrowserKeyMapping().then((keymap: IKeyboardMapping) => {
if (this.isKeyMappingActive(keymap)) {
return;
}
......@@ -180,79 +309,7 @@ export class BrowserKeyboardMapperFactory {
return true;
}
public getRawKeyboardMapping(): IKeyboardMapping | null {
if (!this._initialized) {
return null;
}
return this._rawMapping;
}
public setKeyboardLayout(layoutName: string) {
let allKeyboardLayouts = KeyboardLayoutProvider.INSTANCE.getKeyboardLayouts();
let matchedLayouts: KeyboardLayoutInfo[] = [];
if (isWindows) {
matchedLayouts = allKeyboardLayouts.filter(layout => (<IWindowsKeyboardLayoutInfo>layout.layout).name === layoutName);
}
if (isMacintosh) {
// todo, probably we should use layout.id?
matchedLayouts = allKeyboardLayouts.filter(layout => (<IMacKeyboardLayoutInfo>layout.layout).lang === layoutName);
}
if (isLinux) {
// todo, probably we should use layout.id?
matchedLayouts = allKeyboardLayouts.filter(layout => (<ILinuxKeyboardLayoutInfo>layout.layout).layout === layoutName);
}
if (matchedLayouts.length > 0) {
KeyboardLayoutProvider.INSTANCE.setActive2(matchedLayouts[0]);
let currentKeyboardLayout = KeyboardLayoutProvider.INSTANCE.activeKeyboardLayout;
if (currentKeyboardLayout) {
this._setKeyboardData(currentKeyboardLayout.layout, currentKeyboardLayout.value);
return;
}
}
}
private _setKeyboardData(layoutInfo: IKeyboardLayoutInfo, rawMapping: IKeyboardMapping): void {
this._layoutInfo = layoutInfo;
this._initialized = true;
this._rawMapping = rawMapping;
this._keyboardMapper = new CachedKeyboardMapper(BrowserKeyboardMapperFactory._createKeyboardMapper(this._layoutInfo, this._rawMapping));
this._onDidChangeKeyboardMapper.fire();
}
private static _isUSStandard(rawMapping: IKeyboardMapping): boolean {
for (let key in rawMapping) {
let str = rawMapping[key].value;
let keyCode = KeyCodeUtils.fromString(str);
let usKeyCode = US_SCANCODE_MAP[key];
if (keyCode !== usKeyCode) {
return false;
}
}
return true;
}
private static _createKeyboardMapper(layoutInfo: IKeyboardLayoutInfo, rawMapping: IKeyboardMapping): IKeyboardMapper {
const isUSStandard = BrowserKeyboardMapperFactory._isUSStandard(rawMapping);
if (OS === OperatingSystem.Windows) {
return new WindowsKeyboardMapper(isUSStandard, <IWindowsKeyboardMapping>rawMapping);
}
if (Object.keys(rawMapping).length === 0) {
// Looks like reading the mappings failed (most likely Mac + Japanese/Chinese keyboard layouts)
return new MacLinuxFallbackKeyboardMapper(OS);
}
return new MacLinuxKeyboardMapper(isUSStandard, <IMacLinuxKeyboardMapping>rawMapping, OS);
}
async getBrowserKeyMap() {
private async _getBrowserKeyMapping() {
if ((navigator as any).keyboard) {
try {
return (navigator as any).keyboard.getLayoutMap().then((e: any) => {
......@@ -266,10 +323,10 @@ export class BrowserKeyboardMapperFactory {
};
}
const matchedKeyboardLayout = KeyboardLayoutProvider.INSTANCE.getMatchedKeyboardLayout(ret);
const matchedKeyboardLayout = this.getMatchedKeymapInfo(ret);
if (matchedKeyboardLayout) {
return matchedKeyboardLayout.value;
return matchedKeyboardLayout.mapping;
}
return {};
......@@ -281,8 +338,9 @@ export class BrowserKeyboardMapperFactory {
return {};
}
}
//#endregion
}
export const US_SCANCODE_MAP: { [str: string]: KeyCode; } = {};
......@@ -349,8 +407,8 @@ class UserKeyboardLayout extends Disposable {
private fileWatcherDisposable: IDisposable = Disposable.None;
private directoryWatcherDisposable: IDisposable = Disposable.None;
private _keyboardLayout: KeyboardLayoutInfo | null;
get keyboardLayout(): KeyboardLayoutInfo | null { return this._keyboardLayout; }
private _keyboardLayout: KeymapInfo | null;
get keyboardLayout(): KeymapInfo | null { return this._keyboardLayout; }
constructor(
private readonly keyboardLayoutResource: URI,
......@@ -386,7 +444,7 @@ class UserKeyboardLayout extends Disposable {
const value = parse(content.value.toString());
const layoutInfo = value.layout;
const mappings = value.rawMapping;
this._keyboardLayout = KeyboardLayoutInfo.createKeyboardLayoutFromDebugInfo(layoutInfo, mappings, true);
this._keyboardLayout = KeymapInfo.createKeyboardLayoutFromDebugInfo(layoutInfo, mappings, true);
} catch (e) {
this._keyboardLayout = null;
}
......@@ -466,9 +524,9 @@ class BrowserKeymapService extends Disposable implements IKeymapService {
const keyboardConfig = configurationService.getValue<{ layout: string }>('keyboard');
const layout = keyboardConfig.layout;
if (!layout || layout === 'autodetect') {
this.registerKeyboardListener();
} else {
this.registerKeyboardListener();
if (layout && layout !== 'autodetect') {
// set keyboard layout
BrowserKeyboardMapperFactory.INSTANCE.setKeyboardLayout(layout);
}
......@@ -491,21 +549,21 @@ class BrowserKeymapService extends Disposable implements IKeymapService {
this._userKeyboardLayout.initialize();
if (this._userKeyboardLayout.keyboardLayout) {
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(this._userKeyboardLayout.keyboardLayout);
BrowserKeyboardMapperFactory.INSTANCE.registerKeyboardLayout(this._userKeyboardLayout.keyboardLayout);
}
this._register(this._userKeyboardLayout.onDidChange(() => {
let userKeyboardLayouts = KeyboardLayoutProvider.INSTANCE.getKeyboardLayouts().filter(layout => layout.isUserKeyboardLayout);
let userKeyboardLayouts = BrowserKeyboardMapperFactory.INSTANCE.keymapInfos.filter(layout => layout.isUserKeyboardLayout);
if (userKeyboardLayouts.length) {
if (this._userKeyboardLayout.keyboardLayout) {
userKeyboardLayouts[0].update(this._userKeyboardLayout.keyboardLayout);
} else {
KeyboardLayoutProvider.INSTANCE.removeKeyboardLayout(userKeyboardLayouts[0]);
BrowserKeyboardMapperFactory.INSTANCE.removeKeyboardLayout(userKeyboardLayouts[0]);
}
} else {
if (this._userKeyboardLayout.keyboardLayout) {
KeyboardLayoutProvider.INSTANCE.registerKeyboardLayout(this._userKeyboardLayout.keyboardLayout);
BrowserKeyboardMapperFactory.INSTANCE.registerKeyboardLayout(this._userKeyboardLayout.keyboardLayout);
}
}
......@@ -524,15 +582,15 @@ class BrowserKeymapService extends Disposable implements IKeymapService {
}
public getCurrentKeyboardLayout(): IKeyboardLayoutInfo | null {
return BrowserKeyboardMapperFactory.INSTANCE.getCurrentKeyboardLayout();
return BrowserKeyboardMapperFactory.INSTANCE.activeKeyboardLayout;
}
public getAllKeyboardLayouts(): IKeyboardLayoutInfo[] {
return BrowserKeyboardMapperFactory.INSTANCE.getAllKeyboardLayouts();
return BrowserKeyboardMapperFactory.INSTANCE.keyboardLayouts;
}
public getRawKeyboardMapping(): IKeyboardMapping | null {
return BrowserKeyboardMapperFactory.INSTANCE.getRawKeyboardMapping();
return BrowserKeyboardMapperFactory.INSTANCE.activeKeyMapping;
}
public validateCurrentKeyboardMapping(keyboardEvent: IKeyboardEvent): void {
......
......@@ -65,25 +65,25 @@ interface ISerializedMapping {
[key: string]: (string | number)[];
}
export class KeyboardLayoutInfo {
value: IKeyboardMapping;
export class KeymapInfo {
mapping: IKeyboardMapping;
isUserKeyboardLayout: boolean;
constructor(public layout: IKeyboardLayoutInfo, public secondaryLayouts: IKeyboardLayoutInfo[], keyboardMapping: ISerializedMapping, isUserKeyboardLayout?: boolean) {
this.value = deserializeMapping(keyboardMapping);
this.mapping = deserializeMapping(keyboardMapping);
this.isUserKeyboardLayout = !!isUserKeyboardLayout;
}
static createKeyboardLayoutFromDebugInfo(layout: IKeyboardLayoutInfo, value: IKeyboardMapping, isUserKeyboardLayout?: boolean): KeyboardLayoutInfo {
let keyboardLayoutInfo = new KeyboardLayoutInfo(layout, [], {}, true);
keyboardLayoutInfo.value = value;
static createKeyboardLayoutFromDebugInfo(layout: IKeyboardLayoutInfo, value: IKeyboardMapping, isUserKeyboardLayout?: boolean): KeymapInfo {
let keyboardLayoutInfo = new KeymapInfo(layout, [], {}, true);
keyboardLayoutInfo.mapping = value;
return keyboardLayoutInfo;
}
update(other: KeyboardLayoutInfo) {
update(other: KeymapInfo) {
this.layout = other.layout;
this.secondaryLayouts = other.secondaryLayouts;
this.value = other.value;
this.mapping = other.mapping;
this.isUserKeyboardLayout = other.isUserKeyboardLayout;
}
......@@ -93,11 +93,11 @@ export class KeyboardLayoutInfo {
// keymap from Chromium is probably wrong.
continue;
}
if (this.value[key] === undefined) {
if (this.mapping[key] === undefined) {
return false;
}
let currentMapping = this.value[key];
let currentMapping = this.mapping[key];
let otherMapping = other[key];
if (currentMapping.value !== otherMapping.value) {
......@@ -108,204 +108,3 @@ export class KeyboardLayoutInfo {
return true;
}
}
export const EN_US = new KeyboardLayoutInfo(
{ id: 'com.apple.keylayout.US', lang: 'en' },
[],
{
KeyA: ['a', 'A', 'å', 'Å', 0],
KeyB: ['b', 'B', '', 'ı', 0],
KeyC: ['c', 'C', 'ç', 'Ç', 0],
KeyD: ['d', 'D', '', 'Î', 0],
KeyE: ['e', 'E', '´', '´', 4],
KeyF: ['f', 'F', 'ƒ', 'Ï', 0],
KeyG: ['g', 'G', '©', '˝', 0],
KeyH: ['h', 'H', '˙', 'Ó', 0],
KeyI: ['i', 'I', 'ˆ', 'ˆ', 4],
KeyJ: ['j', 'J', '', 'Ô', 0],
KeyK: ['k', 'K', '˚', '', 0],
KeyL: ['l', 'L', '¬', 'Ò', 0],
KeyM: ['m', 'M', 'µ', 'Â', 0],
KeyN: ['n', 'N', '˜', '˜', 4],
KeyO: ['o', 'O', 'ø', 'Ø', 0],
KeyP: ['p', 'P', 'π', '', 0],
KeyQ: ['q', 'Q', 'œ', 'Œ', 0],
KeyR: ['r', 'R', '®', '', 0],
KeyS: ['s', 'S', 'ß', 'Í', 0],
KeyT: ['t', 'T', '', 'ˇ', 0],
KeyU: ['u', 'U', '¨', '¨', 4],
KeyV: ['v', 'V', '', '', 0],
KeyW: ['w', 'W', '', '', 0],
KeyX: ['x', 'X', '', '˛', 0],
KeyY: ['y', 'Y', '¥', 'Á', 0],
KeyZ: ['z', 'Z', 'Ω', '¸', 0],
Digit1: ['1', '!', '¡', '', 0],
Digit2: ['2', '@', '', '', 0],
Digit3: ['3', '#', '£', '', 0],
Digit4: ['4', '$', '¢', '', 0],
Digit5: ['5', '%', '', '', 0],
Digit6: ['6', '^', '§', '', 0],
Digit7: ['7', '&', '', '', 0],
Digit8: ['8', '*', '', '°', 0],
Digit9: ['9', '(', 'ª', '·', 0],
Digit0: ['0', ')', 'º', '', 0],
Enter: [],
Escape: [],
Backspace: [],
Tab: [],
Space: [' ', ' ', ' ', ' ', 0],
Minus: ['-', '_', '', '', 0],
Equal: ['=', '+', '', '±', 0],
BracketLeft: ['[', '{', '', '', 0],
BracketRight: [']', '}', '', '', 0],
Backslash: ['\\', '|', '«', '»', 0],
Semicolon: [';', ':', '', 'Ú', 0],
Quote: ['\'', '"', 'æ', 'Æ', 0],
Backquote: ['`', '~', '`', '`', 4],
Comma: [',', '<', '', '¯', 0],
Period: ['.', '>', '', '˘', 0],
Slash: ['/', '?', '÷', '¿', 0],
CapsLock: [],
F1: [],
F2: [],
F3: [],
F4: [],
F5: [],
F6: [],
F7: [],
F8: [],
F9: [],
F10: [],
F11: [],
F12: [],
Insert: [],
Home: [],
PageUp: [],
Delete: [],
End: [],
PageDown: [],
ArrowRight: [],
ArrowLeft: [],
ArrowDown: [],
ArrowUp: [],
NumLock: [],
NumpadDivide: ['/', '/', '/', '/', 0],
NumpadMultiply: ['*', '*', '*', '*', 0],
NumpadSubtract: ['-', '-', '-', '-', 0],
NumpadAdd: ['+', '+', '+', '+', 0],
NumpadEnter: [],
Numpad1: ['1', '1', '1', '1', 0],
Numpad2: ['2', '2', '2', '2', 0],
Numpad3: ['3', '3', '3', '3', 0],
Numpad4: ['4', '4', '4', '4', 0],
Numpad5: ['5', '5', '5', '5', 0],
Numpad6: ['6', '6', '6', '6', 0],
Numpad7: ['7', '7', '7', '7', 0],
Numpad8: ['8', '8', '8', '8', 0],
Numpad9: ['9', '9', '9', '9', 0],
Numpad0: ['0', '0', '0', '0', 0],
NumpadDecimal: ['.', '.', '.', '.', 0],
IntlBackslash: ['§', '±', '§', '±', 0],
ContextMenu: [],
NumpadEqual: ['=', '=', '=', '=', 0],
F13: [],
F14: [],
F15: [],
F16: [],
F17: [],
F18: [],
F19: [],
F20: [],
AudioVolumeMute: [],
AudioVolumeUp: ['', '=', '', '=', 0],
AudioVolumeDown: [],
NumpadComma: [],
IntlRo: [],
KanaMode: [],
IntlYen: [],
ControlLeft: [],
ShiftLeft: [],
AltLeft: [],
MetaLeft: [],
ControlRight: [],
ShiftRight: [],
AltRight: [],
MetaRight: []
}
);
export class KeyboardLayoutProvider {
public static readonly INSTANCE: KeyboardLayoutProvider = new KeyboardLayoutProvider();
private _layoutInfos: KeyboardLayoutInfo[] = [];
private _mru: KeyboardLayoutInfo[] = [];
private _active: KeyboardLayoutInfo | null;
private constructor() {
this._active = null;
}
registerKeyboardLayout(layout: KeyboardLayoutInfo) {
this._layoutInfos.push(layout);
this._mru = this._layoutInfos;
}
get activeKeyboardLayout() {
return this._active;
}
isActive(keymap: IKeyboardMapping) {
return this._active && this._active.fuzzyEqual(keymap);
}
setActive(keymap: IKeyboardMapping) {
this._active = this.getMatchedKeyboardLayout(keymap);
if (!this._active) {
return;
}
const index = this._mru.indexOf(this._active);
if (index === 0) {
return;
}
this._mru.splice(index, 1);
this._mru.unshift(this._active);
}
setActive2(layout: KeyboardLayoutInfo) {
this._active = layout;
const index = this._mru.indexOf(this._active);
if (index === 0) {
return;
}
this._mru.splice(index, 1);
this._mru.unshift(this._active);
}
getMatchedKeyboardLayout(keymap: IKeyboardMapping): KeyboardLayoutInfo | null {
// TODO go through mru list instead of _layoutInfos
for (let i = 0; i < this._mru.length; i++) {
if (this._mru[i].fuzzyEqual(keymap)) {
return this._mru[i];
}
}
return null;
}
getKeyboardLayouts(): KeyboardLayoutInfo[] {
return this._layoutInfos;
}
removeKeyboardLayout(layout: KeyboardLayoutInfo): void {
let index = this._mru.indexOf(layout);
this._mru.splice(index, 1);
index = this._layoutInfos.indexOf(layout);
this._layoutInfos.splice(index, 1);
}
}
......@@ -118,7 +118,7 @@ import 'vs/workbench/services/editor/browser/editorService';
import 'vs/workbench/services/history/browser/history';
import 'vs/workbench/services/activity/browser/activityService';
import 'vs/workbench/browser/parts/views/views';
import 'vs/workbench/services/keybinding/browser/keyboardLayoutService';
import 'vs/workbench/services/keybinding/browser/keymapService';
import 'vs/workbench/services/keybinding/browser/keybindingService';
import 'vs/workbench/services/untitled/common/untitledEditorService';
import 'vs/workbench/services/textfile/common/textResourcePropertiesService';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册