UNPKG

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