@theia/scm 1.34.3 → 1.34.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +31 -31
  3. package/lib/browser/decorations/scm-decorations-service.d.ts +14 -14
  4. package/lib/browser/decorations/scm-decorations-service.js +101 -101
  5. package/lib/browser/decorations/scm-navigator-decorator.d.ts +25 -25
  6. package/lib/browser/decorations/scm-navigator-decorator.js +132 -132
  7. package/lib/browser/decorations/scm-tab-bar-decorator.d.ts +17 -17
  8. package/lib/browser/decorations/scm-tab-bar-decorator.js +93 -93
  9. package/lib/browser/dirty-diff/content-lines.d.ts +12 -12
  10. package/lib/browser/dirty-diff/content-lines.js +106 -106
  11. package/lib/browser/dirty-diff/content-lines.spec.d.ts +1 -1
  12. package/lib/browser/dirty-diff/content-lines.spec.js +39 -39
  13. package/lib/browser/dirty-diff/diff-computer.d.ts +29 -29
  14. package/lib/browser/dirty-diff/diff-computer.js +102 -102
  15. package/lib/browser/dirty-diff/diff-computer.spec.d.ts +1 -1
  16. package/lib/browser/dirty-diff/diff-computer.spec.js +315 -315
  17. package/lib/browser/dirty-diff/dirty-diff-decorator.d.ts +14 -14
  18. package/lib/browser/dirty-diff/dirty-diff-decorator.js +98 -98
  19. package/lib/browser/dirty-diff/dirty-diff-module.d.ts +3 -3
  20. package/lib/browser/dirty-diff/dirty-diff-module.js +24 -24
  21. package/lib/browser/scm-amend-component.d.ts +123 -123
  22. package/lib/browser/scm-amend-component.js +423 -423
  23. package/lib/browser/scm-amend-widget.d.ts +20 -20
  24. package/lib/browser/scm-amend-widget.js +101 -101
  25. package/lib/browser/scm-avatar-service.d.ts +3 -3
  26. package/lib/browser/scm-avatar-service.js +36 -36
  27. package/lib/browser/scm-commit-widget.d.ts +52 -52
  28. package/lib/browser/scm-commit-widget.js +199 -199
  29. package/lib/browser/scm-context-key-service.d.ts +10 -10
  30. package/lib/browser/scm-context-key-service.js +58 -58
  31. package/lib/browser/scm-contribution.d.ts +83 -83
  32. package/lib/browser/scm-contribution.js +353 -353
  33. package/lib/browser/scm-frontend-module.d.ts +6 -6
  34. package/lib/browser/scm-frontend-module.js +130 -130
  35. package/lib/browser/scm-groups-tree-model.d.ts +14 -14
  36. package/lib/browser/scm-groups-tree-model.js +97 -97
  37. package/lib/browser/scm-input.d.ts +53 -53
  38. package/lib/browser/scm-input.js +127 -127
  39. package/lib/browser/scm-layout-migrations.d.ts +9 -9
  40. package/lib/browser/scm-layout-migrations.js +79 -79
  41. package/lib/browser/scm-no-repository-widget.d.ts +8 -8
  42. package/lib/browser/scm-no-repository-widget.js +49 -49
  43. package/lib/browser/scm-preferences.d.ts +11 -11
  44. package/lib/browser/scm-preferences.js +51 -51
  45. package/lib/browser/scm-provider.d.ts +56 -56
  46. package/lib/browser/scm-provider.js +19 -19
  47. package/lib/browser/scm-quick-open-service.d.ts +11 -11
  48. package/lib/browser/scm-quick-open-service.js +73 -73
  49. package/lib/browser/scm-repository.d.ts +17 -17
  50. package/lib/browser/scm-repository.js +41 -41
  51. package/lib/browser/scm-service.d.ts +26 -26
  52. package/lib/browser/scm-service.js +108 -108
  53. package/lib/browser/scm-tree-label-provider.d.ts +7 -7
  54. package/lib/browser/scm-tree-label-provider.js +57 -57
  55. package/lib/browser/scm-tree-model.d.ts +74 -74
  56. package/lib/browser/scm-tree-model.js +348 -348
  57. package/lib/browser/scm-tree-widget.d.ts +201 -201
  58. package/lib/browser/scm-tree-widget.js +664 -664
  59. package/lib/browser/scm-widget.d.ts +40 -40
  60. package/lib/browser/scm-widget.js +218 -218
  61. package/package.json +6 -6
  62. package/src/browser/decorations/scm-decorations-service.ts +78 -78
  63. package/src/browser/decorations/scm-navigator-decorator.ts +121 -121
  64. package/src/browser/decorations/scm-tab-bar-decorator.ts +83 -83
  65. package/src/browser/dirty-diff/content-lines.spec.ts +42 -42
  66. package/src/browser/dirty-diff/content-lines.ts +112 -112
  67. package/src/browser/dirty-diff/diff-computer.spec.ts +387 -387
  68. package/src/browser/dirty-diff/diff-computer.ts +129 -129
  69. package/src/browser/dirty-diff/dirty-diff-decorator.ts +107 -107
  70. package/src/browser/dirty-diff/dirty-diff-module.ts +24 -24
  71. package/src/browser/scm-amend-component.tsx +600 -600
  72. package/src/browser/scm-amend-widget.tsx +77 -77
  73. package/src/browser/scm-avatar-service.ts +27 -27
  74. package/src/browser/scm-commit-widget.tsx +215 -215
  75. package/src/browser/scm-context-key-service.ts +46 -46
  76. package/src/browser/scm-contribution.ts +361 -361
  77. package/src/browser/scm-frontend-module.ts +149 -149
  78. package/src/browser/scm-groups-tree-model.ts +78 -78
  79. package/src/browser/scm-input.ts +164 -164
  80. package/src/browser/scm-layout-migrations.ts +64 -64
  81. package/src/browser/scm-no-repository-widget.tsx +41 -41
  82. package/src/browser/scm-preferences.ts +63 -63
  83. package/src/browser/scm-provider.ts +89 -89
  84. package/src/browser/scm-quick-open-service.ts +48 -48
  85. package/src/browser/scm-repository.ts +52 -52
  86. package/src/browser/scm-service.ts +108 -108
  87. package/src/browser/scm-tree-label-provider.ts +44 -44
  88. package/src/browser/scm-tree-model.ts +405 -405
  89. package/src/browser/scm-tree-widget.tsx +809 -809
  90. package/src/browser/scm-widget.tsx +204 -204
  91. package/src/browser/style/dirty-diff-decorator.css +52 -52
  92. package/src/browser/style/dirty-diff.css +50 -50
  93. package/src/browser/style/index.css +267 -267
  94. package/src/browser/style/scm-amend-component.css +94 -94
  95. package/src/browser/style/scm.svg +4 -4
@@ -1,665 +1,665 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2020 Arm 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
- // *****************************************************************************
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
- var __param = (this && this.__param) || function (paramIndex, decorator) {
27
- return function (target, key) { decorator(target, key, paramIndex); }
28
- };
29
- var ScmTreeWidget_1;
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.ScmInlineAction = exports.ScmInlineActions = exports.ScmResourceFolderElement = exports.ScmResourceGroupElement = exports.ScmResourceComponent = exports.ScmElement = exports.ScmTreeWidget = void 0;
32
- /* eslint-disable no-null/no-null, @typescript-eslint/no-explicit-any */
33
- const React = require("@theia/core/shared/react");
34
- const inversify_1 = require("@theia/core/shared/inversify");
35
- const uri_1 = require("@theia/core/lib/common/uri");
36
- const os_1 = require("@theia/core/lib/common/os");
37
- const disposable_1 = require("@theia/core/lib/common/disposable");
38
- const tree_1 = require("@theia/core/lib/browser/tree");
39
- const scm_tree_model_1 = require("./scm-tree-model");
40
- const menu_1 = require("@theia/core/lib/common/menu");
41
- const command_1 = require("@theia/core/lib/common/command");
42
- const browser_1 = require("@theia/core/lib/browser");
43
- const scm_context_key_service_1 = require("./scm-context-key-service");
44
- const browser_2 = require("@theia/editor/lib/browser");
45
- const icon_theme_service_1 = require("@theia/core/lib/browser/icon-theme-service");
46
- const color_registry_1 = require("@theia/core/lib/browser/color-registry");
47
- const decorations_service_1 = require("@theia/core/lib/browser/decorations-service");
48
- const files_1 = require("@theia/filesystem/lib/common/files");
49
- let ScmTreeWidget = ScmTreeWidget_1 = class ScmTreeWidget extends tree_1.TreeWidget {
50
- constructor(props, treeModel, contextMenuRenderer) {
51
- super(props, treeModel, contextMenuRenderer);
52
- this.id = ScmTreeWidget_1.ID;
53
- this.addClass('groups-outer-container');
54
- }
55
- set viewMode(id) {
56
- // Close the search box because the structure of the tree will change dramatically
57
- // and the search results will be out of date.
58
- this.searchBox.hide();
59
- this.model.viewMode = id;
60
- }
61
- get viewMode() {
62
- return this.model.viewMode;
63
- }
64
- /**
65
- * Render the node given the tree node and node properties.
66
- * @param node the tree node.
67
- * @param props the node properties.
68
- */
69
- renderNode(node, props) {
70
- var _a;
71
- if (!tree_1.TreeNode.isVisible(node)) {
72
- return undefined;
73
- }
74
- const attributes = this.createNodeAttributes(node, props);
75
- const label = this.labelProvider.getName(node);
76
- const searchHighlights = (_a = this.searchHighlights) === null || _a === void 0 ? void 0 : _a.get(node.id);
77
- // The group nodes should not be subject to highlighting.
78
- const caption = (searchHighlights && !scm_tree_model_1.ScmFileChangeGroupNode.is(node)) ? this.toReactNode(label, searchHighlights) : label;
79
- if (scm_tree_model_1.ScmFileChangeGroupNode.is(node)) {
80
- const content = React.createElement(ScmResourceGroupElement, { key: `${node.groupId}`, model: this.model, treeNode: node, renderExpansionToggle: () => this.renderExpansionToggle(node, props), contextMenuRenderer: this.contextMenuRenderer, commands: this.commands, menus: this.menus, contextKeys: this.contextKeys, labelProvider: this.labelProvider, corePreferences: this.corePreferences, caption: caption });
81
- return React.createElement('div', attributes, content);
82
- }
83
- if (scm_tree_model_1.ScmFileChangeFolderNode.is(node)) {
84
- const content = React.createElement(ScmResourceFolderElement, { key: String(node.sourceUri), model: this.model, treeNode: node, sourceUri: node.sourceUri, renderExpansionToggle: () => this.renderExpansionToggle(node, props), contextMenuRenderer: this.contextMenuRenderer, commands: this.commands, menus: this.menus, contextKeys: this.contextKeys, labelProvider: this.labelProvider, corePreferences: this.corePreferences, caption: caption });
85
- return React.createElement('div', attributes, content);
86
- }
87
- if (scm_tree_model_1.ScmFileChangeNode.is(node)) {
88
- const parentPath = (node.parent && scm_tree_model_1.ScmFileChangeFolderNode.is(node.parent))
89
- ? new uri_1.default(node.parent.sourceUri) : new uri_1.default(this.model.rootUri);
90
- const content = React.createElement(ScmResourceComponent, Object.assign({ key: node.sourceUri, model: this.model, treeNode: node, contextMenuRenderer: this.contextMenuRenderer, commands: this.commands, menus: this.menus, contextKeys: this.contextKeys, labelProvider: this.labelProvider, corePreferences: this.corePreferences, caption: caption }, Object.assign(Object.assign({}, this.props), { parentPath, sourceUri: node.sourceUri, decoration: this.decorationsService.getDecoration(new uri_1.default(node.sourceUri), true)[0], colors: this.colors, renderExpansionToggle: () => this.renderExpansionToggle(node, props) })));
91
- return React.createElement('div', attributes, content);
92
- }
93
- return super.renderNode(node, props);
94
- }
95
- createContainerAttributes() {
96
- if (this.model.canTabToWidget()) {
97
- return Object.assign(Object.assign({}, super.createContainerAttributes()), { tabIndex: 0 });
98
- }
99
- return super.createContainerAttributes();
100
- }
101
- /**
102
- * The ARROW_LEFT key controls both the movement around the file tree and also
103
- * the movement through the change chunks within a file.
104
- *
105
- * If the selected tree node is a folder then the ARROW_LEFT key behaves exactly
106
- * as it does in explorer. It collapses the tree node if the folder is expanded and
107
- * it moves the selection up to the parent folder if the folder is collapsed (no-op if no parent folder, as
108
- * group headers are not selectable). This behavior is the default behavior implemented
109
- * in the TreeWidget super class.
110
- *
111
- * If the selected tree node is a file then the ARROW_LEFT key moves up through the
112
- * change chunks within each file. If the selected chunk is the first chunk in the file
113
- * then the file selection is moved to the previous file (no-op if no previous file).
114
- *
115
- * Note that when cursoring through change chunks, the ARROW_LEFT key cannot be used to
116
- * move up through the parent folders of the file tree. If users want to do this, using
117
- * keys only, then they must press ARROW_UP repeatedly until the selected node is the folder
118
- * node and then press ARROW_LEFT.
119
- */
120
- async handleLeft(event) {
121
- if (this.model.selectedNodes.length === 1) {
122
- const selectedNode = this.model.selectedNodes[0];
123
- if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
124
- const selectedResource = this.model.getResourceFromNode(selectedNode);
125
- if (!selectedResource) {
126
- return super.handleLeft(event);
127
- }
128
- const widget = await this.openResource(selectedResource);
129
- if (widget) {
130
- const diffNavigator = this.diffNavigatorProvider(widget.editor);
131
- if (diffNavigator.hasPrevious()) {
132
- diffNavigator.previous();
133
- }
134
- else {
135
- const previousNode = this.moveToPreviousFileNode();
136
- if (previousNode) {
137
- const previousResource = this.model.getResourceFromNode(previousNode);
138
- if (previousResource) {
139
- this.openResource(previousResource);
140
- }
141
- }
142
- }
143
- return;
144
- }
145
- }
146
- }
147
- return super.handleLeft(event);
148
- }
149
- /**
150
- * The ARROW_RIGHT key controls both the movement around the file tree and also
151
- * the movement through the change chunks within a file.
152
- *
153
- * If the selected tree node is a folder then the ARROW_RIGHT key behaves exactly
154
- * as it does in explorer. It expands the tree node if the folder is collapsed and
155
- * it moves the selection to the first child node if the folder is expanded.
156
- * This behavior is the default behavior implemented
157
- * in the TreeWidget super class.
158
- *
159
- * If the selected tree node is a file then the ARROW_RIGHT key moves down through the
160
- * change chunks within each file. If the selected chunk is the last chunk in the file
161
- * then the file selection is moved to the next file (no-op if no next file).
162
- */
163
- async handleRight(event) {
164
- if (this.model.selectedNodes.length === 0) {
165
- const firstNode = this.getFirstSelectableNode();
166
- // Selects the first visible resource as none are selected.
167
- if (!firstNode) {
168
- return;
169
- }
170
- this.model.selectNode(firstNode);
171
- return;
172
- }
173
- if (this.model.selectedNodes.length === 1) {
174
- const selectedNode = this.model.selectedNodes[0];
175
- if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
176
- const selectedResource = this.model.getResourceFromNode(selectedNode);
177
- if (!selectedResource) {
178
- return super.handleRight(event);
179
- }
180
- const widget = await this.openResource(selectedResource);
181
- if (widget) {
182
- const diffNavigator = this.diffNavigatorProvider(widget.editor);
183
- if (diffNavigator.hasNext()) {
184
- diffNavigator.next();
185
- }
186
- else {
187
- const nextNode = this.moveToNextFileNode();
188
- if (nextNode) {
189
- const nextResource = this.model.getResourceFromNode(nextNode);
190
- if (nextResource) {
191
- this.openResource(nextResource);
192
- }
193
- }
194
- }
195
- }
196
- return;
197
- }
198
- }
199
- return super.handleRight(event);
200
- }
201
- handleEnter(event) {
202
- if (this.model.selectedNodes.length === 1) {
203
- const selectedNode = this.model.selectedNodes[0];
204
- if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
205
- const selectedResource = this.model.getResourceFromNode(selectedNode);
206
- if (selectedResource) {
207
- this.openResource(selectedResource);
208
- }
209
- return;
210
- }
211
- }
212
- super.handleEnter(event);
213
- }
214
- async goToPreviousChange() {
215
- if (this.model.selectedNodes.length === 1) {
216
- const selectedNode = this.model.selectedNodes[0];
217
- if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
218
- if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
219
- const selectedResource = this.model.getResourceFromNode(selectedNode);
220
- if (!selectedResource) {
221
- return;
222
- }
223
- const widget = await this.openResource(selectedResource);
224
- if (widget) {
225
- const diffNavigator = this.diffNavigatorProvider(widget.editor);
226
- if (diffNavigator.hasPrevious()) {
227
- diffNavigator.previous();
228
- }
229
- else {
230
- const previousNode = this.moveToPreviousFileNode();
231
- if (previousNode) {
232
- const previousResource = this.model.getResourceFromNode(previousNode);
233
- if (previousResource) {
234
- this.openResource(previousResource);
235
- }
236
- }
237
- }
238
- }
239
- }
240
- }
241
- }
242
- }
243
- async goToNextChange() {
244
- if (this.model.selectedNodes.length === 0) {
245
- const firstNode = this.getFirstSelectableNode();
246
- // Selects the first visible resource as none are selected.
247
- if (!firstNode) {
248
- return;
249
- }
250
- this.model.selectNode(firstNode);
251
- return;
252
- }
253
- if (this.model.selectedNodes.length === 1) {
254
- const selectedNode = this.model.selectedNodes[0];
255
- if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
256
- const selectedResource = this.model.getResourceFromNode(selectedNode);
257
- if (!selectedResource) {
258
- return;
259
- }
260
- const widget = await this.openResource(selectedResource);
261
- if (widget) {
262
- const diffNavigator = this.diffNavigatorProvider(widget.editor);
263
- if (diffNavigator.hasNext()) {
264
- diffNavigator.next();
265
- }
266
- else {
267
- const nextNode = this.moveToNextFileNode();
268
- if (nextNode) {
269
- const nextResource = this.model.getResourceFromNode(nextNode);
270
- if (nextResource) {
271
- this.openResource(nextResource);
272
- }
273
- }
274
- }
275
- }
276
- }
277
- }
278
- }
279
- selectNodeByUri(uri) {
280
- for (const group of this.model.groups) {
281
- const sourceUri = new uri_1.default(uri.path.toString());
282
- const id = `${group.id}:${sourceUri.toString()}`;
283
- const node = this.model.getNode(id);
284
- if (tree_1.SelectableTreeNode.is(node)) {
285
- this.model.selectNode(node);
286
- return;
287
- }
288
- }
289
- }
290
- getFirstSelectableNode() {
291
- if (this.model.root) {
292
- const root = this.model.root;
293
- const groupNode = root.children[0];
294
- return groupNode.children[0];
295
- }
296
- }
297
- moveToPreviousFileNode() {
298
- let previousNode = this.model.getPrevSelectableNode();
299
- while (previousNode) {
300
- if (scm_tree_model_1.ScmFileChangeNode.is(previousNode)) {
301
- this.model.selectNode(previousNode);
302
- return previousNode;
303
- }
304
- previousNode = this.model.getPrevSelectableNode(previousNode);
305
- }
306
- ;
307
- }
308
- moveToNextFileNode() {
309
- let nextNode = this.model.getNextSelectableNode();
310
- while (nextNode) {
311
- if (scm_tree_model_1.ScmFileChangeNode.is(nextNode)) {
312
- this.model.selectNode(nextNode);
313
- return nextNode;
314
- }
315
- nextNode = this.model.getNextSelectableNode(nextNode);
316
- }
317
- ;
318
- }
319
- async openResource(resource) {
320
- try {
321
- await resource.open();
322
- }
323
- catch (e) {
324
- console.error('Failed to open a SCM resource', e);
325
- return undefined;
326
- }
327
- let standaloneEditor;
328
- const resourcePath = resource.sourceUri.path.toString();
329
- for (const widget of this.editorManager.all) {
330
- const resourceUri = widget.editor.document.uri;
331
- const editorResourcePath = new uri_1.default(resourceUri).path.toString();
332
- if (resourcePath === editorResourcePath) {
333
- if (widget.editor.uri.scheme === browser_1.DiffUris.DIFF_SCHEME) {
334
- // prefer diff editor
335
- return widget;
336
- }
337
- else {
338
- standaloneEditor = widget;
339
- }
340
- }
341
- if (widget.editor.uri.scheme === browser_1.DiffUris.DIFF_SCHEME
342
- && resourceUri === resource.sourceUri.toString()) {
343
- return widget;
344
- }
345
- }
346
- // fallback to standalone editor
347
- return standaloneEditor;
348
- }
349
- getPaddingLeft(node, props) {
350
- if (this.viewMode === 'list') {
351
- if (props.depth === 1) {
352
- return this.props.expansionTogglePadding;
353
- }
354
- }
355
- return super.getPaddingLeft(node, props);
356
- }
357
- needsExpansionTogglePadding(node) {
358
- const theme = this.iconThemeService.getDefinition(this.iconThemeService.current);
359
- if (theme && (theme.hidesExplorerArrows || (theme.hasFileIcons && !theme.hasFolderIcons))) {
360
- return false;
361
- }
362
- return super.needsExpansionTogglePadding(node);
363
- }
364
- };
365
- ScmTreeWidget.ID = 'scm-resource-widget';
366
- ScmTreeWidget.RESOURCE_GROUP_CONTEXT_MENU = ['RESOURCE_GROUP_CONTEXT_MENU'];
367
- ScmTreeWidget.RESOURCE_GROUP_INLINE_MENU = ['RESOURCE_GROUP_CONTEXT_MENU', 'inline'];
368
- ScmTreeWidget.RESOURCE_FOLDER_CONTEXT_MENU = ['RESOURCE_FOLDER_CONTEXT_MENU'];
369
- ScmTreeWidget.RESOURCE_FOLDER_INLINE_MENU = ['RESOURCE_FOLDER_CONTEXT_MENU', 'inline'];
370
- ScmTreeWidget.RESOURCE_CONTEXT_MENU = ['RESOURCE_CONTEXT_MENU'];
371
- ScmTreeWidget.RESOURCE_INLINE_MENU = ['RESOURCE_CONTEXT_MENU', 'inline'];
372
- __decorate([
373
- (0, inversify_1.inject)(menu_1.MenuModelRegistry),
374
- __metadata("design:type", menu_1.MenuModelRegistry)
375
- ], ScmTreeWidget.prototype, "menus", void 0);
376
- __decorate([
377
- (0, inversify_1.inject)(command_1.CommandRegistry),
378
- __metadata("design:type", command_1.CommandRegistry)
379
- ], ScmTreeWidget.prototype, "commands", void 0);
380
- __decorate([
381
- (0, inversify_1.inject)(scm_context_key_service_1.ScmContextKeyService),
382
- __metadata("design:type", scm_context_key_service_1.ScmContextKeyService)
383
- ], ScmTreeWidget.prototype, "contextKeys", void 0);
384
- __decorate([
385
- (0, inversify_1.inject)(browser_2.EditorManager),
386
- __metadata("design:type", browser_2.EditorManager)
387
- ], ScmTreeWidget.prototype, "editorManager", void 0);
388
- __decorate([
389
- (0, inversify_1.inject)(browser_2.DiffNavigatorProvider),
390
- __metadata("design:type", Function)
391
- ], ScmTreeWidget.prototype, "diffNavigatorProvider", void 0);
392
- __decorate([
393
- (0, inversify_1.inject)(icon_theme_service_1.IconThemeService),
394
- __metadata("design:type", icon_theme_service_1.IconThemeService)
395
- ], ScmTreeWidget.prototype, "iconThemeService", void 0);
396
- __decorate([
397
- (0, inversify_1.inject)(decorations_service_1.DecorationsService),
398
- __metadata("design:type", Object)
399
- ], ScmTreeWidget.prototype, "decorationsService", void 0);
400
- __decorate([
401
- (0, inversify_1.inject)(color_registry_1.ColorRegistry),
402
- __metadata("design:type", color_registry_1.ColorRegistry)
403
- ], ScmTreeWidget.prototype, "colors", void 0);
404
- ScmTreeWidget = ScmTreeWidget_1 = __decorate([
405
- (0, inversify_1.injectable)(),
406
- __param(0, (0, inversify_1.inject)(tree_1.TreeProps)),
407
- __param(1, (0, inversify_1.inject)(tree_1.TreeModel)),
408
- __param(2, (0, inversify_1.inject)(browser_1.ContextMenuRenderer)),
409
- __metadata("design:paramtypes", [Object, scm_tree_model_1.ScmTreeModel,
410
- browser_1.ContextMenuRenderer])
411
- ], ScmTreeWidget);
412
- exports.ScmTreeWidget = ScmTreeWidget;
413
- (function (ScmTreeWidget) {
414
- let Styles;
415
- (function (Styles) {
416
- Styles.NO_SELECT = 'no-select';
417
- })(Styles = ScmTreeWidget.Styles || (ScmTreeWidget.Styles = {}));
418
- })(ScmTreeWidget = exports.ScmTreeWidget || (exports.ScmTreeWidget = {}));
419
- exports.ScmTreeWidget = ScmTreeWidget;
420
- class ScmElement extends React.Component {
421
- constructor(props) {
422
- super(props);
423
- this.toDisposeOnUnmount = new disposable_1.DisposableCollection();
424
- this.detectHover = (element) => {
425
- if (element) {
426
- window.requestAnimationFrame(() => {
427
- const hover = element.matches(':hover');
428
- this.setState({ hover });
429
- });
430
- }
431
- };
432
- this.showHover = () => this.setState({ hover: true });
433
- this.hideHover = () => this.setState({ hover: false });
434
- this.renderContextMenu = (event) => {
435
- event.preventDefault();
436
- const { treeNode: node, contextMenuRenderer } = this.props;
437
- this.props.model.execInNodeContext(node, () => {
438
- contextMenuRenderer.render({
439
- menuPath: this.contextMenuPath,
440
- anchor: event.nativeEvent,
441
- args: this.contextMenuArgs
442
- });
443
- });
444
- };
445
- this.state = {
446
- hover: false
447
- };
448
- const setState = this.setState.bind(this);
449
- this.setState = newState => {
450
- if (!this.toDisposeOnUnmount.disposed) {
451
- setState(newState);
452
- }
453
- };
454
- }
455
- componentDidMount() {
456
- this.toDisposeOnUnmount.push(disposable_1.Disposable.create(() => { }));
457
- }
458
- componentWillUnmount() {
459
- this.toDisposeOnUnmount.dispose();
460
- }
461
- }
462
- exports.ScmElement = ScmElement;
463
- class ScmResourceComponent extends ScmElement {
464
- constructor() {
465
- super(...arguments);
466
- this.open = () => {
467
- const resource = this.props.model.getResourceFromNode(this.props.treeNode);
468
- if (resource) {
469
- resource.open();
470
- }
471
- };
472
- this.contextMenuPath = ScmTreeWidget.RESOURCE_CONTEXT_MENU;
473
- /**
474
- * Handle the single clicking of nodes present in the widget.
475
- */
476
- this.handleClick = (event) => {
477
- if (!this.hasCtrlCmdOrShiftMask(event)) {
478
- // Determine the behavior based on the preference value.
479
- const isSingle = this.props.corePreferences && this.props.corePreferences['workbench.list.openMode'] === 'singleClick';
480
- if (isSingle) {
481
- this.open();
482
- }
483
- }
484
- };
485
- /**
486
- * Handle the double clicking of nodes present in the widget.
487
- */
488
- this.handleDoubleClick = () => {
489
- // Determine the behavior based on the preference value.
490
- const isDouble = this.props.corePreferences && this.props.corePreferences['workbench.list.openMode'] === 'doubleClick';
491
- // Nodes should only be opened through double clicking if the correct preference is set.
492
- if (isDouble) {
493
- this.open();
494
- }
495
- };
496
- }
497
- render() {
498
- var _a;
499
- const { hover } = this.state;
500
- const { model, treeNode, colors, parentPath, sourceUri, decoration, labelProvider, commands, menus, contextKeys, caption } = this.props;
501
- const resourceUri = new uri_1.default(sourceUri);
502
- const icon = labelProvider.getIcon(resourceUri);
503
- const color = decoration && decoration.colorId ? `var(${colors.toCssVariableName(decoration.colorId)})` : '';
504
- const letter = decoration && decoration.letter || '';
505
- const tooltip = decoration && decoration.tooltip || '';
506
- const textDecoration = ((_a = treeNode.decorations) === null || _a === void 0 ? void 0 : _a.strikeThrough) === true ? 'line-through' : 'normal';
507
- const relativePath = parentPath.relative(resourceUri.parent);
508
- const path = relativePath ? relativePath.fsPath() : labelProvider.getLongName(resourceUri.parent);
509
- const title = tooltip.length !== 0
510
- ? `${resourceUri.path.fsPath()} • ${tooltip}`
511
- : resourceUri.path.fsPath();
512
- return React.createElement("div", { key: sourceUri, className: `scmItem ${tree_1.TREE_NODE_SEGMENT_CLASS} ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS}`, onContextMenu: this.renderContextMenu, onMouseEnter: this.showHover, onMouseLeave: this.hideHover, ref: this.detectHover, title: title, onClick: this.handleClick, onDoubleClick: this.handleDoubleClick },
513
- React.createElement("span", { className: icon + ' file-icon' }),
514
- this.props.renderExpansionToggle(),
515
- React.createElement("div", { className: `noWrapInfo ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS}` },
516
- React.createElement("span", { className: 'name', style: { textDecoration } }, caption),
517
- React.createElement("span", { className: 'path', style: { textDecoration } }, path)),
518
- React.createElement(ScmInlineActions, Object.assign({}, {
519
- hover,
520
- menu: menus.getMenu(ScmTreeWidget.RESOURCE_INLINE_MENU),
521
- args: this.contextMenuArgs,
522
- commands,
523
- contextKeys,
524
- model,
525
- treeNode
526
- }),
527
- React.createElement("div", { title: tooltip, className: 'status', style: { color } }, letter)));
528
- }
529
- get contextMenuArgs() {
530
- if (!this.props.model.selectedNodes.some(node => scm_tree_model_1.ScmFileChangeNode.is(node) && node.sourceUri === this.props.sourceUri)) {
531
- // Clicked node is not in selection, so ignore selection and action on just clicked node
532
- return this.singleNodeArgs;
533
- }
534
- else {
535
- return this.props.model.getSelectionArgs(this.props.model.selectedNodes);
536
- }
537
- }
538
- get singleNodeArgs() {
539
- const selectedResource = this.props.model.getResourceFromNode(this.props.treeNode);
540
- if (selectedResource) {
541
- return [selectedResource];
542
- }
543
- else {
544
- // Repository status not yet available. Empty args disables the action.
545
- return [];
546
- }
547
- }
548
- hasCtrlCmdOrShiftMask(event) {
549
- const { metaKey, ctrlKey, shiftKey } = event;
550
- return (os_1.isOSX && metaKey) || ctrlKey || shiftKey;
551
- }
552
- }
553
- exports.ScmResourceComponent = ScmResourceComponent;
554
- class ScmResourceGroupElement extends ScmElement {
555
- constructor() {
556
- super(...arguments);
557
- this.contextMenuPath = ScmTreeWidget.RESOURCE_GROUP_CONTEXT_MENU;
558
- }
559
- render() {
560
- const { hover } = this.state;
561
- const { model, treeNode, menus, commands, contextKeys, caption } = this.props;
562
- return React.createElement("div", { className: `theia-header scm-theia-header ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS}`, onContextMenu: this.renderContextMenu, onMouseEnter: this.showHover, onMouseLeave: this.hideHover, ref: this.detectHover },
563
- this.props.renderExpansionToggle(),
564
- React.createElement("div", { className: `noWrapInfo ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS}` }, caption),
565
- React.createElement(ScmInlineActions, Object.assign({}, {
566
- hover,
567
- args: this.contextMenuArgs,
568
- menu: menus.getMenu(ScmTreeWidget.RESOURCE_GROUP_INLINE_MENU),
569
- commands,
570
- contextKeys,
571
- model,
572
- treeNode
573
- }), this.renderChangeCount()));
574
- }
575
- renderChangeCount() {
576
- const group = this.props.model.getResourceGroupFromNode(this.props.treeNode);
577
- return React.createElement("div", { className: 'notification-count-container scm-change-count' },
578
- React.createElement("span", { className: 'notification-count' }, group ? group.resources.length : 0));
579
- }
580
- get contextMenuArgs() {
581
- const group = this.props.model.getResourceGroupFromNode(this.props.treeNode);
582
- if (group) {
583
- return [group];
584
- }
585
- else {
586
- // Repository status not yet available. Empty args disables the action.
587
- return [];
588
- }
589
- }
590
- }
591
- exports.ScmResourceGroupElement = ScmResourceGroupElement;
592
- class ScmResourceFolderElement extends ScmElement {
593
- constructor() {
594
- super(...arguments);
595
- this.contextMenuPath = ScmTreeWidget.RESOURCE_FOLDER_CONTEXT_MENU;
596
- }
597
- render() {
598
- const { hover } = this.state;
599
- const { model, treeNode, sourceUri, labelProvider, commands, menus, contextKeys, caption } = this.props;
600
- const sourceFileStat = files_1.FileStat.dir(sourceUri);
601
- const icon = labelProvider.getIcon(sourceFileStat);
602
- const title = new uri_1.default(sourceUri).path.fsPath();
603
- return React.createElement("div", { key: sourceUri, className: `scmItem ${tree_1.TREE_NODE_SEGMENT_CLASS} ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS} ${ScmTreeWidget.Styles.NO_SELECT}`, title: title, onContextMenu: this.renderContextMenu, onMouseEnter: this.showHover, onMouseLeave: this.hideHover, ref: this.detectHover },
604
- this.props.renderExpansionToggle(),
605
- React.createElement("span", { className: icon + ' file-icon' }),
606
- React.createElement("div", { className: `noWrapInfo ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS}` },
607
- React.createElement("span", { className: 'name' }, caption)),
608
- React.createElement(ScmInlineActions, Object.assign({}, {
609
- hover,
610
- menu: menus.getMenu(ScmTreeWidget.RESOURCE_FOLDER_INLINE_MENU),
611
- args: this.contextMenuArgs,
612
- commands,
613
- contextKeys,
614
- model,
615
- treeNode
616
- })));
617
- }
618
- get contextMenuArgs() {
619
- if (!this.props.model.selectedNodes.some(node => scm_tree_model_1.ScmFileChangeFolderNode.is(node) && node.sourceUri === this.props.sourceUri)) {
620
- // Clicked node is not in selection, so ignore selection and action on just clicked node
621
- return this.singleNodeArgs;
622
- }
623
- else {
624
- return this.props.model.getSelectionArgs(this.props.model.selectedNodes);
625
- }
626
- }
627
- get singleNodeArgs() {
628
- return this.props.model.getResourcesFromFolderNode(this.props.treeNode);
629
- }
630
- }
631
- exports.ScmResourceFolderElement = ScmResourceFolderElement;
632
- class ScmInlineActions extends React.Component {
633
- render() {
634
- const { hover, menu, args, commands, model, treeNode, contextKeys, children } = this.props;
635
- return React.createElement("div", { className: 'theia-scm-inline-actions-container' },
636
- React.createElement("div", { className: 'theia-scm-inline-actions' }, hover && menu.children
637
- .map((node, index) => node instanceof menu_1.ActionMenuNode && React.createElement(ScmInlineAction, Object.assign({ key: index }, { node, args, commands, model, treeNode, contextKeys })))),
638
- children);
639
- }
640
- }
641
- exports.ScmInlineActions = ScmInlineActions;
642
- class ScmInlineAction extends React.Component {
643
- constructor() {
644
- super(...arguments);
645
- this.execute = (event) => {
646
- event.stopPropagation();
647
- const { commands, node, args } = this.props;
648
- commands.executeCommand(node.command, ...args);
649
- };
650
- }
651
- render() {
652
- const { node, model, treeNode, args, commands, contextKeys } = this.props;
653
- let isActive = false;
654
- model.execInNodeContext(treeNode, () => {
655
- isActive = contextKeys.match(node.when);
656
- });
657
- if (!commands.isVisible(node.command, ...args) || !isActive) {
658
- return false;
659
- }
660
- return React.createElement("div", { className: 'theia-scm-inline-action' },
661
- React.createElement("a", { className: `${node.icon} ${browser_1.ACTION_ITEM}`, title: node.label, onClick: this.execute }));
662
- }
663
- }
664
- exports.ScmInlineAction = ScmInlineAction;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2020 Arm 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
+ // *****************************************************************************
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
27
+ return function (target, key) { decorator(target, key, paramIndex); }
28
+ };
29
+ var ScmTreeWidget_1;
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.ScmInlineAction = exports.ScmInlineActions = exports.ScmResourceFolderElement = exports.ScmResourceGroupElement = exports.ScmResourceComponent = exports.ScmElement = exports.ScmTreeWidget = void 0;
32
+ /* eslint-disable no-null/no-null, @typescript-eslint/no-explicit-any */
33
+ const React = require("@theia/core/shared/react");
34
+ const inversify_1 = require("@theia/core/shared/inversify");
35
+ const uri_1 = require("@theia/core/lib/common/uri");
36
+ const os_1 = require("@theia/core/lib/common/os");
37
+ const disposable_1 = require("@theia/core/lib/common/disposable");
38
+ const tree_1 = require("@theia/core/lib/browser/tree");
39
+ const scm_tree_model_1 = require("./scm-tree-model");
40
+ const menu_1 = require("@theia/core/lib/common/menu");
41
+ const command_1 = require("@theia/core/lib/common/command");
42
+ const browser_1 = require("@theia/core/lib/browser");
43
+ const scm_context_key_service_1 = require("./scm-context-key-service");
44
+ const browser_2 = require("@theia/editor/lib/browser");
45
+ const icon_theme_service_1 = require("@theia/core/lib/browser/icon-theme-service");
46
+ const color_registry_1 = require("@theia/core/lib/browser/color-registry");
47
+ const decorations_service_1 = require("@theia/core/lib/browser/decorations-service");
48
+ const files_1 = require("@theia/filesystem/lib/common/files");
49
+ let ScmTreeWidget = ScmTreeWidget_1 = class ScmTreeWidget extends tree_1.TreeWidget {
50
+ constructor(props, treeModel, contextMenuRenderer) {
51
+ super(props, treeModel, contextMenuRenderer);
52
+ this.id = ScmTreeWidget_1.ID;
53
+ this.addClass('groups-outer-container');
54
+ }
55
+ set viewMode(id) {
56
+ // Close the search box because the structure of the tree will change dramatically
57
+ // and the search results will be out of date.
58
+ this.searchBox.hide();
59
+ this.model.viewMode = id;
60
+ }
61
+ get viewMode() {
62
+ return this.model.viewMode;
63
+ }
64
+ /**
65
+ * Render the node given the tree node and node properties.
66
+ * @param node the tree node.
67
+ * @param props the node properties.
68
+ */
69
+ renderNode(node, props) {
70
+ var _a;
71
+ if (!tree_1.TreeNode.isVisible(node)) {
72
+ return undefined;
73
+ }
74
+ const attributes = this.createNodeAttributes(node, props);
75
+ const label = this.labelProvider.getName(node);
76
+ const searchHighlights = (_a = this.searchHighlights) === null || _a === void 0 ? void 0 : _a.get(node.id);
77
+ // The group nodes should not be subject to highlighting.
78
+ const caption = (searchHighlights && !scm_tree_model_1.ScmFileChangeGroupNode.is(node)) ? this.toReactNode(label, searchHighlights) : label;
79
+ if (scm_tree_model_1.ScmFileChangeGroupNode.is(node)) {
80
+ const content = React.createElement(ScmResourceGroupElement, { key: `${node.groupId}`, model: this.model, treeNode: node, renderExpansionToggle: () => this.renderExpansionToggle(node, props), contextMenuRenderer: this.contextMenuRenderer, commands: this.commands, menus: this.menus, contextKeys: this.contextKeys, labelProvider: this.labelProvider, corePreferences: this.corePreferences, caption: caption });
81
+ return React.createElement('div', attributes, content);
82
+ }
83
+ if (scm_tree_model_1.ScmFileChangeFolderNode.is(node)) {
84
+ const content = React.createElement(ScmResourceFolderElement, { key: String(node.sourceUri), model: this.model, treeNode: node, sourceUri: node.sourceUri, renderExpansionToggle: () => this.renderExpansionToggle(node, props), contextMenuRenderer: this.contextMenuRenderer, commands: this.commands, menus: this.menus, contextKeys: this.contextKeys, labelProvider: this.labelProvider, corePreferences: this.corePreferences, caption: caption });
85
+ return React.createElement('div', attributes, content);
86
+ }
87
+ if (scm_tree_model_1.ScmFileChangeNode.is(node)) {
88
+ const parentPath = (node.parent && scm_tree_model_1.ScmFileChangeFolderNode.is(node.parent))
89
+ ? new uri_1.default(node.parent.sourceUri) : new uri_1.default(this.model.rootUri);
90
+ const content = React.createElement(ScmResourceComponent, Object.assign({ key: node.sourceUri, model: this.model, treeNode: node, contextMenuRenderer: this.contextMenuRenderer, commands: this.commands, menus: this.menus, contextKeys: this.contextKeys, labelProvider: this.labelProvider, corePreferences: this.corePreferences, caption: caption }, Object.assign(Object.assign({}, this.props), { parentPath, sourceUri: node.sourceUri, decoration: this.decorationsService.getDecoration(new uri_1.default(node.sourceUri), true)[0], colors: this.colors, renderExpansionToggle: () => this.renderExpansionToggle(node, props) })));
91
+ return React.createElement('div', attributes, content);
92
+ }
93
+ return super.renderNode(node, props);
94
+ }
95
+ createContainerAttributes() {
96
+ if (this.model.canTabToWidget()) {
97
+ return Object.assign(Object.assign({}, super.createContainerAttributes()), { tabIndex: 0 });
98
+ }
99
+ return super.createContainerAttributes();
100
+ }
101
+ /**
102
+ * The ARROW_LEFT key controls both the movement around the file tree and also
103
+ * the movement through the change chunks within a file.
104
+ *
105
+ * If the selected tree node is a folder then the ARROW_LEFT key behaves exactly
106
+ * as it does in explorer. It collapses the tree node if the folder is expanded and
107
+ * it moves the selection up to the parent folder if the folder is collapsed (no-op if no parent folder, as
108
+ * group headers are not selectable). This behavior is the default behavior implemented
109
+ * in the TreeWidget super class.
110
+ *
111
+ * If the selected tree node is a file then the ARROW_LEFT key moves up through the
112
+ * change chunks within each file. If the selected chunk is the first chunk in the file
113
+ * then the file selection is moved to the previous file (no-op if no previous file).
114
+ *
115
+ * Note that when cursoring through change chunks, the ARROW_LEFT key cannot be used to
116
+ * move up through the parent folders of the file tree. If users want to do this, using
117
+ * keys only, then they must press ARROW_UP repeatedly until the selected node is the folder
118
+ * node and then press ARROW_LEFT.
119
+ */
120
+ async handleLeft(event) {
121
+ if (this.model.selectedNodes.length === 1) {
122
+ const selectedNode = this.model.selectedNodes[0];
123
+ if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
124
+ const selectedResource = this.model.getResourceFromNode(selectedNode);
125
+ if (!selectedResource) {
126
+ return super.handleLeft(event);
127
+ }
128
+ const widget = await this.openResource(selectedResource);
129
+ if (widget) {
130
+ const diffNavigator = this.diffNavigatorProvider(widget.editor);
131
+ if (diffNavigator.hasPrevious()) {
132
+ diffNavigator.previous();
133
+ }
134
+ else {
135
+ const previousNode = this.moveToPreviousFileNode();
136
+ if (previousNode) {
137
+ const previousResource = this.model.getResourceFromNode(previousNode);
138
+ if (previousResource) {
139
+ this.openResource(previousResource);
140
+ }
141
+ }
142
+ }
143
+ return;
144
+ }
145
+ }
146
+ }
147
+ return super.handleLeft(event);
148
+ }
149
+ /**
150
+ * The ARROW_RIGHT key controls both the movement around the file tree and also
151
+ * the movement through the change chunks within a file.
152
+ *
153
+ * If the selected tree node is a folder then the ARROW_RIGHT key behaves exactly
154
+ * as it does in explorer. It expands the tree node if the folder is collapsed and
155
+ * it moves the selection to the first child node if the folder is expanded.
156
+ * This behavior is the default behavior implemented
157
+ * in the TreeWidget super class.
158
+ *
159
+ * If the selected tree node is a file then the ARROW_RIGHT key moves down through the
160
+ * change chunks within each file. If the selected chunk is the last chunk in the file
161
+ * then the file selection is moved to the next file (no-op if no next file).
162
+ */
163
+ async handleRight(event) {
164
+ if (this.model.selectedNodes.length === 0) {
165
+ const firstNode = this.getFirstSelectableNode();
166
+ // Selects the first visible resource as none are selected.
167
+ if (!firstNode) {
168
+ return;
169
+ }
170
+ this.model.selectNode(firstNode);
171
+ return;
172
+ }
173
+ if (this.model.selectedNodes.length === 1) {
174
+ const selectedNode = this.model.selectedNodes[0];
175
+ if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
176
+ const selectedResource = this.model.getResourceFromNode(selectedNode);
177
+ if (!selectedResource) {
178
+ return super.handleRight(event);
179
+ }
180
+ const widget = await this.openResource(selectedResource);
181
+ if (widget) {
182
+ const diffNavigator = this.diffNavigatorProvider(widget.editor);
183
+ if (diffNavigator.hasNext()) {
184
+ diffNavigator.next();
185
+ }
186
+ else {
187
+ const nextNode = this.moveToNextFileNode();
188
+ if (nextNode) {
189
+ const nextResource = this.model.getResourceFromNode(nextNode);
190
+ if (nextResource) {
191
+ this.openResource(nextResource);
192
+ }
193
+ }
194
+ }
195
+ }
196
+ return;
197
+ }
198
+ }
199
+ return super.handleRight(event);
200
+ }
201
+ handleEnter(event) {
202
+ if (this.model.selectedNodes.length === 1) {
203
+ const selectedNode = this.model.selectedNodes[0];
204
+ if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
205
+ const selectedResource = this.model.getResourceFromNode(selectedNode);
206
+ if (selectedResource) {
207
+ this.openResource(selectedResource);
208
+ }
209
+ return;
210
+ }
211
+ }
212
+ super.handleEnter(event);
213
+ }
214
+ async goToPreviousChange() {
215
+ if (this.model.selectedNodes.length === 1) {
216
+ const selectedNode = this.model.selectedNodes[0];
217
+ if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
218
+ if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
219
+ const selectedResource = this.model.getResourceFromNode(selectedNode);
220
+ if (!selectedResource) {
221
+ return;
222
+ }
223
+ const widget = await this.openResource(selectedResource);
224
+ if (widget) {
225
+ const diffNavigator = this.diffNavigatorProvider(widget.editor);
226
+ if (diffNavigator.hasPrevious()) {
227
+ diffNavigator.previous();
228
+ }
229
+ else {
230
+ const previousNode = this.moveToPreviousFileNode();
231
+ if (previousNode) {
232
+ const previousResource = this.model.getResourceFromNode(previousNode);
233
+ if (previousResource) {
234
+ this.openResource(previousResource);
235
+ }
236
+ }
237
+ }
238
+ }
239
+ }
240
+ }
241
+ }
242
+ }
243
+ async goToNextChange() {
244
+ if (this.model.selectedNodes.length === 0) {
245
+ const firstNode = this.getFirstSelectableNode();
246
+ // Selects the first visible resource as none are selected.
247
+ if (!firstNode) {
248
+ return;
249
+ }
250
+ this.model.selectNode(firstNode);
251
+ return;
252
+ }
253
+ if (this.model.selectedNodes.length === 1) {
254
+ const selectedNode = this.model.selectedNodes[0];
255
+ if (scm_tree_model_1.ScmFileChangeNode.is(selectedNode)) {
256
+ const selectedResource = this.model.getResourceFromNode(selectedNode);
257
+ if (!selectedResource) {
258
+ return;
259
+ }
260
+ const widget = await this.openResource(selectedResource);
261
+ if (widget) {
262
+ const diffNavigator = this.diffNavigatorProvider(widget.editor);
263
+ if (diffNavigator.hasNext()) {
264
+ diffNavigator.next();
265
+ }
266
+ else {
267
+ const nextNode = this.moveToNextFileNode();
268
+ if (nextNode) {
269
+ const nextResource = this.model.getResourceFromNode(nextNode);
270
+ if (nextResource) {
271
+ this.openResource(nextResource);
272
+ }
273
+ }
274
+ }
275
+ }
276
+ }
277
+ }
278
+ }
279
+ selectNodeByUri(uri) {
280
+ for (const group of this.model.groups) {
281
+ const sourceUri = new uri_1.default(uri.path.toString());
282
+ const id = `${group.id}:${sourceUri.toString()}`;
283
+ const node = this.model.getNode(id);
284
+ if (tree_1.SelectableTreeNode.is(node)) {
285
+ this.model.selectNode(node);
286
+ return;
287
+ }
288
+ }
289
+ }
290
+ getFirstSelectableNode() {
291
+ if (this.model.root) {
292
+ const root = this.model.root;
293
+ const groupNode = root.children[0];
294
+ return groupNode.children[0];
295
+ }
296
+ }
297
+ moveToPreviousFileNode() {
298
+ let previousNode = this.model.getPrevSelectableNode();
299
+ while (previousNode) {
300
+ if (scm_tree_model_1.ScmFileChangeNode.is(previousNode)) {
301
+ this.model.selectNode(previousNode);
302
+ return previousNode;
303
+ }
304
+ previousNode = this.model.getPrevSelectableNode(previousNode);
305
+ }
306
+ ;
307
+ }
308
+ moveToNextFileNode() {
309
+ let nextNode = this.model.getNextSelectableNode();
310
+ while (nextNode) {
311
+ if (scm_tree_model_1.ScmFileChangeNode.is(nextNode)) {
312
+ this.model.selectNode(nextNode);
313
+ return nextNode;
314
+ }
315
+ nextNode = this.model.getNextSelectableNode(nextNode);
316
+ }
317
+ ;
318
+ }
319
+ async openResource(resource) {
320
+ try {
321
+ await resource.open();
322
+ }
323
+ catch (e) {
324
+ console.error('Failed to open a SCM resource', e);
325
+ return undefined;
326
+ }
327
+ let standaloneEditor;
328
+ const resourcePath = resource.sourceUri.path.toString();
329
+ for (const widget of this.editorManager.all) {
330
+ const resourceUri = widget.editor.document.uri;
331
+ const editorResourcePath = new uri_1.default(resourceUri).path.toString();
332
+ if (resourcePath === editorResourcePath) {
333
+ if (widget.editor.uri.scheme === browser_1.DiffUris.DIFF_SCHEME) {
334
+ // prefer diff editor
335
+ return widget;
336
+ }
337
+ else {
338
+ standaloneEditor = widget;
339
+ }
340
+ }
341
+ if (widget.editor.uri.scheme === browser_1.DiffUris.DIFF_SCHEME
342
+ && resourceUri === resource.sourceUri.toString()) {
343
+ return widget;
344
+ }
345
+ }
346
+ // fallback to standalone editor
347
+ return standaloneEditor;
348
+ }
349
+ getPaddingLeft(node, props) {
350
+ if (this.viewMode === 'list') {
351
+ if (props.depth === 1) {
352
+ return this.props.expansionTogglePadding;
353
+ }
354
+ }
355
+ return super.getPaddingLeft(node, props);
356
+ }
357
+ needsExpansionTogglePadding(node) {
358
+ const theme = this.iconThemeService.getDefinition(this.iconThemeService.current);
359
+ if (theme && (theme.hidesExplorerArrows || (theme.hasFileIcons && !theme.hasFolderIcons))) {
360
+ return false;
361
+ }
362
+ return super.needsExpansionTogglePadding(node);
363
+ }
364
+ };
365
+ ScmTreeWidget.ID = 'scm-resource-widget';
366
+ ScmTreeWidget.RESOURCE_GROUP_CONTEXT_MENU = ['RESOURCE_GROUP_CONTEXT_MENU'];
367
+ ScmTreeWidget.RESOURCE_GROUP_INLINE_MENU = ['RESOURCE_GROUP_CONTEXT_MENU', 'inline'];
368
+ ScmTreeWidget.RESOURCE_FOLDER_CONTEXT_MENU = ['RESOURCE_FOLDER_CONTEXT_MENU'];
369
+ ScmTreeWidget.RESOURCE_FOLDER_INLINE_MENU = ['RESOURCE_FOLDER_CONTEXT_MENU', 'inline'];
370
+ ScmTreeWidget.RESOURCE_CONTEXT_MENU = ['RESOURCE_CONTEXT_MENU'];
371
+ ScmTreeWidget.RESOURCE_INLINE_MENU = ['RESOURCE_CONTEXT_MENU', 'inline'];
372
+ __decorate([
373
+ (0, inversify_1.inject)(menu_1.MenuModelRegistry),
374
+ __metadata("design:type", menu_1.MenuModelRegistry)
375
+ ], ScmTreeWidget.prototype, "menus", void 0);
376
+ __decorate([
377
+ (0, inversify_1.inject)(command_1.CommandRegistry),
378
+ __metadata("design:type", command_1.CommandRegistry)
379
+ ], ScmTreeWidget.prototype, "commands", void 0);
380
+ __decorate([
381
+ (0, inversify_1.inject)(scm_context_key_service_1.ScmContextKeyService),
382
+ __metadata("design:type", scm_context_key_service_1.ScmContextKeyService)
383
+ ], ScmTreeWidget.prototype, "contextKeys", void 0);
384
+ __decorate([
385
+ (0, inversify_1.inject)(browser_2.EditorManager),
386
+ __metadata("design:type", browser_2.EditorManager)
387
+ ], ScmTreeWidget.prototype, "editorManager", void 0);
388
+ __decorate([
389
+ (0, inversify_1.inject)(browser_2.DiffNavigatorProvider),
390
+ __metadata("design:type", Function)
391
+ ], ScmTreeWidget.prototype, "diffNavigatorProvider", void 0);
392
+ __decorate([
393
+ (0, inversify_1.inject)(icon_theme_service_1.IconThemeService),
394
+ __metadata("design:type", icon_theme_service_1.IconThemeService)
395
+ ], ScmTreeWidget.prototype, "iconThemeService", void 0);
396
+ __decorate([
397
+ (0, inversify_1.inject)(decorations_service_1.DecorationsService),
398
+ __metadata("design:type", Object)
399
+ ], ScmTreeWidget.prototype, "decorationsService", void 0);
400
+ __decorate([
401
+ (0, inversify_1.inject)(color_registry_1.ColorRegistry),
402
+ __metadata("design:type", color_registry_1.ColorRegistry)
403
+ ], ScmTreeWidget.prototype, "colors", void 0);
404
+ ScmTreeWidget = ScmTreeWidget_1 = __decorate([
405
+ (0, inversify_1.injectable)(),
406
+ __param(0, (0, inversify_1.inject)(tree_1.TreeProps)),
407
+ __param(1, (0, inversify_1.inject)(tree_1.TreeModel)),
408
+ __param(2, (0, inversify_1.inject)(browser_1.ContextMenuRenderer)),
409
+ __metadata("design:paramtypes", [Object, scm_tree_model_1.ScmTreeModel,
410
+ browser_1.ContextMenuRenderer])
411
+ ], ScmTreeWidget);
412
+ exports.ScmTreeWidget = ScmTreeWidget;
413
+ (function (ScmTreeWidget) {
414
+ let Styles;
415
+ (function (Styles) {
416
+ Styles.NO_SELECT = 'no-select';
417
+ })(Styles = ScmTreeWidget.Styles || (ScmTreeWidget.Styles = {}));
418
+ })(ScmTreeWidget = exports.ScmTreeWidget || (exports.ScmTreeWidget = {}));
419
+ exports.ScmTreeWidget = ScmTreeWidget;
420
+ class ScmElement extends React.Component {
421
+ constructor(props) {
422
+ super(props);
423
+ this.toDisposeOnUnmount = new disposable_1.DisposableCollection();
424
+ this.detectHover = (element) => {
425
+ if (element) {
426
+ window.requestAnimationFrame(() => {
427
+ const hover = element.matches(':hover');
428
+ this.setState({ hover });
429
+ });
430
+ }
431
+ };
432
+ this.showHover = () => this.setState({ hover: true });
433
+ this.hideHover = () => this.setState({ hover: false });
434
+ this.renderContextMenu = (event) => {
435
+ event.preventDefault();
436
+ const { treeNode: node, contextMenuRenderer } = this.props;
437
+ this.props.model.execInNodeContext(node, () => {
438
+ contextMenuRenderer.render({
439
+ menuPath: this.contextMenuPath,
440
+ anchor: event.nativeEvent,
441
+ args: this.contextMenuArgs
442
+ });
443
+ });
444
+ };
445
+ this.state = {
446
+ hover: false
447
+ };
448
+ const setState = this.setState.bind(this);
449
+ this.setState = newState => {
450
+ if (!this.toDisposeOnUnmount.disposed) {
451
+ setState(newState);
452
+ }
453
+ };
454
+ }
455
+ componentDidMount() {
456
+ this.toDisposeOnUnmount.push(disposable_1.Disposable.create(() => { }));
457
+ }
458
+ componentWillUnmount() {
459
+ this.toDisposeOnUnmount.dispose();
460
+ }
461
+ }
462
+ exports.ScmElement = ScmElement;
463
+ class ScmResourceComponent extends ScmElement {
464
+ constructor() {
465
+ super(...arguments);
466
+ this.open = () => {
467
+ const resource = this.props.model.getResourceFromNode(this.props.treeNode);
468
+ if (resource) {
469
+ resource.open();
470
+ }
471
+ };
472
+ this.contextMenuPath = ScmTreeWidget.RESOURCE_CONTEXT_MENU;
473
+ /**
474
+ * Handle the single clicking of nodes present in the widget.
475
+ */
476
+ this.handleClick = (event) => {
477
+ if (!this.hasCtrlCmdOrShiftMask(event)) {
478
+ // Determine the behavior based on the preference value.
479
+ const isSingle = this.props.corePreferences && this.props.corePreferences['workbench.list.openMode'] === 'singleClick';
480
+ if (isSingle) {
481
+ this.open();
482
+ }
483
+ }
484
+ };
485
+ /**
486
+ * Handle the double clicking of nodes present in the widget.
487
+ */
488
+ this.handleDoubleClick = () => {
489
+ // Determine the behavior based on the preference value.
490
+ const isDouble = this.props.corePreferences && this.props.corePreferences['workbench.list.openMode'] === 'doubleClick';
491
+ // Nodes should only be opened through double clicking if the correct preference is set.
492
+ if (isDouble) {
493
+ this.open();
494
+ }
495
+ };
496
+ }
497
+ render() {
498
+ var _a;
499
+ const { hover } = this.state;
500
+ const { model, treeNode, colors, parentPath, sourceUri, decoration, labelProvider, commands, menus, contextKeys, caption } = this.props;
501
+ const resourceUri = new uri_1.default(sourceUri);
502
+ const icon = labelProvider.getIcon(resourceUri);
503
+ const color = decoration && decoration.colorId ? `var(${colors.toCssVariableName(decoration.colorId)})` : '';
504
+ const letter = decoration && decoration.letter || '';
505
+ const tooltip = decoration && decoration.tooltip || '';
506
+ const textDecoration = ((_a = treeNode.decorations) === null || _a === void 0 ? void 0 : _a.strikeThrough) === true ? 'line-through' : 'normal';
507
+ const relativePath = parentPath.relative(resourceUri.parent);
508
+ const path = relativePath ? relativePath.fsPath() : labelProvider.getLongName(resourceUri.parent);
509
+ const title = tooltip.length !== 0
510
+ ? `${resourceUri.path.fsPath()} • ${tooltip}`
511
+ : resourceUri.path.fsPath();
512
+ return React.createElement("div", { key: sourceUri, className: `scmItem ${tree_1.TREE_NODE_SEGMENT_CLASS} ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS}`, onContextMenu: this.renderContextMenu, onMouseEnter: this.showHover, onMouseLeave: this.hideHover, ref: this.detectHover, title: title, onClick: this.handleClick, onDoubleClick: this.handleDoubleClick },
513
+ React.createElement("span", { className: icon + ' file-icon' }),
514
+ this.props.renderExpansionToggle(),
515
+ React.createElement("div", { className: `noWrapInfo ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS}` },
516
+ React.createElement("span", { className: 'name', style: { textDecoration } }, caption),
517
+ React.createElement("span", { className: 'path', style: { textDecoration } }, path)),
518
+ React.createElement(ScmInlineActions, Object.assign({}, {
519
+ hover,
520
+ menu: menus.getMenu(ScmTreeWidget.RESOURCE_INLINE_MENU),
521
+ args: this.contextMenuArgs,
522
+ commands,
523
+ contextKeys,
524
+ model,
525
+ treeNode
526
+ }),
527
+ React.createElement("div", { title: tooltip, className: 'status', style: { color } }, letter)));
528
+ }
529
+ get contextMenuArgs() {
530
+ if (!this.props.model.selectedNodes.some(node => scm_tree_model_1.ScmFileChangeNode.is(node) && node.sourceUri === this.props.sourceUri)) {
531
+ // Clicked node is not in selection, so ignore selection and action on just clicked node
532
+ return this.singleNodeArgs;
533
+ }
534
+ else {
535
+ return this.props.model.getSelectionArgs(this.props.model.selectedNodes);
536
+ }
537
+ }
538
+ get singleNodeArgs() {
539
+ const selectedResource = this.props.model.getResourceFromNode(this.props.treeNode);
540
+ if (selectedResource) {
541
+ return [selectedResource];
542
+ }
543
+ else {
544
+ // Repository status not yet available. Empty args disables the action.
545
+ return [];
546
+ }
547
+ }
548
+ hasCtrlCmdOrShiftMask(event) {
549
+ const { metaKey, ctrlKey, shiftKey } = event;
550
+ return (os_1.isOSX && metaKey) || ctrlKey || shiftKey;
551
+ }
552
+ }
553
+ exports.ScmResourceComponent = ScmResourceComponent;
554
+ class ScmResourceGroupElement extends ScmElement {
555
+ constructor() {
556
+ super(...arguments);
557
+ this.contextMenuPath = ScmTreeWidget.RESOURCE_GROUP_CONTEXT_MENU;
558
+ }
559
+ render() {
560
+ const { hover } = this.state;
561
+ const { model, treeNode, menus, commands, contextKeys, caption } = this.props;
562
+ return React.createElement("div", { className: `theia-header scm-theia-header ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS}`, onContextMenu: this.renderContextMenu, onMouseEnter: this.showHover, onMouseLeave: this.hideHover, ref: this.detectHover },
563
+ this.props.renderExpansionToggle(),
564
+ React.createElement("div", { className: `noWrapInfo ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS}` }, caption),
565
+ React.createElement(ScmInlineActions, Object.assign({}, {
566
+ hover,
567
+ args: this.contextMenuArgs,
568
+ menu: menus.getMenu(ScmTreeWidget.RESOURCE_GROUP_INLINE_MENU),
569
+ commands,
570
+ contextKeys,
571
+ model,
572
+ treeNode
573
+ }), this.renderChangeCount()));
574
+ }
575
+ renderChangeCount() {
576
+ const group = this.props.model.getResourceGroupFromNode(this.props.treeNode);
577
+ return React.createElement("div", { className: 'notification-count-container scm-change-count' },
578
+ React.createElement("span", { className: 'notification-count' }, group ? group.resources.length : 0));
579
+ }
580
+ get contextMenuArgs() {
581
+ const group = this.props.model.getResourceGroupFromNode(this.props.treeNode);
582
+ if (group) {
583
+ return [group];
584
+ }
585
+ else {
586
+ // Repository status not yet available. Empty args disables the action.
587
+ return [];
588
+ }
589
+ }
590
+ }
591
+ exports.ScmResourceGroupElement = ScmResourceGroupElement;
592
+ class ScmResourceFolderElement extends ScmElement {
593
+ constructor() {
594
+ super(...arguments);
595
+ this.contextMenuPath = ScmTreeWidget.RESOURCE_FOLDER_CONTEXT_MENU;
596
+ }
597
+ render() {
598
+ const { hover } = this.state;
599
+ const { model, treeNode, sourceUri, labelProvider, commands, menus, contextKeys, caption } = this.props;
600
+ const sourceFileStat = files_1.FileStat.dir(sourceUri);
601
+ const icon = labelProvider.getIcon(sourceFileStat);
602
+ const title = new uri_1.default(sourceUri).path.fsPath();
603
+ return React.createElement("div", { key: sourceUri, className: `scmItem ${tree_1.TREE_NODE_SEGMENT_CLASS} ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS} ${ScmTreeWidget.Styles.NO_SELECT}`, title: title, onContextMenu: this.renderContextMenu, onMouseEnter: this.showHover, onMouseLeave: this.hideHover, ref: this.detectHover },
604
+ this.props.renderExpansionToggle(),
605
+ React.createElement("span", { className: icon + ' file-icon' }),
606
+ React.createElement("div", { className: `noWrapInfo ${tree_1.TREE_NODE_SEGMENT_GROW_CLASS}` },
607
+ React.createElement("span", { className: 'name' }, caption)),
608
+ React.createElement(ScmInlineActions, Object.assign({}, {
609
+ hover,
610
+ menu: menus.getMenu(ScmTreeWidget.RESOURCE_FOLDER_INLINE_MENU),
611
+ args: this.contextMenuArgs,
612
+ commands,
613
+ contextKeys,
614
+ model,
615
+ treeNode
616
+ })));
617
+ }
618
+ get contextMenuArgs() {
619
+ if (!this.props.model.selectedNodes.some(node => scm_tree_model_1.ScmFileChangeFolderNode.is(node) && node.sourceUri === this.props.sourceUri)) {
620
+ // Clicked node is not in selection, so ignore selection and action on just clicked node
621
+ return this.singleNodeArgs;
622
+ }
623
+ else {
624
+ return this.props.model.getSelectionArgs(this.props.model.selectedNodes);
625
+ }
626
+ }
627
+ get singleNodeArgs() {
628
+ return this.props.model.getResourcesFromFolderNode(this.props.treeNode);
629
+ }
630
+ }
631
+ exports.ScmResourceFolderElement = ScmResourceFolderElement;
632
+ class ScmInlineActions extends React.Component {
633
+ render() {
634
+ const { hover, menu, args, commands, model, treeNode, contextKeys, children } = this.props;
635
+ return React.createElement("div", { className: 'theia-scm-inline-actions-container' },
636
+ React.createElement("div", { className: 'theia-scm-inline-actions' }, hover && menu.children
637
+ .map((node, index) => node instanceof menu_1.ActionMenuNode && React.createElement(ScmInlineAction, Object.assign({ key: index }, { node, args, commands, model, treeNode, contextKeys })))),
638
+ children);
639
+ }
640
+ }
641
+ exports.ScmInlineActions = ScmInlineActions;
642
+ class ScmInlineAction extends React.Component {
643
+ constructor() {
644
+ super(...arguments);
645
+ this.execute = (event) => {
646
+ event.stopPropagation();
647
+ const { commands, node, args } = this.props;
648
+ commands.executeCommand(node.command, ...args);
649
+ };
650
+ }
651
+ render() {
652
+ const { node, model, treeNode, args, commands, contextKeys } = this.props;
653
+ let isActive = false;
654
+ model.execInNodeContext(treeNode, () => {
655
+ isActive = contextKeys.match(node.when);
656
+ });
657
+ if (!commands.isVisible(node.command, ...args) || !isActive) {
658
+ return false;
659
+ }
660
+ return React.createElement("div", { className: 'theia-scm-inline-action' },
661
+ React.createElement("a", { className: `${node.icon} ${browser_1.ACTION_ITEM}`, title: node.label, onClick: this.execute }));
662
+ }
663
+ }
664
+ exports.ScmInlineAction = ScmInlineAction;
665
665
  //# sourceMappingURL=scm-tree-widget.js.map