UNPKG

7.78 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26var __param = (this && this.__param) || function (paramIndex, decorator) {
27 return function (target, key) { decorator(target, key, paramIndex); }
28};
29Object.defineProperty(exports, "__esModule", { value: true });
30exports.ElectronContextMenuRenderer = exports.ElectronTextInputContextMenuContribution = exports.ElectronTextInputContextMenu = exports.ElectronContextMenuAccess = void 0;
31/* eslint-disable @typescript-eslint/no-explicit-any */
32const inversify_1 = require("inversify");
33const browser_1 = require("../../browser");
34const electron_main_menu_factory_1 = require("./electron-main-menu-factory");
35const context_menu_context_1 = require("../../browser/menu/context-menu-context");
36const browser_context_menu_renderer_1 = require("../../browser/menu/browser-context-menu-renderer");
37class ElectronContextMenuAccess extends browser_1.ContextMenuAccess {
38 constructor(menuHandle) {
39 super({
40 dispose: () => menuHandle.then(handle => window.electronTheiaCore.closePopup(handle))
41 });
42 this.menuHandle = menuHandle;
43 }
44}
45exports.ElectronContextMenuAccess = ElectronContextMenuAccess;
46var ElectronTextInputContextMenu;
47(function (ElectronTextInputContextMenu) {
48 ElectronTextInputContextMenu.MENU_PATH = ['electron_text_input'];
49 ElectronTextInputContextMenu.UNDO_REDO_EDIT_GROUP = [...ElectronTextInputContextMenu.MENU_PATH, '0_undo_redo_group'];
50 ElectronTextInputContextMenu.EDIT_GROUP = [...ElectronTextInputContextMenu.MENU_PATH, '1_edit_group'];
51 ElectronTextInputContextMenu.SELECT_GROUP = [...ElectronTextInputContextMenu.MENU_PATH, '2_select_group'];
52})(ElectronTextInputContextMenu = exports.ElectronTextInputContextMenu || (exports.ElectronTextInputContextMenu = {}));
53let ElectronTextInputContextMenuContribution = class ElectronTextInputContextMenuContribution {
54 onStart() {
55 window.document.addEventListener('contextmenu', event => {
56 if (event.target instanceof HTMLElement) {
57 const target = event.target;
58 if (target.nodeName && (target.nodeName.toLowerCase() === 'input' || target.nodeName.toLowerCase() === 'textarea')) {
59 event.preventDefault();
60 event.stopPropagation();
61 this.contextMenuRenderer.render({
62 anchor: event,
63 menuPath: ElectronTextInputContextMenu.MENU_PATH,
64 onHide: () => target.focus()
65 });
66 }
67 }
68 });
69 }
70 registerMenus(registry) {
71 registry.registerMenuAction(ElectronTextInputContextMenu.UNDO_REDO_EDIT_GROUP, { commandId: browser_1.CommonCommands.UNDO.id });
72 registry.registerMenuAction(ElectronTextInputContextMenu.UNDO_REDO_EDIT_GROUP, { commandId: browser_1.CommonCommands.REDO.id });
73 registry.registerMenuAction(ElectronTextInputContextMenu.EDIT_GROUP, { commandId: browser_1.CommonCommands.CUT.id });
74 registry.registerMenuAction(ElectronTextInputContextMenu.EDIT_GROUP, { commandId: browser_1.CommonCommands.COPY.id });
75 registry.registerMenuAction(ElectronTextInputContextMenu.EDIT_GROUP, { commandId: browser_1.CommonCommands.PASTE.id });
76 registry.registerMenuAction(ElectronTextInputContextMenu.SELECT_GROUP, { commandId: browser_1.CommonCommands.SELECT_ALL.id });
77 }
78};
79__decorate([
80 (0, inversify_1.inject)(browser_1.ContextMenuRenderer),
81 __metadata("design:type", browser_1.ContextMenuRenderer)
82], ElectronTextInputContextMenuContribution.prototype, "contextMenuRenderer", void 0);
83ElectronTextInputContextMenuContribution = __decorate([
84 (0, inversify_1.injectable)()
85], ElectronTextInputContextMenuContribution);
86exports.ElectronTextInputContextMenuContribution = ElectronTextInputContextMenuContribution;
87let ElectronContextMenuRenderer = class ElectronContextMenuRenderer extends browser_context_menu_renderer_1.BrowserContextMenuRenderer {
88 constructor(electronMenuFactory) {
89 super(electronMenuFactory);
90 this.electronMenuFactory = electronMenuFactory;
91 this.useNativeStyle = true;
92 }
93 init() {
94 this.doInit();
95 }
96 async doInit() {
97 this.useNativeStyle = await window.electronTheiaCore.getTitleBarStyleAtStartup() === 'native';
98 }
99 doRender(options) {
100 if (this.useNativeStyle) {
101 const { menuPath, anchor, args, onHide, context, contextKeyService, skipSingleRootNode } = options;
102 const menu = this.electronMenuFactory.createElectronContextMenu(menuPath, args, context, contextKeyService, skipSingleRootNode);
103 const { x, y } = (0, browser_1.coordinateFromAnchor)(anchor);
104 const menuHandle = window.electronTheiaCore.popup(menu, x, y, () => {
105 if (onHide) {
106 onHide();
107 }
108 });
109 // native context menu stops the event loop, so there is no keyboard events
110 this.context.resetAltPressed();
111 return new ElectronContextMenuAccess(menuHandle);
112 }
113 else {
114 return super.doRender(options);
115 }
116 }
117};
118__decorate([
119 (0, inversify_1.inject)(context_menu_context_1.ContextMenuContext),
120 __metadata("design:type", context_menu_context_1.ContextMenuContext)
121], ElectronContextMenuRenderer.prototype, "context", void 0);
122__decorate([
123 (0, inversify_1.inject)(browser_1.PreferenceService),
124 __metadata("design:type", Object)
125], ElectronContextMenuRenderer.prototype, "preferenceService", void 0);
126__decorate([
127 (0, inversify_1.postConstruct)(),
128 __metadata("design:type", Function),
129 __metadata("design:paramtypes", []),
130 __metadata("design:returntype", void 0)
131], ElectronContextMenuRenderer.prototype, "init", null);
132ElectronContextMenuRenderer = __decorate([
133 (0, inversify_1.injectable)(),
134 __param(0, (0, inversify_1.inject)(electron_main_menu_factory_1.ElectronMainMenuFactory)),
135 __metadata("design:paramtypes", [electron_main_menu_factory_1.ElectronMainMenuFactory])
136], ElectronContextMenuRenderer);
137exports.ElectronContextMenuRenderer = ElectronContextMenuRenderer;
138//# sourceMappingURL=electron-context-menu-renderer.js.map
\No newline at end of file