UNPKG

sprotty-theia

Version:

Glue code for Sprotty diagrams in a Theia IDE

113 lines 5.77 kB
"use strict"; /******************************************************************************** * Copyright (c) 2018-2020 TypeFox 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DiagramManager = exports.DiagramManagerProvider = void 0; const inversify_1 = require("inversify"); const browser_1 = require("@theia/core/lib/browser"); const browser_2 = require("@theia/editor/lib/browser"); const diagram_widget_1 = require("./diagram-widget"); const diagram_configuration_1 = require("./diagram-configuration"); exports.DiagramManagerProvider = Symbol('DiagramManagerProvider'); let DiagramManager = /** @class */ (() => { let DiagramManager = class DiagramManager extends browser_1.WidgetOpenHandler { constructor() { super(...arguments); this.widgetCount = 0; } canHandle(uri, options) { return 10; } async doOpen(widget, options) { const op = Object.assign({ mode: options && options.mode ? options.mode : 'activate' }, options); if (!widget.isAttached) { const currentEditor = this.editorManager.currentEditor; const widgetOptions = Object.assign({ area: 'main' }, (options && options.widgetOptions ? options.widgetOptions : {})); if (!!currentEditor && currentEditor.editor.uri.toString(true) === widget.uri.toString(true)) { widgetOptions.ref = currentEditor; widgetOptions.mode = options && options.widgetOptions && options.widgetOptions.mode ? options.widgetOptions.mode : 'open-to-right'; } this.shell.addWidget(widget, widgetOptions); } if (op.mode === 'activate') { await widget.getSvgElement(); await this.shell.activateWidget(widget.widgetId); } else if (op.mode === 'reveal') { await this.shell.revealWidget(widget.widgetId); } } get id() { return this.diagramType + "-diagram-manager"; } createWidgetOptions(uri, options) { const widgetOptions = options && options.widgetOptions; return Object.assign(Object.assign({}, { diagramType: this.diagramType, uri: uri.toString(true), iconClass: this.iconClass, label: uri.path.base }), widgetOptions); } async createWidget(options) { if (diagram_widget_1.DiagramWidgetOptions.is(options)) { const clientId = this.createClientId(); const config = this.diagramConfigurationRegistry.get(options.diagramType); const diContainer = config.createContainer(clientId); const diagramWidget = this.widgetFactory(options, clientId + '_widget', diContainer, this.diagramConnector); return diagramWidget; } throw Error('DiagramWidgetFactory needs DiagramWidgetOptions but got ' + JSON.stringify(options)); } createClientId() { return this.diagramType + '_' + (this.widgetCount++); } get diagramConnector() { return undefined; } }; __decorate([ inversify_1.inject(browser_1.WidgetManager), __metadata("design:type", browser_1.WidgetManager) ], DiagramManager.prototype, "widgetManager", void 0); __decorate([ inversify_1.inject(browser_2.EditorManager), __metadata("design:type", browser_2.EditorManager) ], DiagramManager.prototype, "editorManager", void 0); __decorate([ inversify_1.inject(diagram_widget_1.DiagramWidgetFactory), __metadata("design:type", Function) ], DiagramManager.prototype, "widgetFactory", void 0); __decorate([ inversify_1.inject(diagram_configuration_1.DiagramConfigurationRegistry), __metadata("design:type", diagram_configuration_1.DiagramConfigurationRegistry) ], DiagramManager.prototype, "diagramConfigurationRegistry", void 0); DiagramManager = __decorate([ inversify_1.injectable() ], DiagramManager); return DiagramManager; })(); exports.DiagramManager = DiagramManager; //# sourceMappingURL=diagram-manager.js.map