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.TreeViewWelcomeWidget = void 0;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | const React = require("react");
|
34 | const inversify_1 = require("inversify");
|
35 | const common_1 = require("../../common");
|
36 | const context_key_service_1 = require("../context-key-service");
|
37 | const tree_widget_1 = require("./tree-widget");
|
38 | const window_service_1 = require("../window/window-service");
|
39 | let TreeViewWelcomeWidget = class TreeViewWelcomeWidget extends tree_widget_1.TreeWidget {
|
40 | constructor() {
|
41 | super(...arguments);
|
42 | this.viewWelcomeNodes = [];
|
43 | this.items = [];
|
44 | this.openLinkOrCommand = (event, href) => {
|
45 | event.stopPropagation();
|
46 | if (href.startsWith('command:')) {
|
47 | const command = href.replace('command:', '');
|
48 | this.commands.executeCommand(command);
|
49 | }
|
50 | else {
|
51 | this.windowService.openNewWindow(href, { external: true });
|
52 | }
|
53 | };
|
54 | }
|
55 | get visibleItems() {
|
56 | const visibleItems = this.items.filter(v => v.visible);
|
57 | if (visibleItems.length && this.defaultItem) {
|
58 | return [this.defaultItem.welcomeInfo];
|
59 | }
|
60 | return visibleItems.map(v => v.welcomeInfo);
|
61 | }
|
62 | renderTree(model) {
|
63 | if (this.shouldShowWelcomeView() && this.visibleItems.length) {
|
64 | return this.renderViewWelcome();
|
65 | }
|
66 | return super.renderTree(model);
|
67 | }
|
68 | shouldShowWelcomeView() {
|
69 | return false;
|
70 | }
|
71 | renderViewWelcome() {
|
72 | return (React.createElement("div", { className: 'theia-WelcomeView' }, ...this.viewWelcomeNodes));
|
73 | }
|
74 | handleViewWelcomeContentChange(viewWelcomes) {
|
75 | this.items = [];
|
76 | for (const welcomeInfo of viewWelcomes) {
|
77 | if (welcomeInfo.when === 'default') {
|
78 | this.defaultItem = { welcomeInfo, visible: true };
|
79 | }
|
80 | else {
|
81 | const visible = welcomeInfo.when === undefined || this.contextService.match(welcomeInfo.when);
|
82 | this.items.push({ welcomeInfo, visible });
|
83 | }
|
84 | }
|
85 | this.updateViewWelcomeNodes();
|
86 | this.update();
|
87 | }
|
88 | handleWelcomeContextChange() {
|
89 | let didChange = false;
|
90 | for (const item of this.items) {
|
91 | if (!item.welcomeInfo.when || item.welcomeInfo.when === 'default') {
|
92 | continue;
|
93 | }
|
94 | const visible = item.welcomeInfo.when === undefined || this.contextService.match(item.welcomeInfo.when);
|
95 | if (item.visible === visible) {
|
96 | continue;
|
97 | }
|
98 | item.visible = visible;
|
99 | didChange = true;
|
100 | }
|
101 | if (didChange) {
|
102 | this.updateViewWelcomeNodes();
|
103 | this.update();
|
104 | }
|
105 | }
|
106 | updateViewWelcomeNodes() {
|
107 | this.viewWelcomeNodes = [];
|
108 | const items = this.visibleItems.sort((a, b) => a.order - b.order);
|
109 | for (const [iIndex, { content }] of items.entries()) {
|
110 | const lines = content.split('\n');
|
111 | for (let [lIndex, line] of lines.entries()) {
|
112 | const lineKey = `${iIndex}-${lIndex}`;
|
113 | line = line.trim();
|
114 | if (!line) {
|
115 | continue;
|
116 | }
|
117 | const linkedTextItems = this.parseLinkedText(line);
|
118 | if (linkedTextItems.length === 1 && typeof linkedTextItems[0] !== 'string') {
|
119 | this.viewWelcomeNodes.push(this.renderButtonNode(linkedTextItems[0], lineKey));
|
120 | }
|
121 | else {
|
122 | const linkedTextNodes = [];
|
123 | for (const [nIndex, node] of linkedTextItems.entries()) {
|
124 | const linkedTextKey = `${lineKey}-${nIndex}`;
|
125 | if (typeof node === 'string') {
|
126 | linkedTextNodes.push(this.renderTextNode(node, linkedTextKey));
|
127 | }
|
128 | else {
|
129 | linkedTextNodes.push(this.renderCommandLinkNode(node, linkedTextKey));
|
130 | }
|
131 | }
|
132 | this.viewWelcomeNodes.push(React.createElement("div", { key: `line-${lineKey}` }, ...linkedTextNodes));
|
133 | }
|
134 | }
|
135 | }
|
136 | }
|
137 | renderButtonNode(node, lineKey) {
|
138 | return (React.createElement("div", { key: `line-${lineKey}`, className: 'theia-WelcomeViewButtonWrapper' },
|
139 | React.createElement("button", { title: node.title, className: 'theia-button theia-WelcomeViewButton', disabled: !this.isEnabledClick(node.href), onClick: e => this.openLinkOrCommand(e, node.href) }, node.label)));
|
140 | }
|
141 | renderTextNode(node, textKey) {
|
142 | return React.createElement("span", { key: `text-${textKey}` }, node);
|
143 | }
|
144 | renderCommandLinkNode(node, linkKey) {
|
145 | return (React.createElement("a", { key: `link-${linkKey}`, className: this.getLinkClassName(node.href), title: node.title || '', onClick: e => this.openLinkOrCommand(e, node.href) }, node.label));
|
146 | }
|
147 | getLinkClassName(href) {
|
148 | const classNames = ['theia-WelcomeViewCommandLink'];
|
149 | if (!this.isEnabledClick(href)) {
|
150 | classNames.push('disabled');
|
151 | }
|
152 | return classNames.join(' ');
|
153 | }
|
154 | isEnabledClick(href) {
|
155 | if (href.startsWith('command:')) {
|
156 | const command = href.replace('command:', '');
|
157 | return this.commands.isEnabled(command);
|
158 | }
|
159 | return true;
|
160 | }
|
161 | parseLinkedText(text) {
|
162 | const result = [];
|
163 | const linkRegex = /\[([^\]]+)\]\(((?:https?:\/\/|command:)[^\)\s]+)(?: ("|')([^\3]+)(\3))?\)/gi;
|
164 | let index = 0;
|
165 | let match;
|
166 | while (match = linkRegex.exec(text)) {
|
167 | if (match.index - index > 0) {
|
168 | result.push(text.substring(index, match.index));
|
169 | }
|
170 | const [, label, href, , title] = match;
|
171 | if (title) {
|
172 | result.push({ label, href, title });
|
173 | }
|
174 | else {
|
175 | result.push({ label, href });
|
176 | }
|
177 | index = match.index + match[0].length;
|
178 | }
|
179 | if (index < text.length) {
|
180 | result.push(text.substring(index));
|
181 | }
|
182 | return result;
|
183 | }
|
184 | };
|
185 | __decorate([
|
186 | (0, inversify_1.inject)(common_1.CommandRegistry),
|
187 | __metadata("design:type", common_1.CommandRegistry)
|
188 | ], TreeViewWelcomeWidget.prototype, "commands", void 0);
|
189 | __decorate([
|
190 | (0, inversify_1.inject)(context_key_service_1.ContextKeyService),
|
191 | __metadata("design:type", Object)
|
192 | ], TreeViewWelcomeWidget.prototype, "contextService", void 0);
|
193 | __decorate([
|
194 | (0, inversify_1.inject)(window_service_1.WindowService),
|
195 | __metadata("design:type", Object)
|
196 | ], TreeViewWelcomeWidget.prototype, "windowService", void 0);
|
197 | TreeViewWelcomeWidget = __decorate([
|
198 | (0, inversify_1.injectable)()
|
199 | ], TreeViewWelcomeWidget);
|
200 | exports.TreeViewWelcomeWidget = TreeViewWelcomeWidget;
|
201 |
|
\ | No newline at end of file |