UNPKG

4.65 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2018 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// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.DecoratedTreeNode = exports.TreeDecoration = exports.AbstractTreeDecoratorService = exports.NoopTreeDecoratorService = exports.TreeDecoratorService = void 0;
19const tslib_1 = require("tslib");
20const inversify_1 = require("inversify");
21const common_1 = require("../../common");
22const widget_decoration_1 = require("../widget-decoration");
23exports.TreeDecoratorService = Symbol('TreeDecoratorService');
24/**
25 * The default tree decorator service. Does nothing at all. One has to rebind to a concrete implementation
26 * if decorators have to be supported in the tree widget.
27 */
28let NoopTreeDecoratorService = class NoopTreeDecoratorService {
29 constructor() {
30 this.emitter = new common_1.Emitter();
31 this.onDidChangeDecorations = this.emitter.event;
32 }
33 dispose() {
34 this.emitter.dispose();
35 }
36 // eslint-disable-next-line @typescript-eslint/no-explicit-any
37 getDecorations() {
38 return new Map();
39 }
40 deflateDecorators() {
41 return {};
42 }
43 inflateDecorators() {
44 return new Map();
45 }
46};
47NoopTreeDecoratorService = (0, tslib_1.__decorate)([
48 (0, inversify_1.injectable)()
49], NoopTreeDecoratorService);
50exports.NoopTreeDecoratorService = NoopTreeDecoratorService;
51/**
52 * Abstract decorator service implementation which emits events from all known tree decorators and caches the current state.
53 */
54let AbstractTreeDecoratorService = class AbstractTreeDecoratorService {
55 constructor(decorators) {
56 this.decorators = decorators;
57 this.onDidChangeDecorationsEmitter = new common_1.Emitter();
58 this.onDidChangeDecorations = this.onDidChangeDecorationsEmitter.event;
59 this.toDispose = new common_1.DisposableCollection();
60 this.toDispose.push(this.onDidChangeDecorationsEmitter);
61 this.toDispose.pushAll(this.decorators.map(decorator => decorator.onDidChangeDecorations(data => this.onDidChangeDecorationsEmitter.fire(undefined))));
62 }
63 dispose() {
64 this.toDispose.dispose();
65 }
66 async getDecorations(tree) {
67 const changes = new Map();
68 for (const decorator of this.decorators) {
69 for (const [id, data] of (await decorator.decorations(tree)).entries()) {
70 if (changes.has(id)) {
71 changes.get(id).push(data);
72 }
73 else {
74 changes.set(id, [data]);
75 }
76 }
77 }
78 return changes;
79 }
80 deflateDecorators(decorations) {
81 // eslint-disable-next-line no-null/no-null
82 const state = Object.create(null);
83 for (const [id, data] of decorations) {
84 state[id] = data;
85 }
86 return state;
87 }
88 // eslint-disable-next-line @typescript-eslint/no-explicit-any
89 inflateDecorators(state) {
90 const decorators = new Map();
91 for (const id of Object.keys(state)) {
92 decorators.set(id, state[id]);
93 }
94 return decorators;
95 }
96};
97AbstractTreeDecoratorService = (0, tslib_1.__decorate)([
98 (0, inversify_1.injectable)(),
99 (0, tslib_1.__metadata)("design:paramtypes", [Array])
100], AbstractTreeDecoratorService);
101exports.AbstractTreeDecoratorService = AbstractTreeDecoratorService;
102/**
103 * @deprecated import from `@theia/core/lib/browser/widget-decoration` instead.
104 */
105exports.TreeDecoration = widget_decoration_1.WidgetDecoration;
106var DecoratedTreeNode;
107(function (DecoratedTreeNode) {
108 /**
109 * Type-guard for decorated tree nodes.
110 */
111 function is(node) {
112 return !!node && 'decorationData' in node;
113 }
114 DecoratedTreeNode.is = is;
115})(DecoratedTreeNode = exports.DecoratedTreeNode || (exports.DecoratedTreeNode = {}));
116//# sourceMappingURL=tree-decorator.js.map
\No newline at end of file