@theia/workspace 1.45.1 → 1.46.0-next.72

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 (118) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/canonical-uri-service.d.ts +11 -11
  3. package/lib/browser/canonical-uri-service.js +59 -59
  4. package/lib/browser/diff-service.d.ts +10 -10
  5. package/lib/browser/diff-service.js +85 -85
  6. package/lib/browser/index.d.ts +7 -7
  7. package/lib/browser/index.js +34 -34
  8. package/lib/browser/quick-open-workspace.d.ts +25 -25
  9. package/lib/browser/quick-open-workspace.js +137 -137
  10. package/lib/browser/untitled-workspace-exit-dialog.d.ts +19 -19
  11. package/lib/browser/untitled-workspace-exit-dialog.js +74 -74
  12. package/lib/browser/workspace-breadcrumbs-contribution.d.ts +10 -10
  13. package/lib/browser/workspace-breadcrumbs-contribution.js +66 -66
  14. package/lib/browser/workspace-commands.d.ts +117 -117
  15. package/lib/browser/workspace-commands.js +601 -601
  16. package/lib/browser/workspace-commands.spec.d.ts +1 -1
  17. package/lib/browser/workspace-commands.spec.js +127 -127
  18. package/lib/browser/workspace-compare-handler.d.ts +26 -26
  19. package/lib/browser/workspace-compare-handler.js +66 -66
  20. package/lib/browser/workspace-delete-handler.d.ts +75 -75
  21. package/lib/browser/workspace-delete-handler.js +214 -214
  22. package/lib/browser/workspace-duplicate-handler.d.ts +30 -30
  23. package/lib/browser/workspace-duplicate-handler.js +86 -86
  24. package/lib/browser/workspace-frontend-contribution.d.ts +110 -110
  25. package/lib/browser/workspace-frontend-contribution.js +546 -546
  26. package/lib/browser/workspace-frontend-contribution.js.map +1 -1
  27. package/lib/browser/workspace-frontend-module.d.ts +3 -3
  28. package/lib/browser/workspace-frontend-module.js +91 -91
  29. package/lib/browser/workspace-input-dialog.d.ts +19 -19
  30. package/lib/browser/workspace-input-dialog.js +74 -74
  31. package/lib/browser/workspace-preferences.d.ts +11 -11
  32. package/lib/browser/workspace-preferences.js +46 -46
  33. package/lib/browser/workspace-schema-updater.d.ts +34 -34
  34. package/lib/browser/workspace-schema-updater.js +153 -153
  35. package/lib/browser/workspace-service.d.ts +184 -184
  36. package/lib/browser/workspace-service.js +739 -739
  37. package/lib/browser/workspace-storage-service.d.ts +15 -15
  38. package/lib/browser/workspace-storage-service.js +80 -80
  39. package/lib/browser/workspace-trust-preferences.d.ts +21 -21
  40. package/lib/browser/workspace-trust-preferences.js +65 -65
  41. package/lib/browser/workspace-trust-service.d.ts +27 -27
  42. package/lib/browser/workspace-trust-service.js +152 -152
  43. package/lib/browser/workspace-uri-contribution.d.ts +20 -20
  44. package/lib/browser/workspace-uri-contribution.js +113 -113
  45. package/lib/browser/workspace-uri-contribution.spec.d.ts +1 -1
  46. package/lib/browser/workspace-uri-contribution.spec.js +169 -169
  47. package/lib/browser/workspace-user-working-directory-provider.d.ts +12 -12
  48. package/lib/browser/workspace-user-working-directory-provider.js +62 -62
  49. package/lib/browser/workspace-utils.d.ts +15 -15
  50. package/lib/browser/workspace-utils.js +54 -54
  51. package/lib/browser/workspace-variable-contribution.d.ts +23 -23
  52. package/lib/browser/workspace-variable-contribution.js +237 -237
  53. package/lib/browser/workspace-window-title-updater.d.ts +7 -7
  54. package/lib/browser/workspace-window-title-updater.js +57 -57
  55. package/lib/browser-only/browser-only-workspace-server.d.ts +13 -0
  56. package/lib/browser-only/browser-only-workspace-server.d.ts.map +1 -0
  57. package/lib/browser-only/browser-only-workspace-server.js +81 -0
  58. package/lib/browser-only/browser-only-workspace-server.js.map +1 -0
  59. package/lib/browser-only/workspace-frontend-only-module.d.ts +4 -0
  60. package/lib/browser-only/workspace-frontend-only-module.d.ts.map +1 -0
  61. package/lib/browser-only/workspace-frontend-only-module.js +30 -0
  62. package/lib/browser-only/workspace-frontend-only-module.js.map +1 -0
  63. package/lib/common/index.d.ts +3 -3
  64. package/lib/common/index.js +30 -30
  65. package/lib/common/test/mock-workspace-server.d.ts +7 -7
  66. package/lib/common/test/mock-workspace-server.js +35 -35
  67. package/lib/common/untitled-workspace-service.d.ts +8 -8
  68. package/lib/common/untitled-workspace-service.js +60 -60
  69. package/lib/common/workspace-file-service.d.ts +26 -26
  70. package/lib/common/workspace-file-service.js +71 -71
  71. package/lib/common/workspace-protocol.d.ts +26 -26
  72. package/lib/common/workspace-protocol.js +23 -23
  73. package/lib/node/default-workspace-server.d.ts +65 -65
  74. package/lib/node/default-workspace-server.js +248 -248
  75. package/lib/node/default-workspace-server.spec.d.ts +1 -1
  76. package/lib/node/default-workspace-server.spec.js +85 -85
  77. package/lib/node/index.d.ts +2 -2
  78. package/lib/node/index.js +29 -29
  79. package/lib/node/workspace-backend-module.d.ts +3 -3
  80. package/lib/node/workspace-backend-module.js +33 -33
  81. package/package.json +9 -6
  82. package/src/browser/canonical-uri-service.ts +57 -57
  83. package/src/browser/diff-service.ts +62 -62
  84. package/src/browser/index.ts +23 -23
  85. package/src/browser/quick-open-workspace.ts +112 -112
  86. package/src/browser/untitled-workspace-exit-dialog.ts +70 -70
  87. package/src/browser/workspace-breadcrumbs-contribution.ts +56 -56
  88. package/src/browser/workspace-commands.spec.ts +153 -153
  89. package/src/browser/workspace-commands.ts +588 -588
  90. package/src/browser/workspace-compare-handler.ts +56 -56
  91. package/src/browser/workspace-delete-handler.ts +212 -212
  92. package/src/browser/workspace-duplicate-handler.ts +75 -75
  93. package/src/browser/workspace-frontend-contribution.ts +537 -537
  94. package/src/browser/workspace-frontend-module.ts +118 -118
  95. package/src/browser/workspace-input-dialog.ts +61 -61
  96. package/src/browser/workspace-preferences.ts +58 -58
  97. package/src/browser/workspace-schema-updater.ts +150 -150
  98. package/src/browser/workspace-service.ts +780 -780
  99. package/src/browser/workspace-storage-service.ts +67 -67
  100. package/src/browser/workspace-trust-preferences.ts +76 -76
  101. package/src/browser/workspace-trust-service.ts +147 -147
  102. package/src/browser/workspace-uri-contribution.spec.ts +191 -191
  103. package/src/browser/workspace-uri-contribution.ts +97 -97
  104. package/src/browser/workspace-user-working-directory-provider.ts +49 -49
  105. package/src/browser/workspace-utils.ts +45 -45
  106. package/src/browser/workspace-variable-contribution.ts +222 -222
  107. package/src/browser/workspace-window-title-updater.ts +45 -45
  108. package/src/browser-only/browser-only-workspace-server.ts +69 -0
  109. package/src/browser-only/workspace-frontend-only-module.ts +28 -0
  110. package/src/common/index.ts +19 -19
  111. package/src/common/test/mock-workspace-server.ts +29 -29
  112. package/src/common/untitled-workspace-service.ts +50 -50
  113. package/src/common/workspace-file-service.ts +72 -72
  114. package/src/common/workspace-protocol.ts +47 -47
  115. package/src/node/default-workspace-server.spec.ts +100 -100
  116. package/src/node/default-workspace-server.ts +244 -244
  117. package/src/node/index.ts +18 -18
  118. package/src/node/workspace-backend-module.ts +38 -38
@@ -1,56 +1,56 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 Red Hat, Inc. and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { inject, injectable } from '@theia/core/shared/inversify';
18
- import URI from '@theia/core/lib/common/uri';
19
- import { UriCommandHandler } from '@theia/core/lib/common/uri-command-handler';
20
- import { DiffService } from './diff-service';
21
-
22
- @injectable()
23
- export class WorkspaceCompareHandler implements UriCommandHandler<URI[]> {
24
-
25
- @inject(DiffService) protected readonly diffService: DiffService;
26
-
27
- /**
28
- * Determine if the command is visible.
29
- *
30
- * @param uris URIs of selected resources.
31
- * @returns `true` if the command is visible.
32
- */
33
- isVisible(uris: URI[]): boolean {
34
- return uris.length === 2;
35
- }
36
-
37
- /**
38
- * Determine if the command is enabled.
39
- *
40
- * @param uris URIs of selected resources.
41
- * @returns `true` if the command is enabled.
42
- */
43
- isEnabled(uris: URI[]): boolean {
44
- return uris.length === 2;
45
- }
46
-
47
- /**
48
- * Execute the command.
49
- *
50
- * @param uris URIs of selected resources.
51
- */
52
- async execute(uris: URI[]): Promise<void> {
53
- const [left, right] = uris;
54
- await this.diffService.openDiffEditor(left, right);
55
- }
56
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 Red Hat, Inc. and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { inject, injectable } from '@theia/core/shared/inversify';
18
+ import URI from '@theia/core/lib/common/uri';
19
+ import { UriCommandHandler } from '@theia/core/lib/common/uri-command-handler';
20
+ import { DiffService } from './diff-service';
21
+
22
+ @injectable()
23
+ export class WorkspaceCompareHandler implements UriCommandHandler<URI[]> {
24
+
25
+ @inject(DiffService) protected readonly diffService: DiffService;
26
+
27
+ /**
28
+ * Determine if the command is visible.
29
+ *
30
+ * @param uris URIs of selected resources.
31
+ * @returns `true` if the command is visible.
32
+ */
33
+ isVisible(uris: URI[]): boolean {
34
+ return uris.length === 2;
35
+ }
36
+
37
+ /**
38
+ * Determine if the command is enabled.
39
+ *
40
+ * @param uris URIs of selected resources.
41
+ * @returns `true` if the command is enabled.
42
+ */
43
+ isEnabled(uris: URI[]): boolean {
44
+ return uris.length === 2;
45
+ }
46
+
47
+ /**
48
+ * Execute the command.
49
+ *
50
+ * @param uris URIs of selected resources.
51
+ */
52
+ async execute(uris: URI[]): Promise<void> {
53
+ const [left, right] = uris;
54
+ await this.diffService.openDiffEditor(left, right);
55
+ }
56
+ }
@@ -1,212 +1,212 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2017 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable, inject } from '@theia/core/shared/inversify';
18
- import URI from '@theia/core/lib/common/uri';
19
- import { ConfirmDialog, ApplicationShell, SaveableWidget, NavigatableWidget } from '@theia/core/lib/browser';
20
- import { UriCommandHandler } from '@theia/core/lib/common/uri-command-handler';
21
- import { WorkspaceService } from './workspace-service';
22
- import { WorkspaceUtils } from './workspace-utils';
23
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
24
- import { FileSystemPreferences } from '@theia/filesystem/lib/browser/filesystem-preferences';
25
- import { FileDeleteOptions, FileSystemProviderCapabilities } from '@theia/filesystem/lib/common/files';
26
- import { nls } from '@theia/core/lib/common/nls';
27
-
28
- @injectable()
29
- export class WorkspaceDeleteHandler implements UriCommandHandler<URI[]> {
30
-
31
- @inject(FileService)
32
- protected readonly fileService: FileService;
33
-
34
- @inject(ApplicationShell)
35
- protected readonly shell: ApplicationShell;
36
-
37
- @inject(WorkspaceUtils)
38
- protected readonly workspaceUtils: WorkspaceUtils;
39
-
40
- @inject(WorkspaceService)
41
- protected readonly workspaceService: WorkspaceService;
42
-
43
- @inject(FileSystemPreferences)
44
- protected readonly fsPreferences: FileSystemPreferences;
45
-
46
- /**
47
- * Determine if the command is visible.
48
- *
49
- * @param uris URIs of selected resources.
50
- * @returns `true` if the command is visible.
51
- */
52
- isVisible(uris: URI[]): boolean {
53
- return !!uris.length && !this.workspaceUtils.containsRootDirectory(uris);
54
- }
55
-
56
- /**
57
- * Determine if the command is enabled.
58
- *
59
- * @param uris URIs of selected resources.
60
- * @returns `true` if the command is enabled.
61
- */
62
- isEnabled(uris: URI[]): boolean {
63
- return !!uris.length && !this.workspaceUtils.containsRootDirectory(uris);
64
- }
65
-
66
- /**
67
- * Execute the command.
68
- *
69
- * @param uris URIs of selected resources.
70
- */
71
- async execute(uris: URI[]): Promise<void> {
72
- const distinctUris = URI.getDistinctParents(uris);
73
- const resolved: FileDeleteOptions = {
74
- recursive: true,
75
- useTrash: this.fsPreferences['files.enableTrash'] && distinctUris[0] && this.fileService.hasCapability(distinctUris[0], FileSystemProviderCapabilities.Trash)
76
- };
77
- if (await this.confirm(distinctUris, resolved)) {
78
- await Promise.all(distinctUris.map(uri => this.delete(uri, resolved)));
79
- }
80
- }
81
-
82
- /**
83
- * Display dialog to confirm deletion.
84
- *
85
- * @param uris URIs of selected resources.
86
- */
87
- protected confirm(uris: URI[], options: FileDeleteOptions): Promise<boolean | undefined> {
88
- let title = uris.length === 1 ? nls.localizeByDefault('File') : nls.localizeByDefault('Files');
89
- if (options.useTrash) {
90
- title = nls.localize('theia/workspace/trashTitle', 'Move {0} to Trash', title);
91
- } else {
92
- title = nls.localizeByDefault('Delete {0}', title);
93
- }
94
- return new ConfirmDialog({
95
- title,
96
- msg: this.getConfirmMessage(uris)
97
- }).open();
98
- }
99
-
100
- /**
101
- * Get the dialog confirmation message for deletion.
102
- *
103
- * @param uris URIs of selected resources.
104
- */
105
- protected getConfirmMessage(uris: URI[]): string | HTMLElement {
106
- const dirty = this.getDirty(uris);
107
- if (dirty.length) {
108
- if (dirty.length === 1) {
109
- return nls.localize('theia/workspace/confirmMessage.dirtySingle', 'Do you really want to delete {0} with unsaved changes?', dirty[0].path.base);
110
- }
111
- return nls.localize('theia/workspace/confirmMessage.dirtyMultiple', 'Do you really want to delete {0} files with unsaved changes?', dirty.length);
112
- }
113
- if (uris.length === 1) {
114
- return nls.localize('theia/workspace/confirmMessage.uriSingle', 'Do you really want to delete {0}?', uris[0].path.base);
115
- }
116
- if (uris.length > 10) {
117
- return nls.localize('theia/workspace/confirmMessage.uriMultiple', 'Do you really want to delete all the {0} selected files?', uris.length);
118
- }
119
- const messageContainer = document.createElement('div');
120
- messageContainer.textContent = nls.localize('theia/workspace/confirmMessage.delete', 'Do you really want to delete the following files?');
121
- const list = document.createElement('ul');
122
- list.style.listStyleType = 'none';
123
- for (const uri of uris) {
124
- const listItem = document.createElement('li');
125
- listItem.textContent = uri.path.base;
126
- list.appendChild(listItem);
127
- }
128
- messageContainer.appendChild(list);
129
- return messageContainer;
130
- }
131
-
132
- /**
133
- * Get which URI are presently dirty.
134
- *
135
- * @param uris URIs of selected resources.
136
- * @returns An array of dirty URI.
137
- */
138
- protected getDirty(uris: URI[]): URI[] {
139
- const dirty = new Map<string, URI>();
140
- const widgets = NavigatableWidget.getAffected(SaveableWidget.getDirty(this.shell.widgets), uris);
141
- for (const [resourceUri] of widgets) {
142
- dirty.set(resourceUri.toString(), resourceUri);
143
- }
144
- return [...dirty.values()];
145
- }
146
-
147
- /**
148
- * Perform deletion of a given URI.
149
- *
150
- * @param uri URI of selected resource.
151
- * @param options deletion options.
152
- */
153
- protected async delete(uri: URI, options: FileDeleteOptions): Promise<void> {
154
- try {
155
- await Promise.all([
156
- this.closeWithoutSaving(uri),
157
- options.useTrash ? this.moveFileToTrash(uri, options) : this.deleteFilePermanently(uri, options)
158
- ]);
159
- } catch (e) {
160
- console.error(e);
161
- }
162
- }
163
-
164
- protected async deleteFilePermanently(uri: URI, options: FileDeleteOptions): Promise<void> {
165
- this.fileService.delete(uri, { ...options, useTrash: false });
166
- }
167
-
168
- protected async moveFileToTrash(uri: URI, options: FileDeleteOptions): Promise<void> {
169
- try {
170
- await this.fileService.delete(uri, { ...options, useTrash: true });
171
- } catch (error) {
172
- console.error('Error deleting with trash:', error);
173
- if (await this.confirmDeletePermanently(uri)) {
174
- return this.deleteFilePermanently(uri, options);
175
- }
176
- }
177
- }
178
-
179
- /**
180
- * Display dialog to confirm the permanent deletion of a file.
181
- *
182
- * @param uri URI of selected resource.
183
- */
184
- protected async confirmDeletePermanently(uri: URI): Promise<boolean> {
185
- const title = nls.localize('theia/workspace/confirmDeletePermanently.title', 'Error deleting file');
186
-
187
- const msg = document.createElement('div');
188
-
189
- const question = document.createElement('p');
190
- question.textContent = nls.localize('theia/workspace/confirmDeletePermanently.description',
191
- 'Failed to delete "{0}" using the Trash. Do you want to permanently delete instead?',
192
- uri.path.base);
193
- msg.append(question);
194
-
195
- const info = document.createElement('p');
196
- info.textContent = nls.localize('theia/workspace/confirmDeletePermanently.solution', 'You can disable the use of Trash in the preferences.');
197
- msg.append(info);
198
-
199
- const response = await new ConfirmDialog({ title, msg }).open();
200
- return response || false;
201
- }
202
-
203
- /**
204
- * Close widget without saving changes.
205
- *
206
- * @param uri URI of a selected resource.
207
- */
208
- protected async closeWithoutSaving(uri: URI): Promise<void> {
209
- const toClose = [...NavigatableWidget.getAffected(this.shell.widgets, uri)].map(([, widget]) => widget);
210
- await this.shell.closeMany(toClose, { save: false });
211
- }
212
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2017 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable, inject } from '@theia/core/shared/inversify';
18
+ import URI from '@theia/core/lib/common/uri';
19
+ import { ConfirmDialog, ApplicationShell, SaveableWidget, NavigatableWidget } from '@theia/core/lib/browser';
20
+ import { UriCommandHandler } from '@theia/core/lib/common/uri-command-handler';
21
+ import { WorkspaceService } from './workspace-service';
22
+ import { WorkspaceUtils } from './workspace-utils';
23
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
24
+ import { FileSystemPreferences } from '@theia/filesystem/lib/browser/filesystem-preferences';
25
+ import { FileDeleteOptions, FileSystemProviderCapabilities } from '@theia/filesystem/lib/common/files';
26
+ import { nls } from '@theia/core/lib/common/nls';
27
+
28
+ @injectable()
29
+ export class WorkspaceDeleteHandler implements UriCommandHandler<URI[]> {
30
+
31
+ @inject(FileService)
32
+ protected readonly fileService: FileService;
33
+
34
+ @inject(ApplicationShell)
35
+ protected readonly shell: ApplicationShell;
36
+
37
+ @inject(WorkspaceUtils)
38
+ protected readonly workspaceUtils: WorkspaceUtils;
39
+
40
+ @inject(WorkspaceService)
41
+ protected readonly workspaceService: WorkspaceService;
42
+
43
+ @inject(FileSystemPreferences)
44
+ protected readonly fsPreferences: FileSystemPreferences;
45
+
46
+ /**
47
+ * Determine if the command is visible.
48
+ *
49
+ * @param uris URIs of selected resources.
50
+ * @returns `true` if the command is visible.
51
+ */
52
+ isVisible(uris: URI[]): boolean {
53
+ return !!uris.length && !this.workspaceUtils.containsRootDirectory(uris);
54
+ }
55
+
56
+ /**
57
+ * Determine if the command is enabled.
58
+ *
59
+ * @param uris URIs of selected resources.
60
+ * @returns `true` if the command is enabled.
61
+ */
62
+ isEnabled(uris: URI[]): boolean {
63
+ return !!uris.length && !this.workspaceUtils.containsRootDirectory(uris);
64
+ }
65
+
66
+ /**
67
+ * Execute the command.
68
+ *
69
+ * @param uris URIs of selected resources.
70
+ */
71
+ async execute(uris: URI[]): Promise<void> {
72
+ const distinctUris = URI.getDistinctParents(uris);
73
+ const resolved: FileDeleteOptions = {
74
+ recursive: true,
75
+ useTrash: this.fsPreferences['files.enableTrash'] && distinctUris[0] && this.fileService.hasCapability(distinctUris[0], FileSystemProviderCapabilities.Trash)
76
+ };
77
+ if (await this.confirm(distinctUris, resolved)) {
78
+ await Promise.all(distinctUris.map(uri => this.delete(uri, resolved)));
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Display dialog to confirm deletion.
84
+ *
85
+ * @param uris URIs of selected resources.
86
+ */
87
+ protected confirm(uris: URI[], options: FileDeleteOptions): Promise<boolean | undefined> {
88
+ let title = uris.length === 1 ? nls.localizeByDefault('File') : nls.localizeByDefault('Files');
89
+ if (options.useTrash) {
90
+ title = nls.localize('theia/workspace/trashTitle', 'Move {0} to Trash', title);
91
+ } else {
92
+ title = nls.localizeByDefault('Delete {0}', title);
93
+ }
94
+ return new ConfirmDialog({
95
+ title,
96
+ msg: this.getConfirmMessage(uris)
97
+ }).open();
98
+ }
99
+
100
+ /**
101
+ * Get the dialog confirmation message for deletion.
102
+ *
103
+ * @param uris URIs of selected resources.
104
+ */
105
+ protected getConfirmMessage(uris: URI[]): string | HTMLElement {
106
+ const dirty = this.getDirty(uris);
107
+ if (dirty.length) {
108
+ if (dirty.length === 1) {
109
+ return nls.localize('theia/workspace/confirmMessage.dirtySingle', 'Do you really want to delete {0} with unsaved changes?', dirty[0].path.base);
110
+ }
111
+ return nls.localize('theia/workspace/confirmMessage.dirtyMultiple', 'Do you really want to delete {0} files with unsaved changes?', dirty.length);
112
+ }
113
+ if (uris.length === 1) {
114
+ return nls.localize('theia/workspace/confirmMessage.uriSingle', 'Do you really want to delete {0}?', uris[0].path.base);
115
+ }
116
+ if (uris.length > 10) {
117
+ return nls.localize('theia/workspace/confirmMessage.uriMultiple', 'Do you really want to delete all the {0} selected files?', uris.length);
118
+ }
119
+ const messageContainer = document.createElement('div');
120
+ messageContainer.textContent = nls.localize('theia/workspace/confirmMessage.delete', 'Do you really want to delete the following files?');
121
+ const list = document.createElement('ul');
122
+ list.style.listStyleType = 'none';
123
+ for (const uri of uris) {
124
+ const listItem = document.createElement('li');
125
+ listItem.textContent = uri.path.base;
126
+ list.appendChild(listItem);
127
+ }
128
+ messageContainer.appendChild(list);
129
+ return messageContainer;
130
+ }
131
+
132
+ /**
133
+ * Get which URI are presently dirty.
134
+ *
135
+ * @param uris URIs of selected resources.
136
+ * @returns An array of dirty URI.
137
+ */
138
+ protected getDirty(uris: URI[]): URI[] {
139
+ const dirty = new Map<string, URI>();
140
+ const widgets = NavigatableWidget.getAffected(SaveableWidget.getDirty(this.shell.widgets), uris);
141
+ for (const [resourceUri] of widgets) {
142
+ dirty.set(resourceUri.toString(), resourceUri);
143
+ }
144
+ return [...dirty.values()];
145
+ }
146
+
147
+ /**
148
+ * Perform deletion of a given URI.
149
+ *
150
+ * @param uri URI of selected resource.
151
+ * @param options deletion options.
152
+ */
153
+ protected async delete(uri: URI, options: FileDeleteOptions): Promise<void> {
154
+ try {
155
+ await Promise.all([
156
+ this.closeWithoutSaving(uri),
157
+ options.useTrash ? this.moveFileToTrash(uri, options) : this.deleteFilePermanently(uri, options)
158
+ ]);
159
+ } catch (e) {
160
+ console.error(e);
161
+ }
162
+ }
163
+
164
+ protected async deleteFilePermanently(uri: URI, options: FileDeleteOptions): Promise<void> {
165
+ this.fileService.delete(uri, { ...options, useTrash: false });
166
+ }
167
+
168
+ protected async moveFileToTrash(uri: URI, options: FileDeleteOptions): Promise<void> {
169
+ try {
170
+ await this.fileService.delete(uri, { ...options, useTrash: true });
171
+ } catch (error) {
172
+ console.error('Error deleting with trash:', error);
173
+ if (await this.confirmDeletePermanently(uri)) {
174
+ return this.deleteFilePermanently(uri, options);
175
+ }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Display dialog to confirm the permanent deletion of a file.
181
+ *
182
+ * @param uri URI of selected resource.
183
+ */
184
+ protected async confirmDeletePermanently(uri: URI): Promise<boolean> {
185
+ const title = nls.localize('theia/workspace/confirmDeletePermanently.title', 'Error deleting file');
186
+
187
+ const msg = document.createElement('div');
188
+
189
+ const question = document.createElement('p');
190
+ question.textContent = nls.localize('theia/workspace/confirmDeletePermanently.description',
191
+ 'Failed to delete "{0}" using the Trash. Do you want to permanently delete instead?',
192
+ uri.path.base);
193
+ msg.append(question);
194
+
195
+ const info = document.createElement('p');
196
+ info.textContent = nls.localize('theia/workspace/confirmDeletePermanently.solution', 'You can disable the use of Trash in the preferences.');
197
+ msg.append(info);
198
+
199
+ const response = await new ConfirmDialog({ title, msg }).open();
200
+ return response || false;
201
+ }
202
+
203
+ /**
204
+ * Close widget without saving changes.
205
+ *
206
+ * @param uri URI of a selected resource.
207
+ */
208
+ protected async closeWithoutSaving(uri: URI): Promise<void> {
209
+ const toClose = [...NavigatableWidget.getAffected(this.shell.widgets, uri)].map(([, widget]) => widget);
210
+ await this.shell.closeMany(toClose, { save: false });
211
+ }
212
+ }