1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __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 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | var __param = (this && this.__param) || function (paramIndex, decorator) {
|
27 | return function (target, key) { decorator(target, key, paramIndex); }
|
28 | };
|
29 | Object.defineProperty(exports, "__esModule", { value: true });
|
30 | exports.ElectronContextMenuRenderer = exports.ElectronTextInputContextMenuContribution = exports.ElectronTextInputContextMenu = exports.ElectronContextMenuAccess = void 0;
|
31 |
|
32 | const inversify_1 = require("inversify");
|
33 | const browser_1 = require("../../browser");
|
34 | const electron_main_menu_factory_1 = require("./electron-main-menu-factory");
|
35 | const context_menu_context_1 = require("../../browser/menu/context-menu-context");
|
36 | const browser_context_menu_renderer_1 = require("../../browser/menu/browser-context-menu-renderer");
|
37 | class 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 | }
|
45 | exports.ElectronContextMenuAccess = ElectronContextMenuAccess;
|
46 | var 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 = {}));
|
53 | let 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);
|
83 | ElectronTextInputContextMenuContribution = __decorate([
|
84 | (0, inversify_1.injectable)()
|
85 | ], ElectronTextInputContextMenuContribution);
|
86 | exports.ElectronTextInputContextMenuContribution = ElectronTextInputContextMenuContribution;
|
87 | let 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 |
|
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);
|
132 | ElectronContextMenuRenderer = __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);
|
137 | exports.ElectronContextMenuRenderer = ElectronContextMenuRenderer;
|
138 |
|
\ | No newline at end of file |