UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

143 lines 6.85 kB
"use strict"; /******************************************************************************** * Copyright (c) 2025 EclipseSource 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 WITH Classpath-exception-2.0 ********************************************************************************/ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var ResizeKeyTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResizeKeyTool = exports.ResizeKeyListener = void 0; const sprotty_1 = require("@eclipse-glsp/sprotty"); const inversify_1 = require("inversify"); const vscode_jsonrpc_1 = require("vscode-jsonrpc"); const messages_1 = require("../../../base/messages"); const selection_service_1 = require("../../../base/selection-service"); const toast_handler_1 = require("../../accessibility/toast/toast-handler"); const base_tools_1 = require("../../tools/base-tools"); const model_1 = require("../model"); const resize_handler_1 = require("./resize-handler"); let ResizeKeyListener = class ResizeKeyListener extends sprotty_1.KeyListener { keyDown(element, event) { const actions = []; const selectedElementsIds = this.selectionService .getSelectedElements() .filter(model_1.isResizable) .map(e => e.id); if (selectedElementsIds.length > 0) { if (this.matchesIncreaseSizeKeystroke(event)) { actions.push(resize_handler_1.ResizeElementAction.create(selectedElementsIds, resize_handler_1.ResizeType.Increase)); } else if (this.matchesDecreaseSizeKeystroke(event)) { actions.push(resize_handler_1.ResizeElementAction.create(selectedElementsIds, resize_handler_1.ResizeType.Decrease)); } else if (this.matchesMinSizeKeystroke(event)) { actions.push(resize_handler_1.ResizeElementAction.create(selectedElementsIds, resize_handler_1.ResizeType.MinSize)); } } return actions; } enable() { return [ toast_handler_1.ShowToastMessageAction.create({ id: ResizeKeyTool.TOKEN, message: messages_1.messages.resize.resize_mode_activated }) ]; } disable() { return [ toast_handler_1.ShowToastMessageAction.createWithTimeout({ id: ResizeKeyTool.TOKEN, message: messages_1.messages.resize.resize_mode_deactivated }) ]; } matchesIncreaseSizeKeystroke(event) { /** here event.key is used for '+', as keycode 187 is already declared for 'Equals' in {@link matchesKeystroke}.*/ return event.key === '+' || (0, sprotty_1.matchesKeystroke)(event, 'NumpadAdd'); } matchesMinSizeKeystroke(event) { return (0, sprotty_1.matchesKeystroke)(event, 'Digit0', 'ctrl') || (0, sprotty_1.matchesKeystroke)(event, 'Numpad0', 'ctrl'); } matchesDecreaseSizeKeystroke(event) { return (0, sprotty_1.matchesKeystroke)(event, 'Minus') || (0, sprotty_1.matchesKeystroke)(event, 'NumpadSubtract'); } }; exports.ResizeKeyListener = ResizeKeyListener; __decorate([ (0, inversify_1.inject)(selection_service_1.SelectionService), __metadata("design:type", selection_service_1.SelectionService) ], ResizeKeyListener.prototype, "selectionService", void 0); exports.ResizeKeyListener = ResizeKeyListener = __decorate([ (0, inversify_1.injectable)() ], ResizeKeyListener); let ResizeKeyTool = ResizeKeyTool_1 = class ResizeKeyTool extends base_tools_1.BaseEditTool { get id() { return ResizeKeyTool_1.ID; } enable() { this.dispatchActions(this.keyListener.enable()); this.toDisposeOnDisable.push(this.keyTool.registerListener(this.keyListener), (0, messages_1.repeatOnMessagesUpdated)(() => this.shortcutManager.register(ResizeKeyTool_1.TOKEN, [ { shortcuts: ['Escape'], description: messages_1.messages.resize.shortcut_deactivate, group: messages_1.messages.shortcut.group_resize, position: 0 }, { shortcuts: ['+'], description: messages_1.messages.resize.shortcut_increase, group: messages_1.messages.shortcut.group_resize, position: 1 }, { shortcuts: ['-'], description: messages_1.messages.resize.shortcut_decrease, group: messages_1.messages.shortcut.group_resize, position: 2 }, { shortcuts: ['CTRL', '0'], description: messages_1.messages.resize.shortcut_reset, group: messages_1.messages.shortcut.group_resize, position: 3 } ])), vscode_jsonrpc_1.Disposable.create(() => { this.dispatchActions(this.keyListener.disable()); })); } }; exports.ResizeKeyTool = ResizeKeyTool; ResizeKeyTool.ID = 'glsp.resize-key-tool'; ResizeKeyTool.TOKEN = Symbol.for(ResizeKeyTool_1.name); __decorate([ (0, inversify_1.inject)(sprotty_1.TYPES.IShortcutManager), __metadata("design:type", Function) ], ResizeKeyTool.prototype, "shortcutManager", void 0); __decorate([ (0, inversify_1.inject)(ResizeKeyListener), __metadata("design:type", ResizeKeyListener) ], ResizeKeyTool.prototype, "keyListener", void 0); exports.ResizeKeyTool = ResizeKeyTool = ResizeKeyTool_1 = __decorate([ (0, inversify_1.injectable)() ], ResizeKeyTool); //# sourceMappingURL=resize-tool.js.map