@theia/monaco
Version:
Theia - Monaco Extension
141 lines • 7.29 kB
JavaScript
"use strict";
// *****************************************************************************
// Copyright (C) 2017 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
// *****************************************************************************
Object.defineProperty(exports, "__esModule", { value: true });
exports.MonacoEditorMenuContribution = exports.MonacoMenus = void 0;
const tslib_1 = require("tslib");
const common_1 = require("@theia/core/lib/common");
const nls_1 = require("@theia/core/lib/common/nls");
const inversify_1 = require("@theia/core/shared/inversify");
const browser_1 = require("@theia/editor/lib/browser");
const actions_1 = require("@theia/monaco-editor-core/esm/vs/platform/actions/common/actions");
const monaco_command_1 = require("./monaco-command");
const monaco_command_registry_1 = require("./monaco-command-registry");
var MonacoMenus;
(function (MonacoMenus) {
MonacoMenus.SELECTION = [...common_1.MAIN_MENU_BAR, '3_selection'];
MonacoMenus.PEEK_CONTEXT_SUBMENU = [...browser_1.EDITOR_CONTEXT_MENU, 'navigation', 'peek_submenu'];
MonacoMenus.MARKERS_GROUP = [...browser_1.EditorMainMenu.GO, '5_markers_group'];
})(MonacoMenus || (exports.MonacoMenus = MonacoMenus = {}));
let MonacoEditorMenuContribution = class MonacoEditorMenuContribution {
constructor(commands) {
this.commands = commands;
}
registerMenus(registry) {
registry.registerSubmenu(browser_1.EDITOR_CONTEXT_MENU, 'Editor Context Menu');
for (const item of actions_1.MenuRegistry.getMenuItems(actions_1.MenuId.EditorContext)) {
if (!(0, actions_1.isIMenuItem)(item)) {
continue;
}
const commandId = this.commands.validate(item.command.id);
if (commandId) {
const nodeId = monaco_command_1.MonacoCommands.COMMON_ACTIONS.get(commandId) || commandId;
const menuPath = item.group ? [...browser_1.EDITOR_CONTEXT_MENU, item.group] : browser_1.EDITOR_CONTEXT_MENU;
if (!registry.getMenuNode([...menuPath, nodeId])) {
// Don't add additional actions if the item is already registered.
registry.registerMenuAction(menuPath, this.buildMenuAction(commandId, item));
}
}
}
this.registerPeekSubmenu(registry);
registry.registerSubmenu(MonacoMenus.SELECTION, nls_1.nls.localizeByDefault('Selection'));
for (const item of actions_1.MenuRegistry.getMenuItems(actions_1.MenuId.MenubarSelectionMenu)) {
if (!(0, actions_1.isIMenuItem)(item)) {
continue;
}
const commandId = this.commands.validate(item.command.id);
if (commandId) {
const menuPath = [...MonacoMenus.SELECTION, (item.group || '')];
registry.registerMenuAction(menuPath, this.buildMenuAction(commandId, item));
}
}
// Builtin monaco language features commands.
registry.registerMenuAction(browser_1.EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.quickOutline',
label: nls_1.nls.localizeByDefault('Go to Symbol in Editor...'),
order: '1'
});
registry.registerMenuAction(browser_1.EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.revealDefinition',
label: nls_1.nls.localizeByDefault('Go to Definition'),
order: '2'
});
registry.registerMenuAction(browser_1.EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.revealDeclaration',
label: nls_1.nls.localizeByDefault('Go to Declaration'),
order: '3'
});
registry.registerMenuAction(browser_1.EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.goToTypeDefinition',
label: nls_1.nls.localizeByDefault('Go to Type Definition'),
order: '4'
});
registry.registerMenuAction(browser_1.EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.goToImplementation',
label: nls_1.nls.localizeByDefault('Go to Implementations'),
order: '5'
});
registry.registerMenuAction(browser_1.EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.goToReferences',
label: nls_1.nls.localizeByDefault('Go to References'),
order: '6'
});
registry.registerMenuAction(browser_1.EditorMainMenu.LOCATION_GROUP, {
commandId: 'editor.action.jumpToBracket',
label: nls_1.nls.localizeByDefault('Go to Bracket'),
order: '2'
});
// Builtin monaco problem commands.
registry.registerMenuAction(MonacoMenus.MARKERS_GROUP, {
commandId: 'editor.action.marker.nextInFiles',
label: nls_1.nls.localizeByDefault('Next Problem'),
order: '1'
});
registry.registerMenuAction(MonacoMenus.MARKERS_GROUP, {
commandId: 'editor.action.marker.prevInFiles',
label: nls_1.nls.localizeByDefault('Previous Problem'),
order: '2'
});
}
registerPeekSubmenu(registry) {
registry.registerSubmenu(MonacoMenus.PEEK_CONTEXT_SUBMENU, nls_1.nls.localizeByDefault('Peek'));
for (const item of actions_1.MenuRegistry.getMenuItems(actions_1.MenuId.EditorContextPeek)) {
if (!(0, actions_1.isIMenuItem)(item)) {
continue;
}
const commandId = this.commands.validate(item.command.id);
if (commandId) {
registry.registerMenuAction([...MonacoMenus.PEEK_CONTEXT_SUBMENU, item.group || ''], this.buildMenuAction(commandId, item));
}
}
}
buildMenuAction(commandId, item) {
const title = typeof item.command.title === 'string' ? item.command.title : item.command.title.value;
const label = this.removeMnemonic(title);
const order = item.order ? String(item.order) : '';
return { commandId, order, label };
}
removeMnemonic(label) {
return label.replace(/\(&&\w\)|&&/g, '');
}
};
exports.MonacoEditorMenuContribution = MonacoEditorMenuContribution;
exports.MonacoEditorMenuContribution = MonacoEditorMenuContribution = tslib_1.__decorate([
(0, inversify_1.injectable)(),
tslib_1.__param(0, (0, inversify_1.inject)(monaco_command_registry_1.MonacoCommandRegistry)),
tslib_1.__metadata("design:paramtypes", [monaco_command_registry_1.MonacoCommandRegistry])
], MonacoEditorMenuContribution);
//# sourceMappingURL=monaco-menu.js.map