UNPKG

4.23 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// *****************************************************************************
17var SourceTreeWidget_1;
18Object.defineProperty(exports, "__esModule", { value: true });
19exports.SourceTreeWidget = void 0;
20const tslib_1 = require("tslib");
21const React = require("react");
22const inversify_1 = require("inversify");
23const disposable_1 = require("../../common/disposable");
24const tree_1 = require("../tree");
25const source_tree_1 = require("./source-tree");
26let SourceTreeWidget = SourceTreeWidget_1 = class SourceTreeWidget extends tree_1.TreeWidget {
27 constructor() {
28 super(...arguments);
29 this.toDisposeOnSource = new disposable_1.DisposableCollection();
30 }
31 static createContainer(parent, props) {
32 const child = (0, tree_1.createTreeContainer)(parent, {
33 props,
34 tree: source_tree_1.SourceTree,
35 widget: SourceTreeWidget_1,
36 });
37 return child;
38 }
39 init() {
40 super.init();
41 this.addClass('theia-source-tree');
42 this.toDispose.push(this.model.onOpenNode(node => {
43 if (source_tree_1.TreeElementNode.is(node) && node.element.open) {
44 node.element.open();
45 }
46 }));
47 }
48 get source() {
49 const root = this.model.root;
50 return source_tree_1.TreeSourceNode.is(root) ? root.source : undefined;
51 }
52 set source(source) {
53 if (this.source === source) {
54 return;
55 }
56 this.toDisposeOnSource.dispose();
57 this.toDispose.push(this.toDisposeOnSource);
58 this.model.root = source_tree_1.TreeSourceNode.to(source);
59 if (source) {
60 this.toDisposeOnSource.push(source.onDidChange(() => this.model.refresh()));
61 }
62 }
63 get selectedElement() {
64 const node = this.model.selectedNodes[0];
65 return source_tree_1.TreeElementNode.is(node) && node.element || undefined;
66 }
67 renderTree(model) {
68 if (source_tree_1.TreeSourceNode.is(model.root) && model.root.children.length === 0) {
69 const { placeholder } = model.root.source;
70 if (placeholder) {
71 return React.createElement("div", { className: 'theia-tree-source-node-placeholder noselect' }, placeholder);
72 }
73 }
74 return super.renderTree(model);
75 }
76 renderCaption(node) {
77 if (source_tree_1.TreeElementNode.is(node)) {
78 const classNames = this.createTreeElementNodeClassNames(node);
79 return React.createElement("div", { className: classNames.join(' ') }, node.element.render(this));
80 }
81 return undefined;
82 }
83 createTreeElementNodeClassNames(node) {
84 return [tree_1.TREE_NODE_SEGMENT_GROW_CLASS];
85 }
86 storeState() {
87 // no-op
88 return {};
89 }
90 superStoreState() {
91 return super.storeState();
92 }
93 restoreState(state) {
94 // no-op
95 }
96 superRestoreState(state) {
97 super.restoreState(state);
98 return;
99 }
100};
101(0, tslib_1.__decorate)([
102 (0, inversify_1.postConstruct)(),
103 (0, tslib_1.__metadata)("design:type", Function),
104 (0, tslib_1.__metadata)("design:paramtypes", []),
105 (0, tslib_1.__metadata)("design:returntype", void 0)
106], SourceTreeWidget.prototype, "init", null);
107SourceTreeWidget = SourceTreeWidget_1 = (0, tslib_1.__decorate)([
108 (0, inversify_1.injectable)()
109], SourceTreeWidget);
110exports.SourceTreeWidget = SourceTreeWidget;
111//# sourceMappingURL=source-tree-widget.js.map
\No newline at end of file