@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
104 lines • 4.49 kB
JavaScript
// *****************************************************************************
// Copyright (C) 2019 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, postConstruct } from 'inversify';
import { ContributionProvider, Prioritizeable, Emitter } from '../../common/index.js';
import { BreadcrumbPopupContainerFactory } from './breadcrumb-popup-container.js';
import { BreadcrumbsContribution, Styles } from './breadcrumbs-constants.js';
let BreadcrumbsService = class BreadcrumbsService {
constructor() {
this.hasSubscribed = false;
this.onDidChangeBreadcrumbsEmitter = new Emitter();
}
init() {
this.createOverlayContainer();
}
createOverlayContainer() {
this.popupsOverlayContainer = window.document.createElement('div');
this.popupsOverlayContainer.id = Styles.BREADCRUMB_POPUP_OVERLAY_CONTAINER;
if (window.document.body) {
window.document.body.appendChild(this.popupsOverlayContainer);
}
}
/**
* Subscribe to this event emitter to be notified when the breadcrumbs have changed.
* The URI is the URI of the editor the breadcrumbs have changed for.
*/
get onDidChangeBreadcrumbs() {
// This lazy subscription is to address problems in inversify's instantiation routine
// related to use of the IconThemeService by different components instantiated by the
// ContributionProvider.
if (!this.hasSubscribed) {
this.subscribeToContributions();
}
return this.onDidChangeBreadcrumbsEmitter.event;
}
/**
* Subscribes to the onDidChangeBreadcrumbs events for all contributions.
*/
subscribeToContributions() {
this.hasSubscribed = true;
for (const contribution of this.contributions.getContributions()) {
contribution.onDidChangeBreadcrumbs(uri => this.onDidChangeBreadcrumbsEmitter.fire(uri));
}
}
/**
* Returns the breadcrumbs for a given URI, possibly an empty list.
*/
async getBreadcrumbs(uri) {
const result = [];
for (const contribution of await this.prioritizedContributions()) {
result.push(...await contribution.computeBreadcrumbs(uri));
}
return result;
}
async prioritizedContributions() {
const prioritized = await Prioritizeable.prioritizeAll(this.contributions.getContributions(), contribution => contribution.priority);
return prioritized.map(p => p.value).reverse();
}
/**
* Opens a popup for the given breadcrumb at the given position.
*/
async openPopup(breadcrumb, position) {
const contribution = this.contributions.getContributions().find(c => c.type === breadcrumb.type);
if (contribution) {
const popup = this.breadcrumbPopupContainerFactory(this.popupsOverlayContainer, breadcrumb.id, position);
const popupContent = await contribution.attachPopupContent(breadcrumb, popup.container);
if (popupContent && popup.isOpen) {
popup.onDidDispose(() => popupContent.dispose());
}
else {
popupContent?.dispose();
}
return popup;
}
}
};
__decorate([
inject(ContributionProvider),
named(BreadcrumbsContribution)
], BreadcrumbsService.prototype, "contributions", void 0);
__decorate([
inject(BreadcrumbPopupContainerFactory)
], BreadcrumbsService.prototype, "breadcrumbPopupContainerFactory", void 0);
__decorate([
postConstruct()
], BreadcrumbsService.prototype, "init", null);
BreadcrumbsService = __decorate([
injectable()
], BreadcrumbsService);
export { BreadcrumbsService };
//# sourceMappingURL=breadcrumbs-service.js.map