UNPKG

@eclipse-glsp/vscode-integration

Version:

Glue code to integrate GLSP diagrams in VSCode extensions (extension part)

44 lines 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.configureDefaultCommands = void 0; /******************************************************************************** * Copyright (c) 2022-2024 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 ********************************************************************************/ const protocol_1 = require("@eclipse-glsp/protocol"); const vscode = require("vscode"); function configureDefaultCommands(context) { // keep track of diagram specific element selection. const { extensionContext, diagramPrefix, connector } = context; let selectionState; extensionContext.subscriptions.push(connector.onSelectionUpdate(_selectionState => (selectionState = _selectionState))); extensionContext.subscriptions.push(vscode.commands.registerCommand(`${diagramPrefix}.fit`, () => { var _a; connector.dispatchAction(protocol_1.FitToScreenAction.create((_a = selectionState === null || selectionState === void 0 ? void 0 : selectionState.selectedElementsIDs) !== null && _a !== void 0 ? _a : [])); }), vscode.commands.registerCommand(`${diagramPrefix}.center`, () => { var _a; connector.dispatchAction(protocol_1.CenterAction.create((_a = selectionState === null || selectionState === void 0 ? void 0 : selectionState.selectedElementsIDs) !== null && _a !== void 0 ? _a : [])); }), vscode.commands.registerCommand(`${diagramPrefix}.layout`, () => { connector.dispatchAction(protocol_1.LayoutOperation.create([])); }), vscode.commands.registerCommand(`${diagramPrefix}.selectAll`, () => { connector.dispatchAction(protocol_1.SelectAllAction.create()); }), vscode.commands.registerCommand(`${diagramPrefix}.exportAsSVG`, () => { connector.dispatchAction(protocol_1.RequestExportSvgAction.create()); })); extensionContext.subscriptions.push(connector.onSelectionUpdate(state => { vscode.commands.executeCommand('setContext', `${diagramPrefix}.editorSelectedElementsAmount`, state.selectedElementsIDs.length); })); } exports.configureDefaultCommands = configureDefaultCommands; //# sourceMappingURL=configuration-util.js.map