@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
105 lines • 4.92 kB
JavaScript
// *****************************************************************************
// Copyright (C) 2019 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { __decorate } from "tslib";
import { inject, injectable, optional } from 'inversify';
import { isOSX } from '../../common/os.js';
import { Command } from '../../common/command.js';
import { BrowserKeyboardLayoutProvider } from './browser-keyboard-layout-provider.js';
import { QuickInputService } from '../quick-input/index.js';
import { nls } from '../../common/nls.js';
export var KeyboardCommands;
(function (KeyboardCommands) {
const KEYBOARD_CATEGORY = 'Keyboard';
const KEYBOARD_CATEGORY_KEY = nls.getDefaultKey(KEYBOARD_CATEGORY);
KeyboardCommands.CHOOSE_KEYBOARD_LAYOUT = Command.toLocalizedCommand({
id: 'core.keyboard.choose',
category: KEYBOARD_CATEGORY,
label: 'Choose Keyboard Layout',
}, 'theia/core/keyboard/choose', KEYBOARD_CATEGORY_KEY);
})(KeyboardCommands || (KeyboardCommands = {}));
let BrowserKeyboardFrontendContribution = class BrowserKeyboardFrontendContribution {
registerCommands(commandRegistry) {
commandRegistry.registerCommand(KeyboardCommands.CHOOSE_KEYBOARD_LAYOUT, {
execute: () => this.chooseLayout()
});
}
async chooseLayout() {
const current = this.layoutProvider.currentLayoutData;
const autodetect = {
label: nls.localizeByDefault('Auto Detect'),
description: this.layoutProvider.layoutSource !== 'user-choice' ? nls.localize('theia/core/keyboard/current', '(current: {0})', current.name) : undefined,
detail: nls.localize('theia/core/keyboard/tryDetect', 'Try to detect the keyboard layout from browser information and pressed keys.'),
value: 'autodetect'
};
const pcLayouts = this.layoutProvider.allLayoutData
.filter(layout => layout.hardware === 'pc')
.sort((a, b) => compare(a.name, b.name))
.map(layout => this.toQuickPickValue(layout, current === layout));
const macLayouts = this.layoutProvider.allLayoutData
.filter(layout => layout.hardware === 'mac')
.sort((a, b) => compare(a.name, b.name))
.map(layout => this.toQuickPickValue(layout, current === layout));
let layouts;
const macKeyboards = nls.localize('theia/core/keyboard/mac', 'Mac Keyboards');
const pcKeyboards = nls.localize('theia/core/keyboard/pc', 'PC Keyboards');
if (isOSX) {
layouts = [
autodetect,
{ type: 'separator', label: macKeyboards }, ...macLayouts,
{ type: 'separator', label: pcKeyboards }, ...pcLayouts
];
}
else {
layouts = [
autodetect,
{ type: 'separator', label: pcKeyboards }, ...pcLayouts,
{ type: 'separator', label: macKeyboards }, ...macLayouts
];
}
const selectedItem = await this.quickInputService?.showQuickPick(layouts, { placeholder: nls.localize('theia/core/keyboard/chooseLayout', 'Choose a keyboard layout') });
if (selectedItem && ('value' in selectedItem)) {
return this.layoutProvider.setLayoutData(selectedItem.value);
}
}
toQuickPickValue(layout, isCurrent) {
return {
label: layout.name,
description: `${layout.hardware === 'mac' ? 'Mac' : 'PC'} (${layout.language})${isCurrent ? nls.localize('theia/core/keyboard/currentLayout', ' - current layout') : ''}`,
value: layout
};
}
};
__decorate([
inject(BrowserKeyboardLayoutProvider)
], BrowserKeyboardFrontendContribution.prototype, "layoutProvider", void 0);
__decorate([
inject(QuickInputService),
optional()
], BrowserKeyboardFrontendContribution.prototype, "quickInputService", void 0);
BrowserKeyboardFrontendContribution = __decorate([
injectable()
], BrowserKeyboardFrontendContribution);
export { BrowserKeyboardFrontendContribution };
function compare(a, b) {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
}
//# sourceMappingURL=browser-keyboard-frontend-contribution.js.map