UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

120 lines 5.27 kB
"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); }; var StatusOverlay_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.StatusOverlay = void 0; /******************************************************************************** * Copyright (c) 2023-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 sprotty_1 = require("@eclipse-glsp/sprotty"); const inversify_1 = require("inversify"); const ui_extension_1 = require("../../base/ui-extension/ui-extension"); /** * A reusable status overlay for rendering (icon + message) and handling of {@link StatusAction}'s. */ let StatusOverlay = StatusOverlay_1 = class StatusOverlay extends ui_extension_1.GLSPAbstractUIExtension { id() { return StatusOverlay_1.ID; } containerClass() { return 'sprotty-status'; } initializeContents(containerElement) { this.statusIconDiv = document.createElement('div'); containerElement.appendChild(this.statusIconDiv); this.statusMessageDiv = document.createElement('div'); this.statusMessageDiv.classList.add('sprotty-status-message'); containerElement.appendChild(this.statusMessageDiv); } setStatus(status) { if (this.statusMessageDiv) { this.statusMessageDiv.textContent = status.message; this.removeClasses(this.statusMessageDiv, 1); this.statusMessageDiv.classList.add(status.severity.toLowerCase()); } if (this.statusIconDiv) { this.removeClasses(this.statusIconDiv, 0); const classes = this.statusIconDiv.classList; classes.add(status.severity.toLowerCase()); switch (status.severity) { case 'FATAL': classes.add(...(0, sprotty_1.codiconCSSClasses)('error')); break; case 'ERROR': classes.add(...(0, sprotty_1.codiconCSSClasses)('warning')); break; case 'WARNING': classes.add(...(0, sprotty_1.codiconCSSClasses)('warning')); break; case 'INFO': classes.add(...(0, sprotty_1.codiconCSSClasses)('info')); break; } } } clearStatus() { this.setStatus(sprotty_1.StatusAction.create('', { severity: 'NONE' })); } clearTimeout() { if (this.pendingTimeout) { window.clearTimeout(this.pendingTimeout); this.pendingTimeout = undefined; } } removeClasses(element, keep) { const classes = element.classList; while (classes.length > keep) { const item = classes.item(classes.length - 1); if (item) { classes.remove(item); } } } handle(action) { var _a; this.clearTimeout(); if (action.severity === 'NONE') { this.clearStatus(); return; } this.setStatus(action); // Check for timeout const statusTimeout = (_a = action.timeout) !== null && _a !== void 0 ? _a : -1; if (statusTimeout > 0) { this.pendingTimeout = window.setTimeout(() => this.clearStatus(), statusTimeout); } } preInitialize() { return this.actionDispatcher.dispatch(sprotty_1.SetUIExtensionVisibilityAction.create({ extensionId: this.id(), visible: true })); } }; exports.StatusOverlay = StatusOverlay; StatusOverlay.ID = 'glsp.server.status.overlay'; __decorate([ (0, inversify_1.inject)(sprotty_1.TYPES.IActionDispatcher), __metadata("design:type", Object) ], StatusOverlay.prototype, "actionDispatcher", void 0); exports.StatusOverlay = StatusOverlay = StatusOverlay_1 = __decorate([ (0, inversify_1.injectable)() ], StatusOverlay); //# sourceMappingURL=status-overlay.js.map