UNPKG

5.7 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2019 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 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;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27exports.BreadcrumbsService = void 0;
28const inversify_1 = require("inversify");
29const common_1 = require("../../common");
30const breadcrumb_popup_container_1 = require("./breadcrumb-popup-container");
31const breadcrumbs_constants_1 = require("./breadcrumbs-constants");
32let BreadcrumbsService = class BreadcrumbsService {
33 constructor() {
34 this.hasSubscribed = false;
35 this.onDidChangeBreadcrumbsEmitter = new common_1.Emitter();
36 }
37 init() {
38 this.createOverlayContainer();
39 }
40 createOverlayContainer() {
41 this.popupsOverlayContainer = window.document.createElement('div');
42 this.popupsOverlayContainer.id = breadcrumbs_constants_1.Styles.BREADCRUMB_POPUP_OVERLAY_CONTAINER;
43 if (window.document.body) {
44 window.document.body.appendChild(this.popupsOverlayContainer);
45 }
46 }
47 /**
48 * Subscribe to this event emitter to be notified when the breadcrumbs have changed.
49 * The URI is the URI of the editor the breadcrumbs have changed for.
50 */
51 get onDidChangeBreadcrumbs() {
52 // This lazy subscription is to address problems in inversify's instantiation routine
53 // related to use of the IconThemeService by different components instantiated by the
54 // ContributionProvider.
55 if (!this.hasSubscribed) {
56 this.subscribeToContributions();
57 }
58 return this.onDidChangeBreadcrumbsEmitter.event;
59 }
60 /**
61 * Subscribes to the onDidChangeBreadcrumbs events for all contributions.
62 */
63 subscribeToContributions() {
64 this.hasSubscribed = true;
65 for (const contribution of this.contributions.getContributions()) {
66 contribution.onDidChangeBreadcrumbs(uri => this.onDidChangeBreadcrumbsEmitter.fire(uri));
67 }
68 }
69 /**
70 * Returns the breadcrumbs for a given URI, possibly an empty list.
71 */
72 async getBreadcrumbs(uri) {
73 const result = [];
74 for (const contribution of await this.prioritizedContributions()) {
75 result.push(...await contribution.computeBreadcrumbs(uri));
76 }
77 return result;
78 }
79 async prioritizedContributions() {
80 const prioritized = await common_1.Prioritizeable.prioritizeAll(this.contributions.getContributions(), contribution => contribution.priority);
81 return prioritized.map(p => p.value).reverse();
82 }
83 /**
84 * Opens a popup for the given breadcrumb at the given position.
85 */
86 async openPopup(breadcrumb, position) {
87 const contribution = this.contributions.getContributions().find(c => c.type === breadcrumb.type);
88 if (contribution) {
89 const popup = this.breadcrumbPopupContainerFactory(this.popupsOverlayContainer, breadcrumb.id, position);
90 const popupContent = await contribution.attachPopupContent(breadcrumb, popup.container);
91 if (popupContent && popup.isOpen) {
92 popup.onDidDispose(() => popupContent.dispose());
93 }
94 else {
95 popupContent === null || popupContent === void 0 ? void 0 : popupContent.dispose();
96 }
97 return popup;
98 }
99 }
100};
101__decorate([
102 (0, inversify_1.inject)(common_1.ContributionProvider),
103 (0, inversify_1.named)(breadcrumbs_constants_1.BreadcrumbsContribution),
104 __metadata("design:type", Object)
105], BreadcrumbsService.prototype, "contributions", void 0);
106__decorate([
107 (0, inversify_1.inject)(breadcrumb_popup_container_1.BreadcrumbPopupContainerFactory),
108 __metadata("design:type", Function)
109], BreadcrumbsService.prototype, "breadcrumbPopupContainerFactory", void 0);
110__decorate([
111 (0, inversify_1.postConstruct)(),
112 __metadata("design:type", Function),
113 __metadata("design:paramtypes", []),
114 __metadata("design:returntype", void 0)
115], BreadcrumbsService.prototype, "init", null);
116BreadcrumbsService = __decorate([
117 (0, inversify_1.injectable)()
118], BreadcrumbsService);
119exports.BreadcrumbsService = BreadcrumbsService;
120//# sourceMappingURL=breadcrumbs-service.js.map
\No newline at end of file