UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

88 lines • 3.64 kB
// ***************************************************************************** // Copyright (C) 2024 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-only WITH Classpath-exception-2.0 // ***************************************************************************** import { __decorate } from "tslib"; import { inject, injectable, named } from 'inversify'; import { StatusBar } from './status-bar/index.js'; import { ContributionProvider, Disposable, DisposableCollection } from '../common/index.js'; export const WidgetStatusBarContribution = Symbol('WidgetStatusBarContribution'); /** * Creates an empty {@link WidgetStatusBarContribution} that does nothing. * Useful for widgets that are not handled by any other contribution, for example: * * Settings widget * * Welcome widget * * Webview widget * * @param prototype Prototype to identify the kind of the widget. * @returns An empty {@link WidgetStatusBarContribution}. */ export function noopWidgetStatusBarContribution(prototype) { return { canHandle(widget) { return widget instanceof prototype; }, activate: () => { }, deactivate: () => { } }; } let WidgetStatusBarService = class WidgetStatusBarService { constructor() { this.toDisposeOnShow = new DisposableCollection(); } onStart(app) { app.shell.onDidChangeCurrentWidget(event => { if (event.newValue) { this.show(event.newValue); } }); } show(widget) { const contributions = this.contributionProvider.getContributions(); // If any contribution can handle the widget, activate it // If none can, keep everything as is if (contributions.some(contribution => contribution.canHandle(widget))) { // Deactivate all contributions this.hide(); // Remove the items of a closed widget, as the next current widget might not be handled by any contribution const onDisposed = () => this.hide(); widget.disposed.connect(onDisposed); this.toDisposeOnShow.push(Disposable.create(() => widget.disposed.disconnect(onDisposed))); for (const contribution of contributions) { if (contribution.canHandle(widget)) { // Selectively re-activate them contribution.activate(this.statusBar, widget); } } } } hide() { this.toDisposeOnShow.dispose(); for (const contribution of this.contributionProvider.getContributions()) { contribution.deactivate(this.statusBar); } } }; __decorate([ inject(ContributionProvider), named(WidgetStatusBarContribution) ], WidgetStatusBarService.prototype, "contributionProvider", void 0); __decorate([ inject(StatusBar) ], WidgetStatusBarService.prototype, "statusBar", void 0); WidgetStatusBarService = __decorate([ injectable() ], WidgetStatusBarService); export { WidgetStatusBarService }; //# sourceMappingURL=widget-status-bar-service.js.map