1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __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 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | exports.BreadcrumbsRendererFactory = exports.BreadcrumbsRenderer = void 0;
|
28 | const React = require("react");
|
29 | const inversify_1 = require("inversify");
|
30 | const widgets_1 = require("../widgets");
|
31 | const breadcrumbs_service_1 = require("./breadcrumbs-service");
|
32 | const breadcrumb_renderer_1 = require("./breadcrumb-renderer");
|
33 | const perfect_scrollbar_1 = require("perfect-scrollbar");
|
34 | const common_1 = require("../../common");
|
35 | const core_preferences_1 = require("../core-preferences");
|
36 | const breadcrumbs_constants_1 = require("./breadcrumbs-constants");
|
37 | const label_provider_1 = require("../label-provider");
|
38 | let BreadcrumbsRenderer = class BreadcrumbsRenderer extends widgets_1.ReactRenderer {
|
39 | constructor() {
|
40 | super(...arguments);
|
41 | this.onDidChangeActiveStateEmitter = new common_1.Emitter();
|
42 | this.breadcrumbs = [];
|
43 | this.refreshCancellationMarker = { canceled: true };
|
44 | this.togglePopup = (breadcrumb, event) => {
|
45 | var _a;
|
46 | event.stopPropagation();
|
47 | event.preventDefault();
|
48 | let openPopup = true;
|
49 | if ((_a = this.popup) === null || _a === void 0 ? void 0 : _a.isOpen) {
|
50 | this.popup.dispose();
|
51 |
|
52 |
|
53 | openPopup = this.popup.breadcrumbId !== breadcrumb.id;
|
54 | }
|
55 | else {
|
56 | this.popup = undefined;
|
57 | }
|
58 | if (openPopup) {
|
59 | const { currentTarget } = event;
|
60 | const breadcrumbElement = currentTarget.closest(`.${breadcrumbs_constants_1.Styles.BREADCRUMB_ITEM}`);
|
61 | if (breadcrumbElement) {
|
62 | const { left: x, bottom: y } = breadcrumbElement.getBoundingClientRect();
|
63 | this.breadcrumbsService.openPopup(breadcrumb, { x, y }).then(popup => { this.popup = popup; });
|
64 | }
|
65 | }
|
66 | };
|
67 | }
|
68 | get onDidChangeActiveState() {
|
69 | return this.onDidChangeActiveStateEmitter.event;
|
70 | }
|
71 | get active() {
|
72 | return !!this.breadcrumbs.length;
|
73 | }
|
74 | get breadCrumbsContainer() {
|
75 | var _a;
|
76 | return (_a = this.host.firstElementChild) !== null && _a !== void 0 ? _a : undefined;
|
77 | }
|
78 | init() {
|
79 | this.toDispose.push(this.onDidChangeActiveStateEmitter);
|
80 | this.toDispose.push(this.breadcrumbsService.onDidChangeBreadcrumbs(uri => {
|
81 | var _a;
|
82 | if ((_a = this.uri) === null || _a === void 0 ? void 0 : _a.isEqual(uri)) {
|
83 | this.refresh(this.uri);
|
84 | }
|
85 | }));
|
86 | this.toDispose.push(this.corePreferences.onPreferenceChanged(change => {
|
87 | if (change.preferenceName === 'breadcrumbs.enabled') {
|
88 | this.refresh(this.uri);
|
89 | }
|
90 | }));
|
91 | this.toDispose.push(this.labelProvider.onDidChange(() => this.refresh(this.uri)));
|
92 | }
|
93 | dispose() {
|
94 | super.dispose();
|
95 | this.toDispose.dispose();
|
96 | if (this.popup) {
|
97 | this.popup.dispose();
|
98 | }
|
99 | if (this.scrollbar) {
|
100 | this.scrollbar.destroy();
|
101 | this.scrollbar = undefined;
|
102 | }
|
103 | }
|
104 | async refresh(uri) {
|
105 | this.uri = uri;
|
106 | this.refreshCancellationMarker.canceled = true;
|
107 | const currentCallCanceled = { canceled: false };
|
108 | this.refreshCancellationMarker = currentCallCanceled;
|
109 | let breadcrumbs;
|
110 | if (uri && this.corePreferences['breadcrumbs.enabled']) {
|
111 | breadcrumbs = await this.breadcrumbsService.getBreadcrumbs(uri);
|
112 | }
|
113 | else {
|
114 | breadcrumbs = [];
|
115 | }
|
116 | if (currentCallCanceled.canceled) {
|
117 | return;
|
118 | }
|
119 | const wasActive = this.active;
|
120 | this.breadcrumbs = breadcrumbs;
|
121 | const isActive = this.active;
|
122 | if (wasActive !== isActive) {
|
123 | this.onDidChangeActiveStateEmitter.fire(isActive);
|
124 | }
|
125 | this.update();
|
126 | }
|
127 | update() {
|
128 | this.render();
|
129 | if (!this.scrollbar) {
|
130 | this.createScrollbar();
|
131 | }
|
132 | else {
|
133 | this.scrollbar.update();
|
134 | }
|
135 | this.scrollToEnd();
|
136 | }
|
137 | createScrollbar() {
|
138 | const { breadCrumbsContainer } = this;
|
139 | if (breadCrumbsContainer) {
|
140 | this.scrollbar = new perfect_scrollbar_1.default(breadCrumbsContainer, {
|
141 | handlers: ['drag-thumb', 'keyboard', 'wheel', 'touch'],
|
142 | useBothWheelAxes: true,
|
143 | scrollXMarginOffset: 4,
|
144 | suppressScrollY: true
|
145 | });
|
146 | }
|
147 | }
|
148 | scrollToEnd() {
|
149 | const { breadCrumbsContainer } = this;
|
150 | if (breadCrumbsContainer) {
|
151 | breadCrumbsContainer.scrollLeft = breadCrumbsContainer.scrollWidth;
|
152 | }
|
153 | }
|
154 | doRender() {
|
155 | return React.createElement("ul", { className: breadcrumbs_constants_1.Styles.BREADCRUMBS }, this.renderBreadcrumbs());
|
156 | }
|
157 | renderBreadcrumbs() {
|
158 | return this.breadcrumbs.map(breadcrumb => this.breadcrumbRenderer.render(breadcrumb, this.togglePopup));
|
159 | }
|
160 | };
|
161 | __decorate([
|
162 | (0, inversify_1.inject)(breadcrumbs_service_1.BreadcrumbsService),
|
163 | __metadata("design:type", breadcrumbs_service_1.BreadcrumbsService)
|
164 | ], BreadcrumbsRenderer.prototype, "breadcrumbsService", void 0);
|
165 | __decorate([
|
166 | (0, inversify_1.inject)(breadcrumb_renderer_1.BreadcrumbRenderer),
|
167 | __metadata("design:type", Object)
|
168 | ], BreadcrumbsRenderer.prototype, "breadcrumbRenderer", void 0);
|
169 | __decorate([
|
170 | (0, inversify_1.inject)(core_preferences_1.CorePreferences),
|
171 | __metadata("design:type", Object)
|
172 | ], BreadcrumbsRenderer.prototype, "corePreferences", void 0);
|
173 | __decorate([
|
174 | (0, inversify_1.inject)(label_provider_1.LabelProvider),
|
175 | __metadata("design:type", label_provider_1.LabelProvider)
|
176 | ], BreadcrumbsRenderer.prototype, "labelProvider", void 0);
|
177 | __decorate([
|
178 | (0, inversify_1.postConstruct)(),
|
179 | __metadata("design:type", Function),
|
180 | __metadata("design:paramtypes", []),
|
181 | __metadata("design:returntype", void 0)
|
182 | ], BreadcrumbsRenderer.prototype, "init", null);
|
183 | BreadcrumbsRenderer = __decorate([
|
184 | (0, inversify_1.injectable)()
|
185 | ], BreadcrumbsRenderer);
|
186 | exports.BreadcrumbsRenderer = BreadcrumbsRenderer;
|
187 | exports.BreadcrumbsRendererFactory = Symbol('BreadcrumbsRendererFactory');
|
188 |
|
\ | No newline at end of file |