@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1/**
2 * @requires javelin-dom
3 * javelin-install
4 * javelin-util
5 * phuix-icon-view
6 * @provides phabricator-diff-path-view
7 *
8 * @javelin-installs JX.DiffPathView
9 *
10 * @javelin
11 */
12
13JX.install('DiffPathView', {
14
15 construct: function() {
16 },
17
18 members: {
19 _node: null,
20 _path: null,
21 _depth: 0,
22 _selected: false,
23 _focused: false,
24 _icon: null,
25
26 _indentNode: null,
27 _pathNode: null,
28 _changeset: null,
29 _inlineNode: null,
30 _isDirectory: false,
31 _displayPath: null,
32 _isLowImportance: false,
33 _isOwned: false,
34 _isHidden: false,
35 _isLoading: false,
36
37 getNode: function() {
38 if (!this._node) {
39 var attrs = {
40 className: 'diff-tree-path'
41 };
42
43 this._node = JX.$N('li', attrs, this._getIndentNode());
44
45 var onclick = JX.bind(this, this._onclick);
46 JX.DOM.listen(this._node, 'click', null, onclick);
47 }
48 return this._node;
49 },
50
51 getIcon: function() {
52 if (!this._icon) {
53 this._icon = new JX.PHUIXIconView();
54 }
55 return this._icon;
56 },
57
58 setPath: function(path) {
59 this._path = path;
60 this._redrawPath();
61 return this;
62 },
63
64 setDisplayPath: function(path) {
65 this._displayPath = path;
66 this._redrawPath();
67 return this;
68 },
69
70 setIsDirectory: function(is_directory) {
71 this._isDirectory = is_directory;
72 this._redrawPath();
73 return this;
74 },
75
76 setChangeset: function(changeset) {
77 this._changeset = changeset;
78
79 var node = this.getNode();
80 JX.DOM.alterClass(node, 'diff-tree-path-changeset', !!changeset);
81
82 return this;
83 },
84
85 getChangeset: function() {
86 return this._changeset;
87 },
88
89 getPath: function() {
90 return this._path;
91 },
92
93 setHidden: function(hidden) {
94 this._hidden = hidden;
95
96 var node = this.getNode();
97 if (this._hidden) {
98 JX.DOM.hide(node);
99 } else {
100 JX.DOM.show(node);
101 }
102
103 return this;
104 },
105
106 setDepth: function(depth) {
107 this._depth = depth;
108
109 this._getIndentNode().style.marginLeft = (8 * this._depth) + 'px';
110
111 return this;
112 },
113
114 setIsSelected: function(selected) {
115 this._selected = selected;
116
117 var node = this.getNode();
118 JX.DOM.alterClass(node, 'diff-tree-path-selected', this._selected);
119
120 return this;
121 },
122
123 setIsFocused: function(focused) {
124 this._focused = focused;
125
126 var node = this.getNode();
127 JX.DOM.alterClass(node, 'diff-tree-path-focused', this._focused);
128
129 return this;
130 },
131
132 setIsLowImportance: function(low_importance) {
133 this._isLowImportance = low_importance;
134
135 var node = this.getNode();
136 JX.DOM.alterClass(
137 node,
138 'diff-tree-path-low-importance',
139 this._isLowImportance);
140
141 return this;
142 },
143
144 setIsOwned: function(owned) {
145 this._isOwned = owned;
146
147 var node = this.getNode();
148 JX.DOM.alterClass(node, 'diff-tree-path-owned', this._isOwned);
149
150 return this;
151 },
152
153 setIsHidden: function(hidden) {
154 this._isHidden = hidden;
155
156 var node = this.getNode();
157 JX.DOM.alterClass(node, 'diff-tree-path-hidden', this._isHidden);
158
159 return this;
160 },
161
162 setIsLoading: function(loading) {
163 this._isLoading = loading;
164
165 var node = this.getNode();
166 JX.DOM.alterClass(node, 'diff-tree-path-loading', this._isLoading);
167
168 return this;
169 },
170
171 _onclick: function(e) {
172 if (!e.isNormalClick()) {
173 return;
174 }
175
176 var changeset = this.getChangeset();
177 if (changeset) {
178 changeset.select(true);
179 }
180
181 e.kill();
182 },
183
184 _getIndentNode: function() {
185 if (!this._indentNode) {
186 var attrs = {
187 className: 'diff-tree-path-indent'
188 };
189
190 var content = [
191 this.getInlineNode(),
192 this._getHiddenIconNode(),
193 this._getIconNode(),
194 this._getPathNode(),
195 ];
196
197 this._indentNode = JX.$N('div', attrs, content);
198 }
199
200 return this._indentNode;
201 },
202
203 _getPathNode: function() {
204 if (!this._pathNode) {
205 var attrs = {
206 className: 'diff-tree-path-name'
207 };
208 this._pathNode = JX.$N('div', attrs);
209 }
210 return this._pathNode;
211 },
212
213 _getIconNode: function() {
214 if (!this._iconNode) {
215 var attrs = {
216 className: 'diff-tree-path-icon diff-tree-path-icon-kind',
217 };
218 this._iconNode = JX.$N('div', attrs, this.getIcon().getNode());
219 }
220 return this._iconNode;
221 },
222
223 _getHiddenIconNode: function() {
224 if (!this._hiddenIconNode) {
225 var attrs = {
226 className: 'diff-tree-path-icon diff-tree-path-icon-hidden',
227 };
228 this._hiddenIconNode =
229 JX.$N('div', attrs, this._getHiddenIcon().getNode());
230 }
231 return this._hiddenIconNode;
232 },
233
234 _getHiddenIcon: function() {
235 if (!this._hiddenIcon) {
236 this._hiddenIcon = new JX.PHUIXIconView()
237 .setIcon('fa-times-circle-o');
238 }
239 return this._hiddenIcon;
240 },
241
242 getInlineNode: function() {
243 if (!this._inlineNode) {
244 var attrs = {
245 className: 'diff-tree-path-inlines',
246 };
247 this._inlineNode = JX.$N('div', attrs, '-');
248 }
249 return this._inlineNode;
250 },
251
252 _redrawPath: function() {
253 var display;
254 if (this._displayPath) {
255 display = this._displayPath;
256 } else {
257 display = this._path[this._path.length - 1];
258 }
259
260 var is_directory = this._isDirectory;
261
262 if (is_directory) {
263 display = display + '/';
264 }
265
266 JX.DOM.setContent(this._getPathNode(), display);
267 }
268
269 }
270
271});