UNPKG

@eclipse-glsp/theia-integration

Version:

Glue code to integrate GLSP clients into Eclipse Theia

55 lines 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GLSPCommandHandler = void 0; /******************************************************************************** * Copyright (c) 2020-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 client_1 = require("@eclipse-glsp/client"); const glsp_diagram_widget_1 = require("./glsp-diagram-widget"); /** * A reusable {@link CommandHandler} for simplified action dispatching in GLSP diagrams. */ class GLSPCommandHandler { constructor(shell, command) { this.shell = shell; this.command = command; } async execute() { if (this.isEnabled() && this.diagramWidget) { const actions = (0, client_1.asArray)(this.command.actions(this.diagramWidget.editorContext)); return this.diagramWidget.actionDispatcher.dispatchAll(actions); } } get diagramWidget() { return (0, glsp_diagram_widget_1.getDiagramWidget)(this.shell); } isEnabled() { var _a, _b, _c; return !!this.diagramWidget && ((_c = (_b = (_a = this.command).isEnabled) === null || _b === void 0 ? void 0 : _b.call(_a, this.diagramWidget.editorContext)) !== null && _c !== void 0 ? _c : true); } isVisible() { var _a, _b, _c; if (this.command.alwaysVisible) { return true; } return !!this.diagramWidget && ((_c = (_b = (_a = this.command).isVisible) === null || _b === void 0 ? void 0 : _b.call(_a, this.diagramWidget.editorContext)) !== null && _c !== void 0 ? _c : true); } isToggled() { var _a, _b, _c; return !!this.diagramWidget && ((_c = (_b = (_a = this.command).isToggled) === null || _b === void 0 ? void 0 : _b.call(_a, this.diagramWidget.editorContext)) !== null && _c !== void 0 ? _c : false); } } exports.GLSPCommandHandler = GLSPCommandHandler; //# sourceMappingURL=glsp-command-handler.js.map