UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

146 lines 6.92 kB
"use strict"; /******************************************************************************** * Copyright (c) 2023-2025 Business Informatics Group (TU Wien) 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 GridCellZoomTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.GridZoomKeyListener = exports.GridCellZoomTool = void 0; const sprotty_1 = require("@eclipse-glsp/sprotty"); const inversify_1 = require("inversify"); const messages_1 = require("../../../base/messages"); const selection_service_1 = require("../../../base/selection-service"); const viewpoint_util_1 = require("../../../utils/viewpoint-util"); const base_tools_1 = require("../../tools/base-tools"); const diagram_navigation_tool_1 = require("../element-navigation/diagram-navigation-tool"); const action_1 = require("../keyboard-grid/action"); const toast_handler_1 = require("../toast/toast-handler"); /** * Zoom viewport and elements when its focused and arrow keys are hit. */ let GridCellZoomTool = GridCellZoomTool_1 = class GridCellZoomTool extends base_tools_1.BaseTool { constructor() { super(...arguments); this.zoomKeyListener = new GridZoomKeyListener(this); } get id() { return GridCellZoomTool_1.ID; } enable() { this.toDisposeOnDisable.push(this.keyTool.registerListener(this.zoomKeyListener), (0, messages_1.repeatOnMessagesUpdated)(() => this.shortcutManager.register(GridCellZoomTool_1.TOKEN, [ { shortcuts: ['CTRL', '+'], description: messages_1.messages.grid.shortcut_zoom_in, group: messages_1.messages.shortcut.group_zoom, position: 0 } ]))); } handle(action) { const viewport = this.editorContext.viewport; if (viewport) { let viewportAction = undefined; if (action_1.KeyboardGridCellSelectedAction.is(action) && action.options.originId === GridCellZoomTool_1.ID) { viewportAction = this.zoomKeyListener.setNewZoomFactor(viewport, this.zoomFactors.in, (0, viewpoint_util_1.getAbsolutePositionByPoint)(this.editorContext.modelRoot, action.options.centerCellPosition)); } else if (action_1.KeyboardGridKeyboardEventAction.is(action) && action.options.originId === GridCellZoomTool_1.ID) { if ((0, sprotty_1.matchesKeystroke)(action.options.event, 'Minus')) { viewportAction = this.zoomKeyListener.setNewZoomFactor(viewport, this.zoomFactors.out); } else if ((0, sprotty_1.matchesKeystroke)(action.options.event, 'Digit0', 'ctrl')) { viewportAction = sprotty_1.CenterAction.create([]); } } if (viewportAction) { this.actionDispatcher.dispatchAll([ viewportAction, toast_handler_1.HideToastAction.create({ id: Symbol.for(diagram_navigation_tool_1.ElementNavigatorKeyListener.name) }) ]); } } } }; exports.GridCellZoomTool = GridCellZoomTool; GridCellZoomTool.ID = 'glsp.accessibility-grid-cell-zoom-tool'; GridCellZoomTool.TOKEN = Symbol.for(GridCellZoomTool_1.name); __decorate([ (0, inversify_1.inject)(sprotty_1.TYPES.IShortcutManager), __metadata("design:type", Object) ], GridCellZoomTool.prototype, "shortcutManager", void 0); __decorate([ (0, inversify_1.inject)(sprotty_1.TYPES.ZoomFactors), __metadata("design:type", Object) ], GridCellZoomTool.prototype, "zoomFactors", void 0); __decorate([ (0, inversify_1.inject)(selection_service_1.SelectionService), __metadata("design:type", selection_service_1.SelectionService) ], GridCellZoomTool.prototype, "selectionService", void 0); exports.GridCellZoomTool = GridCellZoomTool = GridCellZoomTool_1 = __decorate([ (0, inversify_1.injectable)() ], GridCellZoomTool); class GridZoomKeyListener extends sprotty_1.KeyListener { constructor(tool) { super(); this.tool = tool; } setNewZoomFactor(viewport, zoomFactor, point) { let newViewport; const newZoom = viewport.zoom * zoomFactor; if (point) { newViewport = { scroll: { x: point.x - (0.5 * viewport.canvasBounds.width) / newZoom, y: point.y - (0.5 * viewport.canvasBounds.height) / newZoom }, zoom: newZoom }; } else { newViewport = { scroll: viewport.scroll, zoom: newZoom }; } return sprotty_1.SetViewportAction.create(viewport.id, newViewport, { animate: false }); } keyDown(element, event) { if (this.matchesZoomViaGrid(event)) { return [ action_1.EnableKeyboardGridAction.create({ originId: GridCellZoomTool.ID, triggerActions: [] }), toast_handler_1.ShowToastMessageAction.createWithTimeout({ id: Symbol.for(diagram_navigation_tool_1.ElementNavigatorKeyListener.name), message: messages_1.messages.grid.zoom_in_grid }) ]; } return []; } matchesZoomViaGrid(event) { return event.key === '+' && event.ctrlKey; } } exports.GridZoomKeyListener = GridZoomKeyListener; //# sourceMappingURL=grid-cell-zoom-key-tool.js.map