@codingame/monaco-vscode-bulk-edit-service-override 1.85.0 → 1.85.1

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