@theia/filesystem 1.53.0-next.4 → 1.53.0-next.55

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 (102) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/file-resource.d.ts +2 -0
  3. package/lib/browser/file-resource.d.ts.map +1 -1
  4. package/lib/browser/file-resource.js +11 -0
  5. package/lib/browser/file-resource.js.map +1 -1
  6. package/lib/browser/file-resource.spec.d.ts +2 -0
  7. package/lib/browser/file-resource.spec.d.ts.map +1 -0
  8. package/lib/browser/file-resource.spec.js +191 -0
  9. package/lib/browser/file-resource.spec.js.map +1 -0
  10. package/lib/browser/file-service.d.ts +1 -0
  11. package/lib/browser/file-service.d.ts.map +1 -1
  12. package/lib/browser/file-service.js +3 -0
  13. package/lib/browser/file-service.js.map +1 -1
  14. package/package.json +4 -4
  15. package/src/browser/breadcrumbs/filepath-breadcrumb.ts +43 -43
  16. package/src/browser/breadcrumbs/filepath-breadcrumbs-container.ts +65 -65
  17. package/src/browser/breadcrumbs/filepath-breadcrumbs-contribution.ts +129 -129
  18. package/src/browser/download/file-download-command-contribution.ts +83 -83
  19. package/src/browser/download/file-download-frontend-module.ts +25 -25
  20. package/src/browser/download/file-download-service.ts +179 -179
  21. package/src/browser/file-dialog/file-dialog-container.ts +67 -67
  22. package/src/browser/file-dialog/file-dialog-hidden-files-renderer.tsx +59 -59
  23. package/src/browser/file-dialog/file-dialog-model.ts +96 -96
  24. package/src/browser/file-dialog/file-dialog-module.ts +44 -44
  25. package/src/browser/file-dialog/file-dialog-service.ts +99 -99
  26. package/src/browser/file-dialog/file-dialog-tree-filters-renderer.tsx +100 -100
  27. package/src/browser/file-dialog/file-dialog-tree.ts +89 -89
  28. package/src/browser/file-dialog/file-dialog-widget.ts +75 -75
  29. package/src/browser/file-dialog/file-dialog.ts +434 -434
  30. package/src/browser/file-dialog/index.ts +20 -20
  31. package/src/browser/file-resource.spec.ts +255 -0
  32. package/src/browser/file-resource.ts +402 -390
  33. package/src/browser/file-selection.ts +44 -44
  34. package/src/browser/file-service.ts +1845 -1841
  35. package/src/browser/file-tree/file-tree-container.ts +36 -36
  36. package/src/browser/file-tree/file-tree-decorator-adapter.ts +159 -159
  37. package/src/browser/file-tree/file-tree-label-provider.ts +53 -53
  38. package/src/browser/file-tree/file-tree-model.ts +212 -212
  39. package/src/browser/file-tree/file-tree-widget.tsx +327 -327
  40. package/src/browser/file-tree/file-tree.ts +183 -183
  41. package/src/browser/file-tree/index.ts +22 -22
  42. package/src/browser/file-upload-service.ts +547 -547
  43. package/src/browser/filesystem-frontend-contribution.ts +396 -396
  44. package/src/browser/filesystem-frontend-module.ts +77 -77
  45. package/src/browser/filesystem-preferences.ts +139 -139
  46. package/src/browser/filesystem-saveable-service.ts +138 -138
  47. package/src/browser/filesystem-watcher-error-handler.ts +60 -60
  48. package/src/browser/index.ts +21 -21
  49. package/src/browser/location/index.ts +18 -18
  50. package/src/browser/location/location-renderer.tsx +406 -406
  51. package/src/browser/location/location-service.ts +22 -22
  52. package/src/browser/remote-file-service-contribution.ts +38 -38
  53. package/src/browser/style/file-dialog.css +208 -208
  54. package/src/browser/style/file-icons.css +64 -64
  55. package/src/browser/style/filepath-breadcrumbs.css +20 -20
  56. package/src/browser/style/index.css +36 -36
  57. package/src/browser-only/browser-only-filesystem-frontend-module.ts +38 -38
  58. package/src/browser-only/browser-only-filesystem-provider-server.ts +32 -32
  59. package/src/browser-only/browserfs-filesystem-initialization.ts +61 -61
  60. package/src/browser-only/browserfs-filesystem-provider.ts +462 -462
  61. package/src/common/delegating-file-system-provider.ts +226 -226
  62. package/src/common/download/README.md +30 -30
  63. package/src/common/download/file-download-data.ts +27 -27
  64. package/src/common/file-upload.ts +17 -17
  65. package/src/common/files.spec.ts +51 -51
  66. package/src/common/files.ts +997 -997
  67. package/src/common/filesystem-utils.spec.ts +411 -411
  68. package/src/common/filesystem-utils.ts +64 -64
  69. package/src/common/filesystem-watcher-protocol.ts +96 -96
  70. package/src/common/filesystem.ts +43 -43
  71. package/src/common/index.ts +18 -18
  72. package/src/common/io.ts +150 -150
  73. package/src/common/remote-file-system-provider.ts +549 -549
  74. package/src/electron-browser/file-dialog/electron-file-dialog-module.ts +24 -24
  75. package/src/electron-browser/file-dialog/electron-file-dialog-service.ts +165 -165
  76. package/src/electron-browser/preload.ts +31 -31
  77. package/src/electron-common/electron-api.ts +55 -55
  78. package/src/electron-main/electron-api-main.ts +78 -78
  79. package/src/electron-main/electron-main-module.ts +23 -23
  80. package/src/node/disk-file-system-provider.spec.ts +142 -142
  81. package/src/node/disk-file-system-provider.ts +915 -915
  82. package/src/node/download/directory-archiver.spec.ts +104 -104
  83. package/src/node/download/directory-archiver.ts +126 -126
  84. package/src/node/download/file-download-backend-module.ts +32 -32
  85. package/src/node/download/file-download-cache.ts +88 -88
  86. package/src/node/download/file-download-endpoint.ts +63 -63
  87. package/src/node/download/file-download-handler.ts +304 -304
  88. package/src/node/download/test/mock-directory-archiver.ts +30 -30
  89. package/src/node/file-change-collection.spec.ts +110 -110
  90. package/src/node/file-change-collection.ts +78 -78
  91. package/src/node/filesystem-backend-module.ts +140 -140
  92. package/src/node/filesystem-watcher-client.ts +72 -72
  93. package/src/node/filesystem-watcher-dispatcher.ts +82 -82
  94. package/src/node/node-file-upload-service.ts +80 -80
  95. package/src/node/nsfw-watcher/index.ts +45 -45
  96. package/src/node/nsfw-watcher/nsfw-filesystem-service.ts +481 -481
  97. package/src/node/nsfw-watcher/nsfw-filesystem-watcher.spec.ts +182 -182
  98. package/src/node/nsfw-watcher/nsfw-options.ts +23 -23
  99. package/src/typings/dom.webkit.d.ts +77 -77
  100. package/src/typings/mv/index.d.ts +21 -21
  101. package/src/typings/nsfw/index.d.ts +18 -18
  102. package/src/typings/trash/index.d.ts +20 -20
@@ -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, postConstruct } from '@theia/core/shared/inversify';
18
- import URI from '@theia/core/lib/common/uri';
19
- import { CompositeTreeNode, TreeNode, ConfirmDialog, CompressedTreeModel, Dialog } from '@theia/core/lib/browser';
20
- import { FileStatNode, DirNode, FileNode } from './file-tree';
21
- import { LocationService } from '../location';
22
- import { LabelProvider } from '@theia/core/lib/browser/label-provider';
23
- import { FileService } from '../file-service';
24
- import { FileOperationError, FileOperationResult, FileChangesEvent, FileChangeType, FileChange, FileOperation, FileOperationEvent } from '../../common/files';
25
- import { MessageService } from '@theia/core/lib/common/message-service';
26
- import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
27
- import { FileSystemUtils } from '../../common';
28
- import { nls } from '@theia/core';
29
-
30
- @injectable()
31
- export class FileTreeModel extends CompressedTreeModel implements LocationService {
32
-
33
- @inject(LabelProvider) protected readonly labelProvider: LabelProvider;
34
-
35
- @inject(FileService)
36
- protected readonly fileService: FileService;
37
-
38
- @inject(MessageService)
39
- protected readonly messageService: MessageService;
40
-
41
- @inject(EnvVariablesServer)
42
- protected readonly environments: EnvVariablesServer;
43
-
44
- @postConstruct()
45
- protected override init(): void {
46
- super.init();
47
- this.toDispose.push(this.fileService.onDidFilesChange(changes => this.onFilesChanged(changes)));
48
- this.toDispose.push(this.fileService.onDidRunOperation(event => this.onDidMove(event)));
49
- }
50
-
51
- get location(): URI | undefined {
52
- const root = this.root;
53
- if (FileStatNode.is(root)) {
54
- return root.uri;
55
- }
56
- return undefined;
57
- }
58
-
59
- set location(uri: URI | undefined) {
60
- if (uri) {
61
- this.fileService.resolve(uri).then(fileStat => {
62
- if (fileStat) {
63
- const node = DirNode.createRoot(fileStat);
64
- this.navigateTo(node);
65
- }
66
- }).catch(() => {
67
- // no-op, allow failures for file dialog text input
68
- });
69
- } else {
70
- this.navigateTo(undefined);
71
- }
72
- }
73
-
74
- async drives(): Promise<URI[]> {
75
- try {
76
- const drives = await this.environments.getDrives();
77
- return drives.map(uri => new URI(uri));
78
- } catch (e) {
79
- this.logger.error('Error when loading drives.', e);
80
- return [];
81
- }
82
- }
83
-
84
- get selectedFileStatNodes(): Readonly<FileStatNode>[] {
85
- return this.selectedNodes.filter(FileStatNode.is);
86
- }
87
-
88
- *getNodesByUri(uri: URI): IterableIterator<TreeNode> {
89
- const node = this.getNode(uri.toString());
90
- if (node) {
91
- yield node;
92
- }
93
- }
94
-
95
- /**
96
- * to workaround https://github.com/Axosoft/nsfw/issues/42
97
- */
98
- protected onDidMove(event: FileOperationEvent): void {
99
- if (!event.isOperation(FileOperation.MOVE)) {
100
- return;
101
- }
102
- if (event.resource.parent.toString() === event.target.resource.parent.toString()) {
103
- // file rename
104
- return;
105
- }
106
- this.refreshAffectedNodes([
107
- event.resource,
108
- event.target.resource
109
- ]);
110
- }
111
-
112
- protected onFilesChanged(changes: FileChangesEvent): void {
113
- if (!this.refreshAffectedNodes(this.getAffectedUris(changes)) && this.isRootAffected(changes)) {
114
- this.refresh();
115
- }
116
- }
117
-
118
- protected isRootAffected(changes: FileChangesEvent): boolean {
119
- const root = this.root;
120
- if (FileStatNode.is(root)) {
121
- return changes.contains(root.uri, FileChangeType.ADDED) || changes.contains(root.uri, FileChangeType.UPDATED);
122
- }
123
- return false;
124
- }
125
-
126
- protected getAffectedUris(changes: FileChangesEvent): URI[] {
127
- return changes.changes.filter(change => !this.isFileContentChanged(change)).map(change => change.resource);
128
- }
129
-
130
- protected isFileContentChanged(change: FileChange): boolean {
131
- return change.type === FileChangeType.UPDATED && FileNode.is(this.getNodesByUri(change.resource).next().value);
132
- }
133
-
134
- protected refreshAffectedNodes(uris: URI[]): boolean {
135
- const nodes = this.getAffectedNodes(uris);
136
- for (const node of nodes.values()) {
137
- this.refresh(node);
138
- }
139
- return nodes.size !== 0;
140
- }
141
-
142
- protected getAffectedNodes(uris: URI[]): Map<string, CompositeTreeNode> {
143
- const nodes = new Map<string, CompositeTreeNode>();
144
- for (const uri of uris) {
145
- for (const node of this.getNodesByUri(uri.parent)) {
146
- if (DirNode.is(node) && (node.expanded || (this.compressionToggle.compress && this.compressionService.isCompressionParticipant(node)))) {
147
- nodes.set(node.id, node);
148
- }
149
- }
150
- }
151
- return nodes;
152
- }
153
-
154
- async copy(source: URI, target: Readonly<FileStatNode>): Promise<URI> {
155
- /** If the target is a file or if the target is a directory, but is the same as the source, use the parent of the target as a destination. */
156
- const parentNode = (target.fileStat.isFile || target.uri.isEqual(source)) ? target.parent : target;
157
- if (!FileStatNode.is(parentNode)) {
158
- throw new Error('Parent of file has to be a FileStatNode');
159
- }
160
- let targetUri = parentNode.uri.resolve(source.path.base);
161
- try {
162
- const parent = await this.fileService.resolve(parentNode.uri);
163
- const sourceFileStat = await this.fileService.resolve(source);
164
- targetUri = FileSystemUtils.generateUniqueResourceURI(parent, targetUri, sourceFileStat.isDirectory, 'copy');
165
- await this.fileService.copy(source, targetUri);
166
- } catch (e) {
167
- this.messageService.error(e.message);
168
- }
169
- return targetUri;
170
- }
171
-
172
- /**
173
- * Move the given source file or directory to the given target directory.
174
- */
175
- async move(source: TreeNode, target: TreeNode): Promise<URI | undefined> {
176
- if (DirNode.is(target) && FileStatNode.is(source)) {
177
- const name = source.fileStat.name;
178
- const targetUri = target.uri.resolve(name);
179
- if (source.uri.isEqual(targetUri)) { return; }
180
- try {
181
- await this.fileService.move(source.uri, targetUri);
182
- return targetUri;
183
- } catch (e) {
184
- if (e instanceof FileOperationError && e.fileOperationResult === FileOperationResult.FILE_MOVE_CONFLICT) {
185
- const fileName = this.labelProvider.getName(source);
186
- if (await this.shouldReplace(fileName)) {
187
- try {
188
- await this.fileService.move(source.uri, targetUri, { overwrite: true });
189
- return targetUri;
190
- } catch (e2) {
191
- this.messageService.error(e2.message);
192
- }
193
- }
194
- } else {
195
- this.messageService.error(e.message);
196
- }
197
- }
198
- }
199
- return undefined;
200
- }
201
-
202
- protected async shouldReplace(fileName: string): Promise<boolean> {
203
- const dialog = new ConfirmDialog({
204
- title: nls.localize('theia/filesystem/replaceTitle', 'Replace File'),
205
- msg: nls.localizeByDefault('{0} already exists. Are you sure you want to overwrite it?', fileName),
206
- ok: Dialog.YES,
207
- cancel: Dialog.NO
208
- });
209
- return !!await dialog.open();
210
- }
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, postConstruct } from '@theia/core/shared/inversify';
18
+ import URI from '@theia/core/lib/common/uri';
19
+ import { CompositeTreeNode, TreeNode, ConfirmDialog, CompressedTreeModel, Dialog } from '@theia/core/lib/browser';
20
+ import { FileStatNode, DirNode, FileNode } from './file-tree';
21
+ import { LocationService } from '../location';
22
+ import { LabelProvider } from '@theia/core/lib/browser/label-provider';
23
+ import { FileService } from '../file-service';
24
+ import { FileOperationError, FileOperationResult, FileChangesEvent, FileChangeType, FileChange, FileOperation, FileOperationEvent } from '../../common/files';
25
+ import { MessageService } from '@theia/core/lib/common/message-service';
26
+ import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
27
+ import { FileSystemUtils } from '../../common';
28
+ import { nls } from '@theia/core';
29
+
30
+ @injectable()
31
+ export class FileTreeModel extends CompressedTreeModel implements LocationService {
32
+
33
+ @inject(LabelProvider) protected readonly labelProvider: LabelProvider;
34
+
35
+ @inject(FileService)
36
+ protected readonly fileService: FileService;
37
+
38
+ @inject(MessageService)
39
+ protected readonly messageService: MessageService;
40
+
41
+ @inject(EnvVariablesServer)
42
+ protected readonly environments: EnvVariablesServer;
43
+
44
+ @postConstruct()
45
+ protected override init(): void {
46
+ super.init();
47
+ this.toDispose.push(this.fileService.onDidFilesChange(changes => this.onFilesChanged(changes)));
48
+ this.toDispose.push(this.fileService.onDidRunOperation(event => this.onDidMove(event)));
49
+ }
50
+
51
+ get location(): URI | undefined {
52
+ const root = this.root;
53
+ if (FileStatNode.is(root)) {
54
+ return root.uri;
55
+ }
56
+ return undefined;
57
+ }
58
+
59
+ set location(uri: URI | undefined) {
60
+ if (uri) {
61
+ this.fileService.resolve(uri).then(fileStat => {
62
+ if (fileStat) {
63
+ const node = DirNode.createRoot(fileStat);
64
+ this.navigateTo(node);
65
+ }
66
+ }).catch(() => {
67
+ // no-op, allow failures for file dialog text input
68
+ });
69
+ } else {
70
+ this.navigateTo(undefined);
71
+ }
72
+ }
73
+
74
+ async drives(): Promise<URI[]> {
75
+ try {
76
+ const drives = await this.environments.getDrives();
77
+ return drives.map(uri => new URI(uri));
78
+ } catch (e) {
79
+ this.logger.error('Error when loading drives.', e);
80
+ return [];
81
+ }
82
+ }
83
+
84
+ get selectedFileStatNodes(): Readonly<FileStatNode>[] {
85
+ return this.selectedNodes.filter(FileStatNode.is);
86
+ }
87
+
88
+ *getNodesByUri(uri: URI): IterableIterator<TreeNode> {
89
+ const node = this.getNode(uri.toString());
90
+ if (node) {
91
+ yield node;
92
+ }
93
+ }
94
+
95
+ /**
96
+ * to workaround https://github.com/Axosoft/nsfw/issues/42
97
+ */
98
+ protected onDidMove(event: FileOperationEvent): void {
99
+ if (!event.isOperation(FileOperation.MOVE)) {
100
+ return;
101
+ }
102
+ if (event.resource.parent.toString() === event.target.resource.parent.toString()) {
103
+ // file rename
104
+ return;
105
+ }
106
+ this.refreshAffectedNodes([
107
+ event.resource,
108
+ event.target.resource
109
+ ]);
110
+ }
111
+
112
+ protected onFilesChanged(changes: FileChangesEvent): void {
113
+ if (!this.refreshAffectedNodes(this.getAffectedUris(changes)) && this.isRootAffected(changes)) {
114
+ this.refresh();
115
+ }
116
+ }
117
+
118
+ protected isRootAffected(changes: FileChangesEvent): boolean {
119
+ const root = this.root;
120
+ if (FileStatNode.is(root)) {
121
+ return changes.contains(root.uri, FileChangeType.ADDED) || changes.contains(root.uri, FileChangeType.UPDATED);
122
+ }
123
+ return false;
124
+ }
125
+
126
+ protected getAffectedUris(changes: FileChangesEvent): URI[] {
127
+ return changes.changes.filter(change => !this.isFileContentChanged(change)).map(change => change.resource);
128
+ }
129
+
130
+ protected isFileContentChanged(change: FileChange): boolean {
131
+ return change.type === FileChangeType.UPDATED && FileNode.is(this.getNodesByUri(change.resource).next().value);
132
+ }
133
+
134
+ protected refreshAffectedNodes(uris: URI[]): boolean {
135
+ const nodes = this.getAffectedNodes(uris);
136
+ for (const node of nodes.values()) {
137
+ this.refresh(node);
138
+ }
139
+ return nodes.size !== 0;
140
+ }
141
+
142
+ protected getAffectedNodes(uris: URI[]): Map<string, CompositeTreeNode> {
143
+ const nodes = new Map<string, CompositeTreeNode>();
144
+ for (const uri of uris) {
145
+ for (const node of this.getNodesByUri(uri.parent)) {
146
+ if (DirNode.is(node) && (node.expanded || (this.compressionToggle.compress && this.compressionService.isCompressionParticipant(node)))) {
147
+ nodes.set(node.id, node);
148
+ }
149
+ }
150
+ }
151
+ return nodes;
152
+ }
153
+
154
+ async copy(source: URI, target: Readonly<FileStatNode>): Promise<URI> {
155
+ /** If the target is a file or if the target is a directory, but is the same as the source, use the parent of the target as a destination. */
156
+ const parentNode = (target.fileStat.isFile || target.uri.isEqual(source)) ? target.parent : target;
157
+ if (!FileStatNode.is(parentNode)) {
158
+ throw new Error('Parent of file has to be a FileStatNode');
159
+ }
160
+ let targetUri = parentNode.uri.resolve(source.path.base);
161
+ try {
162
+ const parent = await this.fileService.resolve(parentNode.uri);
163
+ const sourceFileStat = await this.fileService.resolve(source);
164
+ targetUri = FileSystemUtils.generateUniqueResourceURI(parent, targetUri, sourceFileStat.isDirectory, 'copy');
165
+ await this.fileService.copy(source, targetUri);
166
+ } catch (e) {
167
+ this.messageService.error(e.message);
168
+ }
169
+ return targetUri;
170
+ }
171
+
172
+ /**
173
+ * Move the given source file or directory to the given target directory.
174
+ */
175
+ async move(source: TreeNode, target: TreeNode): Promise<URI | undefined> {
176
+ if (DirNode.is(target) && FileStatNode.is(source)) {
177
+ const name = source.fileStat.name;
178
+ const targetUri = target.uri.resolve(name);
179
+ if (source.uri.isEqual(targetUri)) { return; }
180
+ try {
181
+ await this.fileService.move(source.uri, targetUri);
182
+ return targetUri;
183
+ } catch (e) {
184
+ if (e instanceof FileOperationError && e.fileOperationResult === FileOperationResult.FILE_MOVE_CONFLICT) {
185
+ const fileName = this.labelProvider.getName(source);
186
+ if (await this.shouldReplace(fileName)) {
187
+ try {
188
+ await this.fileService.move(source.uri, targetUri, { overwrite: true });
189
+ return targetUri;
190
+ } catch (e2) {
191
+ this.messageService.error(e2.message);
192
+ }
193
+ }
194
+ } else {
195
+ this.messageService.error(e.message);
196
+ }
197
+ }
198
+ }
199
+ return undefined;
200
+ }
201
+
202
+ protected async shouldReplace(fileName: string): Promise<boolean> {
203
+ const dialog = new ConfirmDialog({
204
+ title: nls.localize('theia/filesystem/replaceTitle', 'Replace File'),
205
+ msg: nls.localizeByDefault('{0} already exists. Are you sure you want to overwrite it?', fileName),
206
+ ok: Dialog.YES,
207
+ cancel: Dialog.NO
208
+ });
209
+ return !!await dialog.open();
210
+ }
211
+
212
+ }