@eclipse-glsp/theia-integration
Version:
Glue code to integrate GLSP clients into Eclipse Theia
166 lines • 8.19 kB
JavaScript
"use strict";
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.GLSPDiagramContextKeyService = exports.AbstractGLSPDiagramContextKeyService = void 0;
/********************************************************************************
* Copyright (c) 2020-2023 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 core_1 = require("@theia/core");
const browser_1 = require("@theia/core/lib/browser");
const context_key_service_1 = require("@theia/core/lib/browser/context-key-service");
const inversify_1 = require("@theia/core/shared/inversify");
const glsp_diagram_widget_1 = require("./glsp-diagram-widget");
let AbstractGLSPDiagramContextKeyService = class AbstractGLSPDiagramContextKeyService {
constructor() {
this.disposeOnUpdate = new core_1.DisposableCollection();
}
init() {
this.registerContextKeys();
this.updateContextKeys();
this.shell.onDidChangeActiveWidget(() => this.updateContextKeys());
}
updateContextKeys() {
this.disposeOnUpdate.dispose();
const glspDiagramWidget = this.getDiagramWidget();
if (glspDiagramWidget) {
this.doUpdateStaticContextKeys(glspDiagramWidget);
const selectionService = this.getSelectionService(glspDiagramWidget);
const editorContextService = this.getEditorContextService(glspDiagramWidget);
this.disposeOnUpdate.pushAll([
selectionService.onSelectionChanged(change => this.updateSelectionContextKeys(change.root, change.selectedElements)),
editorContextService.onEditModeChanged(change => this.doUpdateEditModeContextKeys(change.newValue))
]);
}
else {
this.resetContextKeys();
}
}
updateSelectionContextKeys(root, selectedElementIds) {
if (selectedElementIds.length < 1) {
this.doResetSelectionContextKeys();
return;
}
this.doUpdateSelectionContextKeys((0, client_1.getElements)(root.index, selectedElementIds));
}
getSelectionService(glspDiagramWidget) {
return glspDiagramWidget.diContainer.get(client_1.SelectionService);
}
getEditorContextService(glspDiagramWidget) {
return glspDiagramWidget.diContainer.get(client_1.EditorContextService);
}
getDiagramWidget() {
return (0, glsp_diagram_widget_1.getDiagramWidget)(this.shell);
}
resetContextKeys() {
this.doResetStaticContextKeys();
this.doResetSelectionContextKeys();
this.doResetEditModeContextKeys();
}
};
exports.AbstractGLSPDiagramContextKeyService = AbstractGLSPDiagramContextKeyService;
__decorate([
(0, inversify_1.inject)(browser_1.ApplicationShell),
__metadata("design:type", browser_1.ApplicationShell)
], AbstractGLSPDiagramContextKeyService.prototype, "shell", void 0);
__decorate([
(0, inversify_1.inject)(context_key_service_1.ContextKeyService),
__metadata("design:type", Object)
], AbstractGLSPDiagramContextKeyService.prototype, "contextKeyService", void 0);
__decorate([
(0, inversify_1.postConstruct)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], AbstractGLSPDiagramContextKeyService.prototype, "init", null);
exports.AbstractGLSPDiagramContextKeyService = AbstractGLSPDiagramContextKeyService = __decorate([
(0, inversify_1.injectable)()
], AbstractGLSPDiagramContextKeyService);
class GLSPDiagramContextKeyService extends AbstractGLSPDiagramContextKeyService {
get glspEditorFocus() {
return this._glspEditorFocus;
}
get glspEditorDiagramType() {
return this._glspEditorDiagramType;
}
get glspEditorHasSelection() {
return this._glspEditorHasSelection;
}
get glspEditorHasSelectionOfType() {
return this._glspEditorHasSelectionOfType;
}
get glspEditorHasMultipleSelection() {
return this._glspEditorHasMultipleSelection;
}
get glspEditorHasDeletableSelection() {
return this._glspEditorHasDeletableSelection;
}
get glspEditorHasMoveableSelection() {
return this._glspEditorHasMoveableSelection;
}
get glspEditorIsReadonly() {
return this._glspEditorIsReadonly;
}
registerContextKeys() {
this._glspEditorFocus = this.contextKeyService.createKey('glspEditorFocus', false);
this._glspEditorDiagramType = this.contextKeyService.createKey('glspEditorDiagramType', undefined);
this._glspEditorHasSelection = this.contextKeyService.createKey('glspEditorHasSelection', false);
this._glspEditorHasSelectionOfType = this.contextKeyService.createKey('glspEditorHasSelectionOfType', undefined);
this._glspEditorHasMultipleSelection = this.contextKeyService.createKey('glspEditorHasMultipleSelection', false);
this._glspEditorHasDeletableSelection = this.contextKeyService.createKey('glspEditorHasDeletableSelection', false);
this._glspEditorHasMoveableSelection = this.contextKeyService.createKey('glspEditorHasMoveableSelection', false);
this._glspEditorIsReadonly = this.contextKeyService.createKey('glspEditorIsReadonly', false);
}
doUpdateStaticContextKeys(glspDiagramWidget) {
this.glspEditorFocus.set(true);
this.glspEditorDiagramType.set(glspDiagramWidget.diagramType);
}
doResetStaticContextKeys() {
this.glspEditorFocus.reset();
this.glspEditorDiagramType.reset();
}
doUpdateSelectionContextKeys(selectedElements) {
this.glspEditorHasSelection.set(true);
this.glspEditorHasMultipleSelection.set(selectedElements.length > 1);
this.glspEditorHasDeletableSelection.set(selectedElements.filter(client_1.isDeletable).length > 0);
this.glspEditorHasMoveableSelection.set(selectedElements.filter(client_1.isMoveable).length > 0);
if (selectedElements.length === 1 && selectedElements[0]) {
this.glspEditorHasSelectionOfType.set(selectedElements[0].type);
}
}
doUpdateEditModeContextKeys(editMode) {
this.glspEditorIsReadonly.set(editMode === client_1.EditMode.READONLY);
}
doResetSelectionContextKeys() {
this.glspEditorHasDeletableSelection.reset();
this.glspEditorHasMoveableSelection.reset();
this.glspEditorHasMultipleSelection.reset();
this.glspEditorHasSelection.reset();
this.glspEditorHasSelectionOfType.reset();
}
doResetEditModeContextKeys() {
this.glspEditorIsReadonly.reset();
}
}
exports.GLSPDiagramContextKeyService = GLSPDiagramContextKeyService;
//# sourceMappingURL=glsp-diagram-context-key-service.js.map