@codingame/monaco-vscode-bulk-edit-service-override 3.2.3 → 4.1.0

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.
@@ -1,334 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../../external/tslib/tslib.es6.js';
2
- import './bulkEdit.css.js';
3
- import { WorkbenchAsyncDataTree } from 'vscode/vscode/vs/platform/list/browser/listService';
4
- import { BulkEditDataSource, BulkEditDelegate, TextEditElementRenderer, FileElementRenderer, CategoryElementRenderer, BulkEditAccessibilityProvider, BulkEditIdentityProvider, BulkEditNaviLabelProvider, BulkEditSorter, FileElement, CategoryElement, TextEditElement, compareBulkFileOperations } from './bulkEditTree.js';
5
- import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
6
- import { IThemeService } from 'vscode/vscode/vs/platform/theme/common/themeService';
7
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
8
- import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
9
- import { SIDE_GROUP, ACTIVE_GROUP, IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
10
- import { BulkFileOperations, BulkEditPreviewProvider } from './bulkEditPreview.js';
11
- import { ILabelService } from 'vscode/vscode/vs/platform/label/common/label';
12
- import { ITextModelService } from 'vscode/vscode/vs/editor/common/services/resolverService';
13
- import { URI } from 'vscode/vscode/vs/base/common/uri';
14
- import { ViewPane } from 'vscode/vscode/vs/workbench/browser/parts/views/viewPane';
15
- import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
16
- import { IContextMenuService } from 'vscode/vscode/vs/platform/contextview/browser/contextView';
17
- import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
18
- import { RawContextKey, IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
19
- import { ResourceLabels } from 'vscode/vscode/vs/workbench/browser/labels';
20
- import '../../../../../../../../override/vs/platform/dialogs/common/dialogs.js';
21
- import { MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
22
- import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage';
23
- import { IViewDescriptorService } from 'vscode/vscode/vs/workbench/common/views';
24
- import { IOpenerService } from 'vscode/vscode/vs/platform/opener/common/opener';
25
- import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
26
- import { ButtonBar } from 'vscode/vscode/vs/base/browser/ui/button/button';
27
- import { defaultButtonStyles } from 'vscode/vscode/vs/platform/theme/browser/defaultStyles';
28
- import { IDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
29
-
30
- var BulkEditPane_1;
31
- let BulkEditPane = class BulkEditPane extends ViewPane {
32
- static { BulkEditPane_1 = this; }
33
- static { this.ID = 'refactorPreview'; }
34
- static { this.Schema = 'vscode-bulkeditpreview-multieditor'; }
35
- static { this.ctxHasCategories = ( new RawContextKey('refactorPreview.hasCategories', false)); }
36
- static { this.ctxGroupByFile = ( new RawContextKey('refactorPreview.groupByFile', true)); }
37
- static { this.ctxHasCheckedChanges = ( new RawContextKey('refactorPreview.hasCheckedChanges', true)); }
38
- static { this._memGroupByFile = `${BulkEditPane_1.ID}.groupByFile`; }
39
- constructor(options, _instaService, _editorService, _labelService, _textModelService, _dialogService, _contextMenuService, _storageService, contextKeyService, viewDescriptorService, keybindingService, contextMenuService, configurationService, openerService, themeService, telemetryService) {
40
- super({ ...options, titleMenuId: MenuId.BulkEditTitle }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, _instaService, openerService, themeService, telemetryService);
41
- this._instaService = _instaService;
42
- this._editorService = _editorService;
43
- this._labelService = _labelService;
44
- this._textModelService = _textModelService;
45
- this._dialogService = _dialogService;
46
- this._contextMenuService = _contextMenuService;
47
- this._storageService = _storageService;
48
- this._treeViewStates = ( new Map());
49
- this._disposables = ( new DisposableStore());
50
- this._sessionDisposables = ( new DisposableStore());
51
- this.element.classList.add('bulk-edit-panel', 'show-file-icons');
52
- this._ctxHasCategories = BulkEditPane_1.ctxHasCategories.bindTo(contextKeyService);
53
- this._ctxGroupByFile = BulkEditPane_1.ctxGroupByFile.bindTo(contextKeyService);
54
- this._ctxHasCheckedChanges = BulkEditPane_1.ctxHasCheckedChanges.bindTo(contextKeyService);
55
- }
56
- dispose() {
57
- this._tree.dispose();
58
- this._disposables.dispose();
59
- super.dispose();
60
- }
61
- renderBody(parent) {
62
- super.renderBody(parent);
63
- const resourceLabels = this._instaService.createInstance(ResourceLabels, { onDidChangeVisibility: this.onDidChangeBodyVisibility });
64
- this._disposables.add(resourceLabels);
65
- const contentContainer = document.createElement('div');
66
- contentContainer.className = 'content';
67
- parent.appendChild(contentContainer);
68
- const treeContainer = document.createElement('div');
69
- contentContainer.appendChild(treeContainer);
70
- this._treeDataSource = this._instaService.createInstance(BulkEditDataSource);
71
- this._treeDataSource.groupByFile = this._storageService.getBoolean(BulkEditPane_1._memGroupByFile, 0 , true);
72
- this._ctxGroupByFile.set(this._treeDataSource.groupByFile);
73
- this._tree = this._instaService.createInstance(WorkbenchAsyncDataTree, this.id, treeContainer, ( new BulkEditDelegate()), [this._instaService.createInstance(TextEditElementRenderer), this._instaService.createInstance(FileElementRenderer, resourceLabels), this._instaService.createInstance(CategoryElementRenderer)], this._treeDataSource, {
74
- accessibilityProvider: this._instaService.createInstance(BulkEditAccessibilityProvider),
75
- identityProvider: ( new BulkEditIdentityProvider()),
76
- expandOnlyOnTwistieClick: true,
77
- multipleSelectionSupport: false,
78
- keyboardNavigationLabelProvider: ( new BulkEditNaviLabelProvider()),
79
- sorter: ( new BulkEditSorter()),
80
- selectionNavigation: true
81
- });
82
- this._disposables.add(this._tree.onContextMenu(this._onContextMenu, this));
83
- this._disposables.add(this._tree.onDidOpen(e => this._openElementInMultiDiffEditor(e)));
84
- const buttonsContainer = document.createElement('div');
85
- buttonsContainer.className = 'buttons';
86
- contentContainer.appendChild(buttonsContainer);
87
- const buttonBar = ( new ButtonBar(buttonsContainer));
88
- this._disposables.add(buttonBar);
89
- const btnConfirm = buttonBar.addButton({ supportIcons: true, ...defaultButtonStyles });
90
- btnConfirm.label = ( localizeWithPath(
91
- 'vs/workbench/contrib/bulkEdit/browser/preview/bulkEditPane',
92
- 'ok',
93
- 'Apply'
94
- ));
95
- btnConfirm.onDidClick(() => this.accept(), this, this._disposables);
96
- const btnCancel = buttonBar.addButton({ ...defaultButtonStyles, secondary: true });
97
- btnCancel.label = ( localizeWithPath(
98
- 'vs/workbench/contrib/bulkEdit/browser/preview/bulkEditPane',
99
- 'cancel',
100
- 'Discard'
101
- ));
102
- btnCancel.onDidClick(() => this.discard(), this, this._disposables);
103
- this._message = document.createElement('span');
104
- this._message.className = 'message';
105
- this._message.innerText = ( localizeWithPath(
106
- 'vs/workbench/contrib/bulkEdit/browser/preview/bulkEditPane',
107
- 'empty.msg',
108
- "Invoke a code action, like rename, to see a preview of its changes here."
109
- ));
110
- parent.appendChild(this._message);
111
- this._setState("message" );
112
- }
113
- layoutBody(height, width) {
114
- super.layoutBody(height, width);
115
- const treeHeight = height - 50;
116
- this._tree.getHTMLElement().parentElement.style.height = `${treeHeight}px`;
117
- this._tree.layout(treeHeight, width);
118
- }
119
- _setState(state) {
120
- this.element.dataset['state'] = state;
121
- }
122
- async setInput(edit, token) {
123
- this._setState("data" );
124
- this._sessionDisposables.clear();
125
- this._treeViewStates.clear();
126
- if (this._currentResolve) {
127
- this._currentResolve(undefined);
128
- this._currentResolve = undefined;
129
- }
130
- const input = await this._instaService.invokeFunction(BulkFileOperations.create, edit);
131
- this._currentProvider = this._instaService.createInstance(BulkEditPreviewProvider, input);
132
- this._sessionDisposables.add(this._currentProvider);
133
- this._sessionDisposables.add(input);
134
- const hasCategories = input.categories.length > 1;
135
- this._ctxHasCategories.set(hasCategories);
136
- this._treeDataSource.groupByFile = !hasCategories || this._treeDataSource.groupByFile;
137
- this._ctxHasCheckedChanges.set(input.checked.checkedCount > 0);
138
- this._currentInput = input;
139
- return ( new Promise(resolve => {
140
- token.onCancellationRequested(() => resolve(undefined));
141
- this._currentResolve = resolve;
142
- this._setTreeInput(input);
143
- this._sessionDisposables.add(input.checked.onDidChange(() => {
144
- this._tree.updateChildren();
145
- this._ctxHasCheckedChanges.set(input.checked.checkedCount > 0);
146
- }));
147
- }));
148
- }
149
- hasInput() {
150
- return Boolean(this._currentInput);
151
- }
152
- async _setTreeInput(input) {
153
- const viewState = this._treeViewStates.get(this._treeDataSource.groupByFile);
154
- await this._tree.setInput(input, viewState);
155
- this._tree.domFocus();
156
- if (viewState) {
157
- return;
158
- }
159
- const expand = [...this._tree.getNode(input).children].slice(0, 10);
160
- while (expand.length > 0) {
161
- const { element } = expand.shift();
162
- if (element instanceof FileElement) {
163
- await this._tree.expand(element, true);
164
- }
165
- if (element instanceof CategoryElement) {
166
- await this._tree.expand(element, true);
167
- expand.push(...this._tree.getNode(element).children);
168
- }
169
- }
170
- }
171
- accept() {
172
- const conflicts = this._currentInput?.conflicts.list();
173
- if (!conflicts || conflicts.length === 0) {
174
- this._done(true);
175
- return;
176
- }
177
- let message;
178
- if (conflicts.length === 1) {
179
- message = ( localizeWithPath(
180
- 'vs/workbench/contrib/bulkEdit/browser/preview/bulkEditPane',
181
- 'conflict.1',
182
- "Cannot apply refactoring because '{0}' has changed in the meantime.",
183
- this._labelService.getUriLabel(conflicts[0], { relative: true })
184
- ));
185
- }
186
- else {
187
- message = ( localizeWithPath(
188
- 'vs/workbench/contrib/bulkEdit/browser/preview/bulkEditPane',
189
- 'conflict.N',
190
- "Cannot apply refactoring because {0} other files have changed in the meantime.",
191
- conflicts.length
192
- ));
193
- }
194
- this._dialogService.warn(message).finally(() => this._done(false));
195
- }
196
- discard() {
197
- this._done(false);
198
- }
199
- _done(accept) {
200
- this._currentResolve?.(accept ? this._currentInput?.getWorkspaceEdit() : undefined);
201
- this._currentInput = undefined;
202
- this._setState("message" );
203
- this._sessionDisposables.clear();
204
- }
205
- toggleChecked() {
206
- const [first] = this._tree.getFocus();
207
- if ((first instanceof FileElement || first instanceof TextEditElement) && !first.isDisabled()) {
208
- first.setChecked(!first.isChecked());
209
- }
210
- else if (first instanceof CategoryElement) {
211
- first.setChecked(!first.isChecked());
212
- }
213
- }
214
- groupByFile() {
215
- if (!this._treeDataSource.groupByFile) {
216
- this.toggleGrouping();
217
- }
218
- }
219
- groupByType() {
220
- if (this._treeDataSource.groupByFile) {
221
- this.toggleGrouping();
222
- }
223
- }
224
- toggleGrouping() {
225
- const input = this._tree.getInput();
226
- if (input) {
227
- const oldViewState = this._tree.getViewState();
228
- this._treeViewStates.set(this._treeDataSource.groupByFile, oldViewState);
229
- this._treeDataSource.groupByFile = !this._treeDataSource.groupByFile;
230
- this._setTreeInput(input);
231
- this._storageService.store(BulkEditPane_1._memGroupByFile, this._treeDataSource.groupByFile, 0 , 0 );
232
- this._ctxGroupByFile.set(this._treeDataSource.groupByFile);
233
- }
234
- }
235
- async _openElementInMultiDiffEditor(e) {
236
- const fileOperations = this._currentInput?.fileOperations;
237
- if (!fileOperations) {
238
- return;
239
- }
240
- let selection = undefined;
241
- let fileElement;
242
- if (e.element instanceof TextEditElement) {
243
- fileElement = e.element.parent;
244
- selection = e.element.edit.textEdit.textEdit.range;
245
- }
246
- else if (e.element instanceof FileElement) {
247
- fileElement = e.element;
248
- selection = e.element.edit.textEdits[0]?.textEdit.textEdit.range;
249
- }
250
- else {
251
- return;
252
- }
253
- const resources = await this._resolveResources(fileOperations);
254
- const options = {
255
- ...e.editorOptions,
256
- viewState: {
257
- revealData: {
258
- resource: { original: fileElement.edit.uri },
259
- range: selection,
260
- }
261
- }
262
- };
263
- const multiDiffSource = ( URI.from({ scheme: BulkEditPane_1.Schema }));
264
- const label = 'Refactor Preview';
265
- this._editorService.openEditor({
266
- multiDiffSource,
267
- resources,
268
- label,
269
- options,
270
- isTransient: true,
271
- description: label
272
- }, e.sideBySide ? SIDE_GROUP : ACTIVE_GROUP);
273
- }
274
- async _resolveResources(fileOperations) {
275
- if (this._fileOperations === fileOperations && this._resources) {
276
- return this._resources;
277
- }
278
- const sortedFileOperations = fileOperations.sort(compareBulkFileOperations);
279
- const resources = [];
280
- for (const operation of sortedFileOperations) {
281
- const operationUri = operation.uri;
282
- const previewUri = this._currentProvider.asPreviewUri(operationUri);
283
- if (operation.type & 4 ) {
284
- resources.push({
285
- original: { resource: undefined },
286
- modified: { resource: URI.revive(previewUri) }
287
- });
288
- }
289
- else {
290
- let leftResource;
291
- try {
292
- (await this._textModelService.createModelReference(operationUri)).dispose();
293
- leftResource = operationUri;
294
- }
295
- catch {
296
- leftResource = BulkEditPreviewProvider.emptyPreview;
297
- }
298
- resources.push({
299
- original: { resource: URI.revive(leftResource) },
300
- modified: { resource: URI.revive(previewUri) }
301
- });
302
- }
303
- }
304
- this._fileOperations = fileOperations;
305
- this._resources = resources;
306
- return resources;
307
- }
308
- _onContextMenu(e) {
309
- this._contextMenuService.showContextMenu({
310
- menuId: MenuId.BulkEditContext,
311
- contextKeyService: this.contextKeyService,
312
- getAnchor: () => e.anchor
313
- });
314
- }
315
- };
316
- BulkEditPane = BulkEditPane_1 = ( __decorate([
317
- ( __param(1, IInstantiationService)),
318
- ( __param(2, IEditorService)),
319
- ( __param(3, ILabelService)),
320
- ( __param(4, ITextModelService)),
321
- ( __param(5, IDialogService)),
322
- ( __param(6, IContextMenuService)),
323
- ( __param(7, IStorageService)),
324
- ( __param(8, IContextKeyService)),
325
- ( __param(9, IViewDescriptorService)),
326
- ( __param(10, IKeybindingService)),
327
- ( __param(11, IContextMenuService)),
328
- ( __param(12, IConfigurationService)),
329
- ( __param(13, IOpenerService)),
330
- ( __param(14, IThemeService)),
331
- ( __param(15, ITelemetryService))
332
- ], BulkEditPane));
333
-
334
- export { BulkEditPane };