@codingame/monaco-vscode-scm-service-override 1.83.15

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.
@@ -0,0 +1,719 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import * as path from 'monaco-editor/esm/vs/base/common/path.js';
3
+ import { append, $, prepend } from 'monaco-editor/esm/vs/base/browser/dom.js';
4
+ import { CountBadge } from 'monaco-editor/esm/vs/base/browser/ui/countBadge/countBadge.js';
5
+ import { IconLabel } from 'monaco-editor/esm/vs/base/browser/ui/iconLabel/iconLabel.js';
6
+ import { DisposableStore, combinedDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
7
+ import { ThemeIcon } from 'monaco-editor/esm/vs/base/common/themables.js';
8
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
9
+ import { ICommandService } from 'monaco-editor/esm/vs/platform/commands/common/commands.js';
10
+ import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
11
+ import { RawContextKey, ContextKeyExpr, IContextKeyService } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey.js';
12
+ import { IContextMenuService } from 'monaco-editor/esm/vs/platform/contextview/browser/contextView.js';
13
+ import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
14
+ import { IKeybindingService } from 'monaco-editor/esm/vs/platform/keybinding/common/keybinding.js';
15
+ import { WorkbenchCompressibleAsyncDataTree } from 'monaco-editor/esm/vs/platform/list/browser/listService.js';
16
+ import { IOpenerService } from 'monaco-editor/esm/vs/platform/opener/common/opener.js';
17
+ import { ITelemetryService } from 'monaco-editor/esm/vs/platform/telemetry/common/telemetry.js';
18
+ import { defaultCountBadgeStyles } from 'monaco-editor/esm/vs/platform/theme/browser/defaultStyles.js';
19
+ import { IThemeService } from 'monaco-editor/esm/vs/platform/theme/common/themeService.js';
20
+ import { ResourceLabels } from 'vscode/vscode/vs/workbench/browser/labels';
21
+ import { API_OPEN_DIFF_EDITOR_COMMAND_ID } from 'vscode/vscode/vs/workbench/browser/parts/editor/editorCommands';
22
+ import { ViewPane, ViewAction } from 'vscode/vscode/vs/workbench/browser/parts/views/viewPane';
23
+ import { IViewDescriptorService } from 'vscode/vscode/vs/workbench/common/views';
24
+ import { RepositoryRenderer } from './scmRepositoryRenderer.js';
25
+ import { ActionButtonRenderer } from './scmViewPane.js';
26
+ import { getActionViewItemProvider, isSCMRepositoryArray, isSCMRepository, isSCMActionButton } from './util.js';
27
+ import { SYNC_VIEW_PANE_ID, ISCMViewService } from 'vscode/vscode/vs/workbench/contrib/scm/common/scm';
28
+ import { comparePaths } from 'monaco-editor/esm/vs/base/common/comparers.js';
29
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
30
+ import { Iterable } from 'monaco-editor/esm/vs/base/common/iterator.js';
31
+ import { IWorkspaceContextService } from 'monaco-editor/esm/vs/platform/workspace/common/workspace.js';
32
+ import { basename, dirname } from 'monaco-editor/esm/vs/base/common/resources.js';
33
+ import { ILabelService } from 'monaco-editor/esm/vs/platform/label/common/label.js';
34
+ import { stripIcons } from 'monaco-editor/esm/vs/base/common/iconLabels.js';
35
+ import { FileKind } from 'monaco-editor/esm/vs/platform/files/common/files.js';
36
+ import { registerAction2, MenuId } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
37
+ import { Codicon } from 'monaco-editor/esm/vs/base/common/codicons.js';
38
+ import { IStorageService } from 'monaco-editor/esm/vs/platform/storage/common/storage.js';
39
+ import { Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
40
+ import { ResourceTree } from '../../../../base/common/resourceTree.js';
41
+ import { IUriIdentityService } from 'monaco-editor/esm/vs/platform/uriIdentity/common/uriIdentity.js';
42
+
43
+ var HistoryItemChangeRenderer_1;
44
+ function isSCMHistoryItemGroupTreeElement(obj) {
45
+ return obj.type === 'historyItemGroup';
46
+ }
47
+ function isSCMHistoryItemTreeElement(obj) {
48
+ return obj.type === 'historyItem';
49
+ }
50
+ function isSCMHistoryItemChangeTreeElement(obj) {
51
+ return obj.type === 'historyItemChange';
52
+ }
53
+ function toDiffEditorArguments(uri, originalUri, modifiedUri) {
54
+ const basename = path.basename(uri.fsPath);
55
+ const originalQuery = JSON.parse(originalUri.query);
56
+ const modifiedQuery = JSON.parse(modifiedUri.query);
57
+ const originalShortRef = originalQuery.ref.substring(0, 8).concat(originalQuery.ref.endsWith('^') ? '^' : '');
58
+ const modifiedShortRef = modifiedQuery.ref.substring(0, 8).concat(modifiedQuery.ref.endsWith('^') ? '^' : '');
59
+ return [originalUri, modifiedUri, `${basename} (${originalShortRef}) ↔ ${basename} (${modifiedShortRef})`, null];
60
+ }
61
+ function getSCMResourceId(element) {
62
+ if (isSCMRepository(element)) {
63
+ const provider = element.provider;
64
+ return `repo:${provider.id}`;
65
+ }
66
+ else if (isSCMActionButton(element)) {
67
+ const provider = element.repository.provider;
68
+ return `actionButton:${provider.id}`;
69
+ }
70
+ else if (isSCMHistoryItemGroupTreeElement(element)) {
71
+ const provider = element.repository.provider;
72
+ return `historyItemGroup:${provider.id}/${element.id}`;
73
+ }
74
+ else if (isSCMHistoryItemTreeElement(element)) {
75
+ const historyItemGroup = element.historyItemGroup;
76
+ const provider = historyItemGroup.repository.provider;
77
+ return `historyItem:${provider.id}/${historyItemGroup.id}/${element.id}`;
78
+ }
79
+ else if (isSCMHistoryItemChangeTreeElement(element)) {
80
+ const historyItem = element.historyItem;
81
+ const historyItemGroup = historyItem.historyItemGroup;
82
+ const provider = historyItemGroup.repository.provider;
83
+ return `historyItemChange:${provider.id}/${historyItemGroup.id}/${historyItem.id}/${( element.uri.toString())}`;
84
+ }
85
+ else if (ResourceTree.isResourceNode(element)) {
86
+ const historyItem = element.context;
87
+ const historyItemGroup = historyItem.historyItemGroup;
88
+ const provider = historyItemGroup.repository.provider;
89
+ return element.childrenCount === 0 && element.element ?
90
+ `historyItemChange:${provider.id}/${historyItemGroup.id}/${historyItem.id}/${( element.element.uri.toString())}` :
91
+ `folder:${provider.id}/${historyItemGroup.id}/${historyItem.id}/$FOLDER/${( element.uri.toString())}`;
92
+ }
93
+ else {
94
+ throw new Error('Invalid tree element');
95
+ }
96
+ }
97
+ const ContextKeys = {
98
+ ViewMode: ( new RawContextKey('scmSyncViewMode', "list" )),
99
+ };
100
+ class ListDelegate {
101
+ getHeight(element) {
102
+ if (isSCMActionButton(element)) {
103
+ return ActionButtonRenderer.DEFAULT_HEIGHT + 10;
104
+ }
105
+ else {
106
+ return 22;
107
+ }
108
+ }
109
+ getTemplateId(element) {
110
+ if (isSCMRepository(element)) {
111
+ return RepositoryRenderer.TEMPLATE_ID;
112
+ }
113
+ else if (isSCMActionButton(element)) {
114
+ return ActionButtonRenderer.TEMPLATE_ID;
115
+ }
116
+ else if (isSCMHistoryItemGroupTreeElement(element)) {
117
+ return HistoryItemGroupRenderer.TEMPLATE_ID;
118
+ }
119
+ else if (isSCMHistoryItemTreeElement(element)) {
120
+ return HistoryItemRenderer.TEMPLATE_ID;
121
+ }
122
+ else if (isSCMHistoryItemChangeTreeElement(element)) {
123
+ return HistoryItemChangeRenderer.TEMPLATE_ID;
124
+ }
125
+ else if (ResourceTree.isResourceNode(element)) {
126
+ return HistoryItemChangeRenderer.TEMPLATE_ID;
127
+ }
128
+ else {
129
+ throw new Error('Invalid tree element');
130
+ }
131
+ }
132
+ }
133
+ class CompressionDelegate {
134
+ isIncompressible(element) {
135
+ if (ResourceTree.isResourceNode(element)) {
136
+ return element.childrenCount === 0 || !element.parent || !element.parent.parent;
137
+ }
138
+ return true;
139
+ }
140
+ }
141
+ class HistoryItemGroupRenderer {
142
+ static { this.TEMPLATE_ID = 'history-item-group'; }
143
+ get templateId() { return HistoryItemGroupRenderer.TEMPLATE_ID; }
144
+ renderTemplate(container) {
145
+ container.parentElement.parentElement.querySelector('.monaco-tl-twistie').classList.add('force-twistie');
146
+ const element = append(container, $('.history-item-group'));
147
+ const label = ( new IconLabel(element, { supportIcons: true }));
148
+ const countContainer = append(element, $('.count'));
149
+ const count = ( new CountBadge(countContainer, {}, defaultCountBadgeStyles));
150
+ return { label, count, disposables: ( new DisposableStore()) };
151
+ }
152
+ renderElement(node, index, templateData, height) {
153
+ const historyItemGroup = node.element;
154
+ templateData.label.setLabel(historyItemGroup.label, historyItemGroup.description);
155
+ templateData.count.setCount(historyItemGroup.count ?? 0);
156
+ }
157
+ disposeTemplate(templateData) {
158
+ templateData.disposables.dispose();
159
+ }
160
+ }
161
+ class HistoryItemRenderer {
162
+ static { this.TEMPLATE_ID = 'history-item'; }
163
+ get templateId() { return HistoryItemRenderer.TEMPLATE_ID; }
164
+ renderTemplate(container) {
165
+ container.parentElement.parentElement.querySelector('.monaco-tl-twistie').classList.add('force-twistie');
166
+ const element = append(container, $('.history-item'));
167
+ const iconLabel = ( new IconLabel(element, { supportIcons: true }));
168
+ const iconContainer = prepend(iconLabel.element, $('.icon-container'));
169
+ return { iconContainer, iconLabel, disposables: ( new DisposableStore()) };
170
+ }
171
+ renderElement(node, index, templateData, height) {
172
+ const historyItem = node.element;
173
+ templateData.iconContainer.className = 'icon-container';
174
+ if (historyItem.icon && ThemeIcon.isThemeIcon(historyItem.icon)) {
175
+ templateData.iconContainer.classList.add(...ThemeIcon.asClassNameArray(historyItem.icon));
176
+ }
177
+ templateData.iconLabel.setLabel(historyItem.label, historyItem.description);
178
+ }
179
+ disposeTemplate(templateData) {
180
+ templateData.disposables.dispose();
181
+ }
182
+ }
183
+ let HistoryItemChangeRenderer = class HistoryItemChangeRenderer {
184
+ static { HistoryItemChangeRenderer_1 = this; }
185
+ static { this.TEMPLATE_ID = 'historyItemChange'; }
186
+ get templateId() { return HistoryItemChangeRenderer_1.TEMPLATE_ID; }
187
+ constructor(viewMode, labels, labelService) {
188
+ this.viewMode = viewMode;
189
+ this.labels = labels;
190
+ this.labelService = labelService;
191
+ }
192
+ renderTemplate(container) {
193
+ const element = append(container, $('.change'));
194
+ const name = append(element, $('.name'));
195
+ const fileLabel = this.labels.create(name, { supportDescriptionHighlights: true, supportHighlights: true });
196
+ const decorationIcon = append(element, $('.decoration-icon'));
197
+ return { element, name, fileLabel, decorationIcon, disposables: ( new DisposableStore()) };
198
+ }
199
+ renderElement(node, index, templateData, height) {
200
+ const historyItemChangeOrFolder = node.element;
201
+ const uri = ResourceTree.isResourceNode(historyItemChangeOrFolder) ? historyItemChangeOrFolder.element?.uri ?? historyItemChangeOrFolder.uri : historyItemChangeOrFolder.uri;
202
+ const fileKind = ResourceTree.isResourceNode(historyItemChangeOrFolder) && historyItemChangeOrFolder.childrenCount > 0 ? FileKind.FOLDER : FileKind.FILE;
203
+ templateData.fileLabel.setFile(uri, {
204
+ fileDecorations: { colors: false, badges: true },
205
+ fileKind,
206
+ hidePath: this.viewMode() === "tree" ,
207
+ });
208
+ }
209
+ renderCompressedElements(node, index, templateData, height) {
210
+ const compressed = node.element;
211
+ const folder = compressed.elements[compressed.elements.length - 1];
212
+ const label = ( compressed.elements.map(e => e.name));
213
+ templateData.fileLabel.setResource({ resource: folder.uri, name: label }, {
214
+ fileDecorations: { colors: false, badges: true },
215
+ fileKind: FileKind.FOLDER,
216
+ separator: this.labelService.getSeparator(folder.uri.scheme)
217
+ });
218
+ }
219
+ disposeTemplate(templateData) {
220
+ templateData.disposables.dispose();
221
+ }
222
+ };
223
+ HistoryItemChangeRenderer = HistoryItemChangeRenderer_1 = ( __decorate([
224
+ ( __param(2, ILabelService))
225
+ ], HistoryItemChangeRenderer));
226
+ let SCMSyncViewPaneAccessibilityProvider = class SCMSyncViewPaneAccessibilityProvider {
227
+ constructor(labelService, workspaceContextService) {
228
+ this.labelService = labelService;
229
+ this.workspaceContextService = workspaceContextService;
230
+ }
231
+ getAriaLabel(element) {
232
+ if (isSCMRepository(element)) {
233
+ let folderName = '';
234
+ if (element.provider.rootUri) {
235
+ const folder = this.workspaceContextService.getWorkspaceFolder(element.provider.rootUri);
236
+ if (folder?.uri.toString() === ( element.provider.rootUri.toString())) {
237
+ folderName = folder.name;
238
+ }
239
+ else {
240
+ folderName = basename(element.provider.rootUri);
241
+ }
242
+ }
243
+ return `${folderName} ${element.provider.label}`;
244
+ }
245
+ else if (isSCMHistoryItemGroupTreeElement(element)) {
246
+ return `${stripIcons(element.label).trim()}${element.description ? `, ${element.description}` : ''}`;
247
+ }
248
+ else if (isSCMActionButton(element)) {
249
+ return element.button?.command.title ?? '';
250
+ }
251
+ else if (isSCMHistoryItemTreeElement(element)) {
252
+ return `${stripIcons(element.label).trim()}${element.description ? `, ${element.description}` : ''}`;
253
+ }
254
+ else if (isSCMHistoryItemChangeTreeElement(element)) {
255
+ const result = [basename(element.uri)];
256
+ const path = this.labelService.getUriLabel(dirname(element.uri), { relative: true, noPrefix: true });
257
+ if (path) {
258
+ result.push(path);
259
+ }
260
+ return result.join(', ');
261
+ }
262
+ return '';
263
+ }
264
+ getWidgetAriaLabel() {
265
+ return ( localizeWithPath(
266
+ 'vs/workbench/contrib/scm/browser/scmSyncViewPane',
267
+ 'scmSync',
268
+ 'Source Control Sync'
269
+ ));
270
+ }
271
+ };
272
+ SCMSyncViewPaneAccessibilityProvider = ( __decorate([
273
+ ( __param(0, ILabelService)),
274
+ ( __param(1, IWorkspaceContextService))
275
+ ], SCMSyncViewPaneAccessibilityProvider));
276
+ class SCMSyncViewPaneTreeIdentityProvider {
277
+ getId(element) {
278
+ return getSCMResourceId(element);
279
+ }
280
+ }
281
+ class SCMSyncViewPaneTreeSorter {
282
+ compare(element, otherElement) {
283
+ if (isSCMRepository(element)) {
284
+ if (!isSCMRepository(otherElement)) {
285
+ throw new Error('Invalid comparison');
286
+ }
287
+ return 0;
288
+ }
289
+ if (isSCMActionButton(element)) {
290
+ return -1;
291
+ }
292
+ else if (isSCMActionButton(otherElement)) {
293
+ return 1;
294
+ }
295
+ if (isSCMHistoryItemGroupTreeElement(element)) {
296
+ if (!isSCMHistoryItemGroupTreeElement(otherElement)) {
297
+ throw new Error('Invalid comparison');
298
+ }
299
+ return 0;
300
+ }
301
+ if (isSCMHistoryItemTreeElement(element)) {
302
+ if (!isSCMHistoryItemTreeElement(otherElement)) {
303
+ throw new Error('Invalid comparison');
304
+ }
305
+ return 0;
306
+ }
307
+ const elementPath = element.uri.fsPath;
308
+ const otherElementPath = otherElement.uri.fsPath;
309
+ return comparePaths(elementPath, otherElementPath);
310
+ }
311
+ }
312
+ let SCMSyncViewPane = class SCMSyncViewPane extends ViewPane {
313
+ get viewModel() { return this._viewModel; }
314
+ constructor(options, commandService, keybindingService, contextMenuService, instantiationService, viewDescriptorService, contextKeyService, configurationService, openerService, themeService, telemetryService) {
315
+ super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
316
+ this.commandService = commandService;
317
+ this.disposables = ( new DisposableStore());
318
+ }
319
+ renderBody(container) {
320
+ super.renderBody(container);
321
+ this.treeContainer = append(container, $('.scm-view.scm-sync-view'));
322
+ this.listLabels = this.instantiationService.createInstance(ResourceLabels, { onDidChangeVisibility: this.onDidChangeBodyVisibility });
323
+ this._register(this.listLabels);
324
+ this._tree = this.instantiationService.createInstance(WorkbenchCompressibleAsyncDataTree, 'SCM Sync View', this.treeContainer, ( new ListDelegate()), ( new CompressionDelegate()), [
325
+ this.instantiationService.createInstance(RepositoryRenderer, getActionViewItemProvider(this.instantiationService)),
326
+ this.instantiationService.createInstance(ActionButtonRenderer),
327
+ this.instantiationService.createInstance(HistoryItemGroupRenderer),
328
+ this.instantiationService.createInstance(HistoryItemRenderer),
329
+ this.instantiationService.createInstance(HistoryItemChangeRenderer, () => this.viewModel.mode, this.listLabels),
330
+ ], this.instantiationService.createInstance(SCMSyncDataSource, () => this.viewModel.mode), {
331
+ compressionEnabled: true,
332
+ horizontalScrolling: false,
333
+ autoExpandSingleChildren: true,
334
+ multipleSelectionSupport: false,
335
+ collapseByDefault: (e) => !ResourceTree.isResourceNode(e),
336
+ accessibilityProvider: this.instantiationService.createInstance(SCMSyncViewPaneAccessibilityProvider),
337
+ identityProvider: this.instantiationService.createInstance(SCMSyncViewPaneTreeIdentityProvider),
338
+ sorter: this.instantiationService.createInstance(SCMSyncViewPaneTreeSorter),
339
+ });
340
+ this._register(this._tree);
341
+ this._register(this._tree.onDidOpen(this.onDidOpen, this));
342
+ this._viewModel = this.instantiationService.createInstance(SCMSyncPaneViewModel, this._tree);
343
+ this.treeContainer.classList.add('file-icon-themable-tree');
344
+ this.treeContainer.classList.add('show-file-icons');
345
+ this.updateIndentStyles(this.themeService.getFileIconTheme());
346
+ this._register(this.themeService.onDidFileIconThemeChange(this.updateIndentStyles, this));
347
+ this._register(this._viewModel.onDidChangeMode(this.onDidChangeMode, this));
348
+ }
349
+ layoutBody(height, width) {
350
+ super.layoutBody(height, width);
351
+ this._tree.layout(height, width);
352
+ }
353
+ onDidChangeMode() {
354
+ this.updateIndentStyles(this.themeService.getFileIconTheme());
355
+ }
356
+ async onDidOpen(e) {
357
+ if (!e.element) {
358
+ return;
359
+ }
360
+ if (isSCMHistoryItemChangeTreeElement(e.element)) {
361
+ if (e.element.originalUri && e.element.modifiedUri) {
362
+ await this.commandService.executeCommand(API_OPEN_DIFF_EDITOR_COMMAND_ID, ...toDiffEditorArguments(e.element.uri, e.element.originalUri, e.element.modifiedUri), e);
363
+ }
364
+ }
365
+ else if (ResourceTree.isResourceNode(e.element) && e.element.childrenCount === 0) {
366
+ if (e.element.element?.originalUri && e.element.element?.modifiedUri) {
367
+ await this.commandService.executeCommand(API_OPEN_DIFF_EDITOR_COMMAND_ID, ...toDiffEditorArguments(e.element.element.uri, e.element.element.originalUri, e.element.element.modifiedUri), e);
368
+ }
369
+ }
370
+ }
371
+ updateIndentStyles(theme) {
372
+ this.treeContainer.classList.toggle('list-view-mode', this._viewModel.mode === "list" );
373
+ this.treeContainer.classList.toggle('tree-view-mode', this._viewModel.mode === "tree" );
374
+ this.treeContainer.classList.toggle('align-icons-and-twisties', (this._viewModel.mode === "list" && theme.hasFileIcons) || (theme.hasFileIcons && !theme.hasFolderIcons));
375
+ }
376
+ dispose() {
377
+ this.disposables.dispose();
378
+ super.dispose();
379
+ }
380
+ };
381
+ SCMSyncViewPane = ( __decorate([
382
+ ( __param(1, ICommandService)),
383
+ ( __param(2, IKeybindingService)),
384
+ ( __param(3, IContextMenuService)),
385
+ ( __param(4, IInstantiationService)),
386
+ ( __param(5, IViewDescriptorService)),
387
+ ( __param(6, IContextKeyService)),
388
+ ( __param(7, IConfigurationService)),
389
+ ( __param(8, IOpenerService)),
390
+ ( __param(9, IThemeService)),
391
+ ( __param(10, ITelemetryService))
392
+ ], SCMSyncViewPane));
393
+ let SCMSyncPaneViewModel = class SCMSyncPaneViewModel {
394
+ get mode() { return this._mode; }
395
+ set mode(mode) {
396
+ if (this._mode === mode) {
397
+ return;
398
+ }
399
+ this._mode = mode;
400
+ this.refresh();
401
+ this.modeContextKey.set(mode);
402
+ this._onDidChangeMode.fire(mode);
403
+ this.storageService.store(`scm.syncViewMode`, mode, 1 , 0 );
404
+ }
405
+ constructor(tree, contextKeyService, scmViewService, configurationService, storageService) {
406
+ this.tree = tree;
407
+ this.configurationService = configurationService;
408
+ this.storageService = storageService;
409
+ this._onDidChangeMode = ( new Emitter());
410
+ this.onDidChangeMode = this._onDidChangeMode.event;
411
+ this.repositories = ( new Map());
412
+ this.historyProviders = ( new Map());
413
+ this.alwaysShowRepositories = false;
414
+ this.disposables = ( new DisposableStore());
415
+ configurationService.onDidChangeConfiguration(this._onDidChangeConfiguration, this, this.disposables);
416
+ this._onDidChangeConfiguration();
417
+ scmViewService.onDidChangeVisibleRepositories(this._onDidChangeVisibleRepositories, this, this.disposables);
418
+ this._onDidChangeVisibleRepositories({ added: scmViewService.visibleRepositories, removed: [] });
419
+ this._mode = this.getViewMode();
420
+ this.modeContextKey = ContextKeys.ViewMode.bindTo(contextKeyService);
421
+ this.modeContextKey.set(this._mode);
422
+ }
423
+ _onDidChangeConfiguration(e) {
424
+ if (!e || e.affectsConfiguration('scm.alwaysShowRepositories')) {
425
+ this.alwaysShowRepositories = this.configurationService.getValue('scm.alwaysShowRepositories');
426
+ this.refresh();
427
+ }
428
+ }
429
+ _onDidChangeVisibleRepositories({ added, removed }) {
430
+ for (const repository of added) {
431
+ const repositoryDisposable = repository.provider.onDidChangeHistoryProvider(() => this._onDidChangeHistoryProvider(repository));
432
+ this._onDidChangeHistoryProvider(repository);
433
+ this.repositories.set(repository, repositoryDisposable);
434
+ }
435
+ for (const repository of removed) {
436
+ this.historyProviders.get(repository)?.dispose();
437
+ this.historyProviders.delete(repository);
438
+ this.repositories.get(repository)?.dispose();
439
+ this.repositories.delete(repository);
440
+ }
441
+ this.refresh();
442
+ }
443
+ _onDidChangeHistoryProvider(repository) {
444
+ if (repository.provider.historyProvider) {
445
+ const historyProviderDisposable = combinedDisposable(repository.provider.historyProvider.onDidChangeActionButton(() => this.refresh(repository)), repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => this.refresh(repository)));
446
+ this.historyProviders.set(repository, historyProviderDisposable);
447
+ }
448
+ else {
449
+ this.historyProviders.get(repository)?.dispose();
450
+ this.historyProviders.delete(repository);
451
+ }
452
+ }
453
+ getViewMode() {
454
+ let mode = this.configurationService.getValue('scm.defaultViewMode') === 'list' ? "list" : "tree" ;
455
+ const storageMode = this.storageService.get(`scm.syncViewMode`, 1 );
456
+ if (typeof storageMode === 'string') {
457
+ mode = storageMode;
458
+ }
459
+ return mode;
460
+ }
461
+ async refresh(repository) {
462
+ if (this.repositories.size === 0) {
463
+ return;
464
+ }
465
+ if (repository) {
466
+ await this.tree.updateChildren(repository);
467
+ }
468
+ else if (this.repositories.size === 1 && !this.alwaysShowRepositories) {
469
+ await this.tree.setInput(Iterable.first(( this.repositories.keys())));
470
+ }
471
+ else {
472
+ const expanded = ( Array.from(( this.repositories.keys()))
473
+ .map(repository => `repo:${repository.provider.id}`));
474
+ await this.tree.setInput([...( this.repositories.keys())], { expanded });
475
+ }
476
+ }
477
+ };
478
+ SCMSyncPaneViewModel = ( __decorate([
479
+ ( __param(1, IContextKeyService)),
480
+ ( __param(2, ISCMViewService)),
481
+ ( __param(3, IConfigurationService)),
482
+ ( __param(4, IStorageService))
483
+ ], SCMSyncPaneViewModel));
484
+ let SCMSyncDataSource = class SCMSyncDataSource {
485
+ constructor(viewMode, uriIdentityService) {
486
+ this.viewMode = viewMode;
487
+ this.uriIdentityService = uriIdentityService;
488
+ }
489
+ hasChildren(element) {
490
+ if (isSCMRepositoryArray(element)) {
491
+ return true;
492
+ }
493
+ else if (isSCMRepository(element)) {
494
+ return true;
495
+ }
496
+ else if (isSCMActionButton(element)) {
497
+ return false;
498
+ }
499
+ else if (isSCMHistoryItemGroupTreeElement(element)) {
500
+ return true;
501
+ }
502
+ else if (isSCMHistoryItemTreeElement(element)) {
503
+ return true;
504
+ }
505
+ else if (isSCMHistoryItemChangeTreeElement(element)) {
506
+ return false;
507
+ }
508
+ else if (ResourceTree.isResourceNode(element)) {
509
+ return element.childrenCount > 0;
510
+ }
511
+ else {
512
+ throw new Error('hasChildren not implemented.');
513
+ }
514
+ }
515
+ async getChildren(element) {
516
+ const children = [];
517
+ if (isSCMRepositoryArray(element)) {
518
+ children.push(...element);
519
+ }
520
+ else if (isSCMRepository(element)) {
521
+ const scmProvider = element.provider;
522
+ const historyProvider = scmProvider.historyProvider;
523
+ const historyItemGroup = historyProvider?.currentHistoryItemGroup;
524
+ if (!historyProvider || !historyItemGroup) {
525
+ return [];
526
+ }
527
+ const actionButton = historyProvider.actionButton;
528
+ if (actionButton) {
529
+ children.push({
530
+ type: 'actionButton',
531
+ repository: element,
532
+ button: actionButton
533
+ });
534
+ }
535
+ children.push(...(await this.getHistoryItemGroups(element)));
536
+ }
537
+ else if (isSCMHistoryItemGroupTreeElement(element)) {
538
+ children.push(...(await this.getHistoryItems(element)));
539
+ }
540
+ else if (isSCMHistoryItemTreeElement(element)) {
541
+ children.push(...(await this.getHistoryItemChanges(element)));
542
+ }
543
+ else if (ResourceTree.isResourceNode(element)) {
544
+ children.push(...element.children);
545
+ }
546
+ else {
547
+ throw new Error('getChildren Method not implemented.');
548
+ }
549
+ return children;
550
+ }
551
+ async getHistoryItemGroups(element) {
552
+ const scmProvider = element.provider;
553
+ const historyProvider = scmProvider.historyProvider;
554
+ const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup;
555
+ if (!historyProvider || !currentHistoryItemGroup) {
556
+ return [];
557
+ }
558
+ const historyItemGroupBase = await historyProvider.resolveHistoryItemGroupBase(currentHistoryItemGroup.id);
559
+ if (!historyItemGroupBase) {
560
+ return [];
561
+ }
562
+ const ancestor = await historyProvider.resolveHistoryItemGroupCommonAncestor(currentHistoryItemGroup.id, historyItemGroupBase.id);
563
+ const children = [];
564
+ if (historyItemGroupBase) {
565
+ children.push({
566
+ id: historyItemGroupBase.id,
567
+ label: `$(cloud-download) ${historyItemGroupBase.label}`,
568
+ description: ( localizeWithPath(
569
+ 'vs/workbench/contrib/scm/browser/scmSyncViewPane',
570
+ 'incoming',
571
+ "Incoming Changes"
572
+ )),
573
+ ancestor: ancestor?.id,
574
+ count: ancestor?.behind ?? 0,
575
+ repository: element,
576
+ type: 'historyItemGroup'
577
+ });
578
+ }
579
+ children.push({
580
+ id: currentHistoryItemGroup.id,
581
+ label: `$(cloud-upload) ${currentHistoryItemGroup.label}`,
582
+ description: ( localizeWithPath(
583
+ 'vs/workbench/contrib/scm/browser/scmSyncViewPane',
584
+ 'outgoing',
585
+ "Outgoing Changes"
586
+ )),
587
+ ancestor: ancestor?.id,
588
+ count: ancestor?.ahead ?? 0,
589
+ repository: element,
590
+ type: 'historyItemGroup'
591
+ });
592
+ return children;
593
+ }
594
+ async getHistoryItems(element) {
595
+ const scmProvider = element.repository.provider;
596
+ const historyProvider = scmProvider.historyProvider;
597
+ if (!historyProvider) {
598
+ return [];
599
+ }
600
+ const historyItems = (await historyProvider.provideHistoryItems(element.id, { limit: { id: element.ancestor } })) ?? [];
601
+ return ( historyItems.map(historyItem => ({
602
+ id: historyItem.id,
603
+ label: historyItem.label,
604
+ description: historyItem.description,
605
+ icon: historyItem.icon,
606
+ historyItemGroup: element,
607
+ type: 'historyItem'
608
+ })));
609
+ }
610
+ async getHistoryItemChanges(element) {
611
+ const repository = element.historyItemGroup.repository;
612
+ const historyProvider = repository.provider.historyProvider;
613
+ if (!historyProvider) {
614
+ return [];
615
+ }
616
+ const changes = (await historyProvider.provideHistoryItemChanges(element.id)) ?? [];
617
+ if (this.viewMode() === "list" ) {
618
+ return ( changes.map(change => ({
619
+ uri: change.uri,
620
+ originalUri: change.originalUri,
621
+ modifiedUri: change.modifiedUri,
622
+ renameUri: change.renameUri,
623
+ historyItem: element,
624
+ type: 'historyItemChange'
625
+ })));
626
+ }
627
+ const tree = ( new ResourceTree(
628
+ element,
629
+ repository.provider.rootUri ?? URI.file('/'),
630
+ this.uriIdentityService.extUri
631
+ ));
632
+ for (const change of changes) {
633
+ tree.add(change.uri, {
634
+ uri: change.uri,
635
+ originalUri: change.originalUri,
636
+ modifiedUri: change.modifiedUri,
637
+ renameUri: change.renameUri,
638
+ historyItem: element,
639
+ type: 'historyItemChange'
640
+ });
641
+ }
642
+ return [...tree.root.children];
643
+ }
644
+ };
645
+ SCMSyncDataSource = ( __decorate([
646
+ ( __param(1, IUriIdentityService))
647
+ ], SCMSyncDataSource));
648
+ class RefreshAction extends ViewAction {
649
+ constructor() {
650
+ super({
651
+ id: 'workbench.scm.sync.action.refresh',
652
+ title: ( localizeWithPath('vs/workbench/contrib/scm/browser/scmSyncViewPane', 'refresh', "Refresh")),
653
+ viewId: SYNC_VIEW_PANE_ID,
654
+ f1: false,
655
+ icon: Codicon.refresh,
656
+ menu: {
657
+ id: MenuId.ViewTitle,
658
+ when: ( ContextKeyExpr.equals('view', SYNC_VIEW_PANE_ID)),
659
+ group: 'navigation'
660
+ }
661
+ });
662
+ }
663
+ async runInView(_, view) {
664
+ view.viewModel.refresh();
665
+ }
666
+ }
667
+ class SetListViewModeAction extends ViewAction {
668
+ constructor() {
669
+ super({
670
+ id: 'workbench.scm.sync.action.setListViewMode',
671
+ title: ( localizeWithPath(
672
+ 'vs/workbench/contrib/scm/browser/scmSyncViewPane',
673
+ 'setListViewMode',
674
+ "View as List"
675
+ )),
676
+ viewId: SYNC_VIEW_PANE_ID,
677
+ f1: false,
678
+ icon: Codicon.listTree,
679
+ toggled: ( ContextKeys.ViewMode.isEqualTo("list" )),
680
+ menu: {
681
+ id: MenuId.ViewTitle,
682
+ when: ( ContextKeyExpr.equals('view', SYNC_VIEW_PANE_ID)),
683
+ group: '1_viewmode'
684
+ }
685
+ });
686
+ }
687
+ async runInView(_, view) {
688
+ view.viewModel.mode = "list" ;
689
+ }
690
+ }
691
+ class SetTreeViewModeAction extends ViewAction {
692
+ constructor() {
693
+ super({
694
+ id: 'workbench.scm.sync.action.setTreeViewMode',
695
+ title: ( localizeWithPath(
696
+ 'vs/workbench/contrib/scm/browser/scmSyncViewPane',
697
+ 'setTreeViewMode',
698
+ "View as Tree"
699
+ )),
700
+ viewId: SYNC_VIEW_PANE_ID,
701
+ f1: false,
702
+ icon: Codicon.listFlat,
703
+ toggled: ( ContextKeys.ViewMode.isEqualTo("tree" )),
704
+ menu: {
705
+ id: MenuId.ViewTitle,
706
+ when: ( ContextKeyExpr.equals('view', SYNC_VIEW_PANE_ID)),
707
+ group: '1_viewmode'
708
+ }
709
+ });
710
+ }
711
+ async runInView(_, view) {
712
+ view.viewModel.mode = "tree" ;
713
+ }
714
+ }
715
+ registerAction2(RefreshAction);
716
+ registerAction2(SetListViewModeAction);
717
+ registerAction2(SetTreeViewModeAction);
718
+
719
+ export { SCMSyncViewPane };