@theia/filesystem 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.
- package/README.md +30 -30
- package/lib/browser/breadcrumbs/filepath-breadcrumb.d.ts +15 -15
- package/lib/browser/breadcrumbs/filepath-breadcrumb.js +41 -41
- package/lib/browser/breadcrumbs/filepath-breadcrumbs-container.d.ts +13 -13
- package/lib/browser/breadcrumbs/filepath-breadcrumbs-container.js +81 -81
- package/lib/browser/breadcrumbs/filepath-breadcrumbs-contribution.d.ts +27 -27
- package/lib/browser/breadcrumbs/filepath-breadcrumbs-contribution.js +126 -126
- package/lib/browser/download/file-download-command-contribution.d.ts +18 -18
- package/lib/browser/download/file-download-command-contribution.js +83 -83
- package/lib/browser/download/file-download-frontend-module.d.ts +3 -3
- package/lib/browser/download/file-download-frontend-module.js +25 -25
- package/lib/browser/download/file-download-service.d.ts +28 -28
- package/lib/browser/download/file-download-service.js +175 -175
- package/lib/browser/file-dialog/file-dialog-container.d.ts +5 -5
- package/lib/browser/file-dialog/file-dialog-container.js +60 -60
- package/lib/browser/file-dialog/file-dialog-hidden-files-renderer.d.ts +15 -15
- package/lib/browser/file-dialog/file-dialog-hidden-files-renderer.js +67 -67
- package/lib/browser/file-dialog/file-dialog-model.d.ts +25 -25
- package/lib/browser/file-dialog/file-dialog-model.js +108 -108
- package/lib/browser/file-dialog/file-dialog-module.d.ts +3 -3
- package/lib/browser/file-dialog/file-dialog-module.js +45 -45
- package/lib/browser/file-dialog/file-dialog-service.d.ts +32 -32
- package/lib/browser/file-dialog/file-dialog-service.js +109 -109
- package/lib/browser/file-dialog/file-dialog-tree-filters-renderer.d.ts +39 -39
- package/lib/browser/file-dialog/file-dialog-tree-filters-renderer.js +92 -92
- package/lib/browser/file-dialog/file-dialog-tree.d.ts +26 -26
- package/lib/browser/file-dialog/file-dialog-tree.js +88 -88
- package/lib/browser/file-dialog/file-dialog-widget.d.ts +15 -15
- package/lib/browser/file-dialog/file-dialog-widget.js +86 -86
- package/lib/browser/file-dialog/file-dialog.d.ts +129 -129
- package/lib/browser/file-dialog/file-dialog.js +362 -362
- package/lib/browser/file-dialog/index.d.ts +4 -4
- package/lib/browser/file-dialog/index.js +31 -31
- package/lib/browser/file-resource.d.ts +66 -63
- package/lib/browser/file-resource.d.ts.map +1 -1
- package/lib/browser/file-resource.js +362 -352
- package/lib/browser/file-resource.js.map +1 -1
- package/lib/browser/file-selection.d.ts +14 -14
- package/lib/browser/file-selection.js +36 -36
- package/lib/browser/file-service.d.ts +413 -412
- package/lib/browser/file-service.d.ts.map +1 -1
- package/lib/browser/file-service.js +1362 -1360
- package/lib/browser/file-service.js.map +1 -1
- package/lib/browser/file-tree/file-tree-container.d.ts +3 -3
- package/lib/browser/file-tree/file-tree-container.js +35 -35
- package/lib/browser/file-tree/file-tree-decorator-adapter.d.ts +30 -30
- package/lib/browser/file-tree/file-tree-decorator-adapter.js +177 -177
- package/lib/browser/file-tree/file-tree-label-provider.d.ts +12 -12
- package/lib/browser/file-tree/file-tree-label-provider.js +62 -62
- package/lib/browser/file-tree/file-tree-model.d.ts +37 -37
- package/lib/browser/file-tree/file-tree-model.js +225 -225
- package/lib/browser/file-tree/file-tree-widget.d.ts +44 -44
- package/lib/browser/file-tree/file-tree-widget.js +328 -328
- package/lib/browser/file-tree/file-tree.d.ts +46 -46
- package/lib/browser/file-tree/file-tree.js +184 -184
- package/lib/browser/file-tree/index.d.ts +6 -6
- package/lib/browser/file-tree/index.js +33 -33
- package/lib/browser/file-upload-service.d.ts +109 -111
- package/lib/browser/file-upload-service.d.ts.map +1 -1
- package/lib/browser/file-upload-service.js +442 -442
- package/lib/browser/file-upload-service.js.map +1 -1
- package/lib/browser/filesystem-frontend-contribution.d.ts +63 -63
- package/lib/browser/filesystem-frontend-contribution.js +327 -327
- package/lib/browser/filesystem-frontend-module.d.ts +5 -5
- package/lib/browser/filesystem-frontend-module.js +64 -64
- package/lib/browser/filesystem-preferences.d.ts +29 -29
- package/lib/browser/filesystem-preferences.js +110 -110
- package/lib/browser/filesystem-save-resource-service.d.ts +29 -29
- package/lib/browser/filesystem-save-resource-service.d.ts.map +1 -1
- package/lib/browser/filesystem-save-resource-service.js +143 -142
- package/lib/browser/filesystem-save-resource-service.js.map +1 -1
- package/lib/browser/filesystem-watcher-error-handler.d.ts +10 -10
- package/lib/browser/filesystem-watcher-error-handler.js +69 -69
- package/lib/browser/index.d.ts +5 -5
- package/lib/browser/index.js +32 -32
- package/lib/browser/location/index.d.ts +2 -2
- package/lib/browser/location/index.js +29 -29
- package/lib/browser/location/location-renderer.d.ts +100 -100
- package/lib/browser/location/location-renderer.js +354 -354
- package/lib/browser/location/location-service.d.ts +5 -5
- package/lib/browser/location/location-service.js +17 -17
- package/lib/browser/remote-file-service-contribution.d.ts +6 -6
- package/lib/browser/remote-file-service-contribution.js +47 -47
- package/lib/browser-only/browser-only-filesystem-frontend-module.d.ts +4 -0
- package/lib/browser-only/browser-only-filesystem-frontend-module.d.ts.map +1 -0
- package/lib/browser-only/browser-only-filesystem-frontend-module.js +41 -0
- package/lib/browser-only/browser-only-filesystem-frontend-module.js.map +1 -0
- package/lib/browser-only/browser-only-filesystem-provider-server.d.ts +12 -0
- package/lib/browser-only/browser-only-filesystem-provider-server.d.ts.map +1 -0
- package/lib/browser-only/browser-only-filesystem-provider-server.js +45 -0
- package/lib/browser-only/browser-only-filesystem-provider-server.js.map +1 -0
- package/lib/browser-only/browserfs-filesystem-initialization.d.ts +13 -0
- package/lib/browser-only/browserfs-filesystem-initialization.d.ts.map +1 -0
- package/lib/browser-only/browserfs-filesystem-initialization.js +60 -0
- package/lib/browser-only/browserfs-filesystem-initialization.js.map +1 -0
- package/lib/browser-only/browserfs-filesystem-provider.d.ts +46 -0
- package/lib/browser-only/browserfs-filesystem-provider.d.ts.map +1 -0
- package/lib/browser-only/browserfs-filesystem-provider.js +451 -0
- package/lib/browser-only/browserfs-filesystem-provider.js.map +1 -0
- package/lib/common/delegating-file-system-provider.d.ts +76 -76
- package/lib/common/delegating-file-system-provider.js +168 -168
- package/lib/common/download/file-download-data.d.ts +6 -6
- package/lib/common/download/file-download-data.js +26 -26
- package/lib/common/file-upload.d.ts +1 -1
- package/lib/common/file-upload.js +19 -19
- package/lib/common/files.d.ts +651 -651
- package/lib/common/files.js +347 -347
- package/lib/common/files.spec.d.ts +1 -1
- package/lib/common/files.spec.js +51 -51
- package/lib/common/filesystem-utils.d.ts +14 -14
- package/lib/common/filesystem-utils.js +63 -63
- package/lib/common/filesystem-utils.spec.d.ts +1 -1
- package/lib/common/filesystem-utils.spec.js +378 -378
- package/lib/common/filesystem-watcher-protocol.d.ts +71 -71
- package/lib/common/filesystem-watcher-protocol.js +20 -20
- package/lib/common/filesystem.d.ts +22 -22
- package/lib/common/filesystem.js +42 -42
- package/lib/common/index.d.ts +2 -2
- package/lib/common/index.js +29 -29
- package/lib/common/io.d.ts +19 -19
- package/lib/common/io.js +110 -110
- package/lib/common/remote-file-system-provider.d.ts +164 -164
- package/lib/common/remote-file-system-provider.js +413 -413
- package/lib/electron-browser/file-dialog/electron-file-dialog-module.d.ts +3 -3
- package/lib/electron-browser/file-dialog/electron-file-dialog-module.js +24 -24
- package/lib/electron-browser/file-dialog/electron-file-dialog-service.d.ts +19 -19
- package/lib/electron-browser/file-dialog/electron-file-dialog-service.js +156 -156
- package/lib/electron-browser/file-dialog/electron-file-dialog-service.js.map +1 -1
- package/lib/electron-browser/preload.d.ts +1 -1
- package/lib/electron-browser/preload.js +30 -30
- package/lib/electron-common/electron-api.d.ts +34 -34
- package/lib/electron-common/electron-api.js +20 -20
- package/lib/electron-main/electron-api-main.d.ts +5 -5
- package/lib/electron-main/electron-api-main.js +78 -78
- package/lib/electron-main/electron-main-module.d.ts +3 -3
- package/lib/electron-main/electron-main-module.js +24 -24
- package/lib/node/disk-file-system-provider.d.ts +72 -72
- package/lib/node/disk-file-system-provider.d.ts.map +1 -1
- package/lib/node/disk-file-system-provider.js +795 -789
- package/lib/node/disk-file-system-provider.js.map +1 -1
- package/lib/node/disk-file-system-provider.spec.d.ts +1 -1
- package/lib/node/disk-file-system-provider.spec.js +122 -91
- package/lib/node/disk-file-system-provider.spec.js.map +1 -1
- package/lib/node/download/directory-archiver.d.ts +9 -9
- package/lib/node/download/directory-archiver.js +132 -132
- package/lib/node/download/directory-archiver.js.map +1 -1
- package/lib/node/download/directory-archiver.spec.d.ts +1 -1
- package/lib/node/download/directory-archiver.spec.js +97 -97
- package/lib/node/download/directory-archiver.spec.js.map +1 -1
- package/lib/node/download/file-download-backend-module.d.ts +3 -3
- package/lib/node/download/file-download-backend-module.js +32 -32
- package/lib/node/download/file-download-cache.d.ts +21 -21
- package/lib/node/download/file-download-cache.js +90 -90
- package/lib/node/download/file-download-endpoint.d.ts +11 -11
- package/lib/node/download/file-download-endpoint.js +75 -75
- package/lib/node/download/file-download-endpoint.js.map +1 -1
- package/lib/node/download/file-download-handler.d.ts +50 -50
- package/lib/node/download/file-download-handler.d.ts.map +1 -1
- package/lib/node/download/file-download-handler.js +315 -315
- package/lib/node/download/file-download-handler.js.map +1 -1
- package/lib/node/download/test/mock-directory-archiver.d.ts +7 -7
- package/lib/node/download/test/mock-directory-archiver.js +29 -29
- package/lib/node/file-change-collection.d.ts +22 -22
- package/lib/node/file-change-collection.js +77 -77
- package/lib/node/file-change-collection.spec.d.ts +1 -1
- package/lib/node/file-change-collection.spec.js +90 -90
- package/lib/node/file-change-collection.spec.js.map +1 -1
- package/lib/node/filesystem-backend-module.d.ts +26 -26
- package/lib/node/filesystem-backend-module.js +120 -120
- package/lib/node/filesystem-watcher-client.d.ts +23 -23
- package/lib/node/filesystem-watcher-client.js +83 -83
- package/lib/node/filesystem-watcher-dispatcher.d.ts +23 -23
- package/lib/node/filesystem-watcher-dispatcher.js +85 -85
- package/lib/node/node-file-upload-service.d.ts +16 -16
- package/lib/node/node-file-upload-service.js +84 -84
- package/lib/node/nsfw-watcher/index.d.ts +3 -3
- package/lib/node/nsfw-watcher/index.js +39 -39
- package/lib/node/nsfw-watcher/nsfw-filesystem-service.d.ts +191 -191
- package/lib/node/nsfw-watcher/nsfw-filesystem-service.js +405 -405
- package/lib/node/nsfw-watcher/nsfw-filesystem-service.js.map +1 -1
- package/lib/node/nsfw-watcher/nsfw-filesystem-watcher.spec.d.ts +1 -1
- package/lib/node/nsfw-watcher/nsfw-filesystem-watcher.spec.js +151 -151
- package/lib/node/nsfw-watcher/nsfw-options.d.ts +6 -6
- package/lib/node/nsfw-watcher/nsfw-options.js +22 -22
- package/package.json +8 -6
- package/src/browser/breadcrumbs/filepath-breadcrumb.ts +43 -43
- package/src/browser/breadcrumbs/filepath-breadcrumbs-container.ts +65 -65
- package/src/browser/breadcrumbs/filepath-breadcrumbs-contribution.ts +129 -129
- package/src/browser/download/file-download-command-contribution.ts +83 -83
- package/src/browser/download/file-download-frontend-module.ts +25 -25
- package/src/browser/download/file-download-service.ts +179 -179
- package/src/browser/file-dialog/file-dialog-container.ts +67 -67
- package/src/browser/file-dialog/file-dialog-hidden-files-renderer.tsx +59 -59
- package/src/browser/file-dialog/file-dialog-model.ts +96 -96
- package/src/browser/file-dialog/file-dialog-module.ts +44 -44
- package/src/browser/file-dialog/file-dialog-service.ts +99 -99
- package/src/browser/file-dialog/file-dialog-tree-filters-renderer.tsx +100 -100
- package/src/browser/file-dialog/file-dialog-tree.ts +89 -89
- package/src/browser/file-dialog/file-dialog-widget.ts +75 -75
- package/src/browser/file-dialog/file-dialog.ts +434 -434
- package/src/browser/file-dialog/index.ts +20 -20
- package/src/browser/file-resource.ts +373 -361
- package/src/browser/file-selection.ts +44 -44
- package/src/browser/file-service.ts +1817 -1814
- package/src/browser/file-tree/file-tree-container.ts +36 -36
- package/src/browser/file-tree/file-tree-decorator-adapter.ts +159 -159
- package/src/browser/file-tree/file-tree-label-provider.ts +53 -53
- package/src/browser/file-tree/file-tree-model.ts +212 -212
- package/src/browser/file-tree/file-tree-widget.tsx +327 -327
- package/src/browser/file-tree/file-tree.ts +183 -183
- package/src/browser/file-tree/index.ts +22 -22
- package/src/browser/file-upload-service.ts +539 -541
- package/src/browser/filesystem-frontend-contribution.ts +338 -338
- package/src/browser/filesystem-frontend-module.ts +77 -77
- package/src/browser/filesystem-preferences.ts +139 -139
- package/src/browser/filesystem-save-resource-service.ts +125 -124
- package/src/browser/filesystem-watcher-error-handler.ts +60 -60
- package/src/browser/index.ts +21 -21
- package/src/browser/location/index.ts +18 -18
- package/src/browser/location/location-renderer.tsx +404 -404
- package/src/browser/location/location-service.ts +22 -22
- package/src/browser/remote-file-service-contribution.ts +38 -38
- package/src/browser/style/file-dialog.css +208 -208
- package/src/browser/style/file-icons.css +64 -64
- package/src/browser/style/filepath-breadcrumbs.css +20 -20
- package/src/browser/style/index.css +36 -36
- package/src/browser-only/browser-only-filesystem-frontend-module.ts +38 -0
- package/src/browser-only/browser-only-filesystem-provider-server.ts +32 -0
- package/src/browser-only/browserfs-filesystem-initialization.ts +61 -0
- package/src/browser-only/browserfs-filesystem-provider.ts +462 -0
- package/src/common/delegating-file-system-provider.ts +226 -226
- package/src/common/download/README.md +30 -30
- package/src/common/download/file-download-data.ts +27 -27
- package/src/common/file-upload.ts +17 -17
- package/src/common/files.spec.ts +51 -51
- package/src/common/files.ts +983 -983
- package/src/common/filesystem-utils.spec.ts +411 -411
- package/src/common/filesystem-utils.ts +64 -64
- package/src/common/filesystem-watcher-protocol.ts +96 -96
- package/src/common/filesystem.ts +43 -43
- package/src/common/index.ts +18 -18
- package/src/common/io.ts +150 -150
- package/src/common/remote-file-system-provider.ts +511 -511
- package/src/electron-browser/file-dialog/electron-file-dialog-module.ts +24 -24
- package/src/electron-browser/file-dialog/electron-file-dialog-service.ts +165 -165
- package/src/electron-browser/preload.ts +31 -31
- package/src/electron-common/electron-api.ts +55 -55
- package/src/electron-main/electron-api-main.ts +78 -78
- package/src/electron-main/electron-main-module.ts +23 -23
- package/src/node/disk-file-system-provider.spec.ts +142 -109
- package/src/node/disk-file-system-provider.ts +915 -910
- package/src/node/download/directory-archiver.spec.ts +104 -104
- package/src/node/download/directory-archiver.ts +126 -126
- package/src/node/download/file-download-backend-module.ts +32 -32
- package/src/node/download/file-download-cache.ts +88 -88
- package/src/node/download/file-download-endpoint.ts +63 -63
- package/src/node/download/file-download-handler.ts +304 -304
- package/src/node/download/test/mock-directory-archiver.ts +30 -30
- package/src/node/file-change-collection.spec.ts +110 -110
- package/src/node/file-change-collection.ts +78 -78
- package/src/node/filesystem-backend-module.ts +140 -140
- package/src/node/filesystem-watcher-client.ts +72 -72
- package/src/node/filesystem-watcher-dispatcher.ts +82 -82
- package/src/node/node-file-upload-service.ts +80 -80
- package/src/node/nsfw-watcher/index.ts +45 -45
- package/src/node/nsfw-watcher/nsfw-filesystem-service.ts +481 -481
- package/src/node/nsfw-watcher/nsfw-filesystem-watcher.spec.ts +182 -182
- package/src/node/nsfw-watcher/nsfw-options.ts +23 -23
- package/src/typings/dom.webkit.d.ts +77 -77
- package/src/typings/mv/index.d.ts +21 -21
- package/src/typings/nsfw/index.d.ts +18 -18
- package/src/typings/trash/index.d.ts +20 -20
|
@@ -1,404 +1,404 @@
|
|
|
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 URI from '@theia/core/lib/common/uri';
|
|
18
|
-
import { LocationService } from './location-service';
|
|
19
|
-
import * as React from '@theia/core/shared/react';
|
|
20
|
-
import { FileService } from '../file-service';
|
|
21
|
-
import { DisposableCollection, Emitter, Path } from '@theia/core/lib/common';
|
|
22
|
-
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
|
23
|
-
import { FileDialogModel } from '../file-dialog/file-dialog-model';
|
|
24
|
-
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
25
|
-
import { ReactRenderer } from '@theia/core/lib/browser/widgets/react-renderer';
|
|
26
|
-
import { codicon } from '@theia/core/lib/browser';
|
|
27
|
-
|
|
28
|
-
interface AutoSuggestDataEvent {
|
|
29
|
-
parent: string;
|
|
30
|
-
children: string[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
class ResolvedDirectoryCache {
|
|
34
|
-
protected pendingResolvedDirectories = new Map<string, Promise<void>>();
|
|
35
|
-
protected cachedDirectories = new Map<string, string[]>();
|
|
36
|
-
|
|
37
|
-
protected directoryResolvedEmitter = new Emitter<AutoSuggestDataEvent>();
|
|
38
|
-
readonly onDirectoryDidResolve = this.directoryResolvedEmitter.event;
|
|
39
|
-
|
|
40
|
-
constructor(protected readonly fileService: FileService) { }
|
|
41
|
-
|
|
42
|
-
tryResolveChildDirectories(inputAsURI: URI): string[] | undefined {
|
|
43
|
-
const parentDirectory = inputAsURI.path.dir.toString();
|
|
44
|
-
const cachedDirectories = this.cachedDirectories.get(parentDirectory);
|
|
45
|
-
const pendingDirectories = this.pendingResolvedDirectories.get(parentDirectory);
|
|
46
|
-
if (cachedDirectories) {
|
|
47
|
-
return cachedDirectories;
|
|
48
|
-
} else if (!pendingDirectories) {
|
|
49
|
-
this.pendingResolvedDirectories.set(parentDirectory, this.createResolutionPromise(parentDirectory));
|
|
50
|
-
}
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
protected async createResolutionPromise(directoryToResolve: string): Promise<void> {
|
|
55
|
-
return this.fileService.resolve(new URI(directoryToResolve)).then(({ children }) => {
|
|
56
|
-
if (children) {
|
|
57
|
-
const childDirectories = children.filter(child => child.isDirectory)
|
|
58
|
-
.map(directory => `${directory.resource.path}/`);
|
|
59
|
-
this.cachedDirectories.set(directoryToResolve, childDirectories);
|
|
60
|
-
this.directoryResolvedEmitter.fire({ parent: directoryToResolve, children: childDirectories });
|
|
61
|
-
}
|
|
62
|
-
}).catch(e => {
|
|
63
|
-
// no-op
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const LocationListRendererFactory = Symbol('LocationListRendererFactory');
|
|
69
|
-
export interface LocationListRendererFactory {
|
|
70
|
-
(options: LocationListRendererOptions): LocationListRenderer;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export const LocationListRendererOptions = Symbol('LocationListRendererOptions');
|
|
74
|
-
export interface LocationListRendererOptions {
|
|
75
|
-
model: FileDialogModel;
|
|
76
|
-
host?: HTMLElement;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@injectable()
|
|
80
|
-
export class LocationListRenderer extends ReactRenderer {
|
|
81
|
-
|
|
82
|
-
@inject(FileService) protected readonly fileService: FileService;
|
|
83
|
-
@inject(EnvVariablesServer) protected readonly variablesServer: EnvVariablesServer;
|
|
84
|
-
|
|
85
|
-
protected directoryCache: ResolvedDirectoryCache;
|
|
86
|
-
protected service: LocationService;
|
|
87
|
-
protected toDisposeOnNewCache = new DisposableCollection();
|
|
88
|
-
protected _drives: URI[] | undefined;
|
|
89
|
-
protected _doShowTextInput = false;
|
|
90
|
-
protected homeDir: string;
|
|
91
|
-
|
|
92
|
-
get doShowTextInput(): boolean {
|
|
93
|
-
return this._doShowTextInput;
|
|
94
|
-
}
|
|
95
|
-
set doShowTextInput(doShow: boolean) {
|
|
96
|
-
this._doShowTextInput = doShow;
|
|
97
|
-
if (doShow) {
|
|
98
|
-
this.initResolveDirectoryCache();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
protected lastUniqueTextInputLocation: URI | undefined;
|
|
102
|
-
protected previousAutocompleteMatch: string;
|
|
103
|
-
protected doAttemptAutocomplete = true;
|
|
104
|
-
|
|
105
|
-
constructor(
|
|
106
|
-
@inject(LocationListRendererOptions) readonly options: LocationListRendererOptions
|
|
107
|
-
) {
|
|
108
|
-
super(options.host);
|
|
109
|
-
this.service = options.model;
|
|
110
|
-
this.doLoadDrives();
|
|
111
|
-
this.doAfterRender = this.doAfterRender.bind(this);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
@postConstruct()
|
|
115
|
-
protected init(): void {
|
|
116
|
-
this.doInit();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
protected async doInit(): Promise<void> {
|
|
120
|
-
const homeDirWithPrefix = await this.variablesServer.getHomeDirUri();
|
|
121
|
-
this.homeDir = (new URI(homeDirWithPrefix)).path.toString();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
override render(): void {
|
|
125
|
-
this.hostRoot.render(this.doRender());
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
protected initResolveDirectoryCache(): void {
|
|
129
|
-
this.toDisposeOnNewCache.dispose();
|
|
130
|
-
this.directoryCache = new ResolvedDirectoryCache(this.fileService);
|
|
131
|
-
this.toDisposeOnNewCache.push(this.directoryCache.onDirectoryDidResolve(({ parent, children }) => {
|
|
132
|
-
if (this.locationTextInput) {
|
|
133
|
-
const expandedPath = Path.untildify(this.locationTextInput.value, this.homeDir);
|
|
134
|
-
const inputParent = (new URI(expandedPath)).path.dir.toString();
|
|
135
|
-
if (inputParent === parent) {
|
|
136
|
-
this.tryRenderFirstMatch(this.locationTextInput, children);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
protected doAfterRender = (): void => {
|
|
143
|
-
const locationList = this.locationList;
|
|
144
|
-
const locationListTextInput = this.locationTextInput;
|
|
145
|
-
if (locationList) {
|
|
146
|
-
const currentLocation = this.service.location;
|
|
147
|
-
locationList.value = currentLocation ? currentLocation.toString() : '';
|
|
148
|
-
} else if (locationListTextInput) {
|
|
149
|
-
locationListTextInput.focus();
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
protected readonly handleLocationChanged = (e: React.ChangeEvent<HTMLSelectElement>) => this.onLocationChanged(e);
|
|
154
|
-
protected readonly handleTextInputOnChange = (e: React.ChangeEvent<HTMLInputElement>) => this.trySuggestDirectory(e);
|
|
155
|
-
protected readonly handleTextInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => this.handleControlKeys(e);
|
|
156
|
-
protected readonly handleIconKeyDown = (e: React.KeyboardEvent<HTMLSpanElement>) => this.toggleInputOnKeyDown(e);
|
|
157
|
-
protected readonly handleTextInputOnBlur = () => this.toggleToSelectInput();
|
|
158
|
-
protected readonly handleTextInputMouseDown = (e: React.MouseEvent<HTMLSpanElement>) => this.toggleToTextInputOnMouseDown(e);
|
|
159
|
-
|
|
160
|
-
protected override doRender(): React.ReactElement {
|
|
161
|
-
return (
|
|
162
|
-
<>
|
|
163
|
-
{this.renderInputIcon()}
|
|
164
|
-
{this.doShowTextInput
|
|
165
|
-
? this.renderTextInput()
|
|
166
|
-
: this.renderSelectInput()
|
|
167
|
-
}
|
|
168
|
-
</>
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
protected renderInputIcon(): React.ReactNode {
|
|
173
|
-
return (
|
|
174
|
-
<span
|
|
175
|
-
// onMouseDown is used since it will fire before 'onBlur'. This prevents
|
|
176
|
-
// a re-render when textinput is in focus and user clicks toggle icon
|
|
177
|
-
onMouseDown={this.handleTextInputMouseDown}
|
|
178
|
-
onKeyDown={this.handleIconKeyDown}
|
|
179
|
-
className={LocationListRenderer.Styles.LOCATION_INPUT_TOGGLE_CLASS}
|
|
180
|
-
tabIndex={0}
|
|
181
|
-
id={`${this.doShowTextInput ? 'text-input' : 'select-input'}`}
|
|
182
|
-
title={this.doShowTextInput
|
|
183
|
-
? LocationListRenderer.Tooltips.TOGGLE_SELECT_INPUT
|
|
184
|
-
: LocationListRenderer.Tooltips.TOGGLE_TEXT_INPUT}
|
|
185
|
-
ref={this.doAfterRender}
|
|
186
|
-
>
|
|
187
|
-
<i className={codicon(this.doShowTextInput ? 'folder-opened' : 'edit')} />
|
|
188
|
-
</span>
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
protected renderTextInput(): React.ReactNode {
|
|
193
|
-
return (
|
|
194
|
-
<input className={'theia-select ' + LocationListRenderer.Styles.LOCATION_TEXT_INPUT_CLASS}
|
|
195
|
-
defaultValue={this.service.location?.path.fsPath()}
|
|
196
|
-
onBlur={this.handleTextInputOnBlur}
|
|
197
|
-
onChange={this.handleTextInputOnChange}
|
|
198
|
-
onKeyDown={this.handleTextInputKeyDown}
|
|
199
|
-
spellCheck={false}
|
|
200
|
-
/>
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
protected renderSelectInput(): React.ReactNode {
|
|
205
|
-
const options = this.collectLocations().map(value => this.renderLocation(value));
|
|
206
|
-
return (
|
|
207
|
-
<select className={`theia-select ${LocationListRenderer.Styles.LOCATION_LIST_CLASS}`}
|
|
208
|
-
onChange={this.handleLocationChanged}>
|
|
209
|
-
{...options}
|
|
210
|
-
</select>
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
protected toggleInputOnKeyDown(e: React.KeyboardEvent<HTMLSpanElement>): void {
|
|
215
|
-
if (e.key === 'Enter') {
|
|
216
|
-
this.doShowTextInput = true;
|
|
217
|
-
this.render();
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
protected toggleToTextInputOnMouseDown(e: React.MouseEvent<HTMLSpanElement>): void {
|
|
222
|
-
if (e.currentTarget.id === 'select-input') {
|
|
223
|
-
e.preventDefault();
|
|
224
|
-
this.doShowTextInput = true;
|
|
225
|
-
this.render();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
protected toggleToSelectInput(): void {
|
|
230
|
-
if (this.doShowTextInput) {
|
|
231
|
-
this.doShowTextInput = false;
|
|
232
|
-
this.render();
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Collects the available locations based on the currently selected, and appends the available drives to it.
|
|
238
|
-
*/
|
|
239
|
-
protected collectLocations(): LocationListRenderer.Location[] {
|
|
240
|
-
const location = this.service.location;
|
|
241
|
-
const locations: LocationListRenderer.Location[] = (!!location ? location.allLocations : []).map(uri => ({ uri }));
|
|
242
|
-
if (this._drives) {
|
|
243
|
-
const drives = this._drives.map(uri => ({ uri, isDrive: true }));
|
|
244
|
-
// `URI.allLocations` returns with the URI without the trailing slash unlike `FileUri.create(fsPath)`.
|
|
245
|
-
// to be able to compare file:///path/to/resource with file:///path/to/resource/.
|
|
246
|
-
const toUriString = (uri: URI) => {
|
|
247
|
-
const toString = uri.toString();
|
|
248
|
-
return toString.endsWith('/') ? toString.slice(0, -1) : toString;
|
|
249
|
-
};
|
|
250
|
-
drives.forEach(drive => {
|
|
251
|
-
const index = locations.findIndex(loc => toUriString(loc.uri) === toUriString(drive.uri));
|
|
252
|
-
// Ignore drives which are already discovered as a location based on the current model root URI.
|
|
253
|
-
if (index === -1) {
|
|
254
|
-
// Make sure, it does not have the trailing slash.
|
|
255
|
-
locations.push({ uri: new URI(toUriString(drive.uri)), isDrive: true });
|
|
256
|
-
} else {
|
|
257
|
-
// This is necessary for Windows to be able to show `/e:/` as a drive and `c:` as "non-drive" in the same way.
|
|
258
|
-
// `URI.path.toString()` Vs. `URI.displayName` behaves a bit differently on Windows.
|
|
259
|
-
// https://github.com/eclipse-theia/theia/pull/3038#issuecomment-425944189
|
|
260
|
-
locations[index].isDrive = true;
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
this.doLoadDrives();
|
|
265
|
-
return locations;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Asynchronously loads the drives (if not yet available) and triggers a UI update on success with the new values.
|
|
270
|
-
*/
|
|
271
|
-
protected doLoadDrives(): void {
|
|
272
|
-
if (!this._drives) {
|
|
273
|
-
this.service.drives().then(drives => {
|
|
274
|
-
// If the `drives` are empty, something already went wrong.
|
|
275
|
-
if (drives.length > 0) {
|
|
276
|
-
this._drives = drives;
|
|
277
|
-
this.render();
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
protected renderLocation(location: LocationListRenderer.Location): React.ReactNode {
|
|
284
|
-
const { uri, isDrive } = location;
|
|
285
|
-
const value = uri.toString();
|
|
286
|
-
return <option value={value} key={uri.toString()}>{isDrive ? uri.path.fsPath() : uri.displayName}</option>;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
protected onLocationChanged(e: React.ChangeEvent<HTMLSelectElement>): void {
|
|
290
|
-
const locationList = this.locationList;
|
|
291
|
-
if (locationList) {
|
|
292
|
-
const value = locationList.value;
|
|
293
|
-
const uri = new URI(value);
|
|
294
|
-
this.trySetNewLocation(uri);
|
|
295
|
-
e.preventDefault();
|
|
296
|
-
e.stopPropagation();
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
protected trySetNewLocation(newLocation: URI): void {
|
|
301
|
-
if (this.lastUniqueTextInputLocation === undefined) {
|
|
302
|
-
this.lastUniqueTextInputLocation = this.service.location;
|
|
303
|
-
}
|
|
304
|
-
// prevent consecutive repeated locations from being added to location history
|
|
305
|
-
if (this.lastUniqueTextInputLocation?.path.toString() !== newLocation.path.toString()) {
|
|
306
|
-
this.lastUniqueTextInputLocation = newLocation;
|
|
307
|
-
this.service.location = newLocation;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
protected trySuggestDirectory(e: React.ChangeEvent<HTMLInputElement>): void {
|
|
312
|
-
if (this.doAttemptAutocomplete) {
|
|
313
|
-
const inputElement = e.currentTarget;
|
|
314
|
-
const { value } = inputElement;
|
|
315
|
-
if ((value.startsWith('/') || value.startsWith('~/')) && value.slice(-1) !== '/') {
|
|
316
|
-
const expandedPath = Path.untildify(value, this.homeDir);
|
|
317
|
-
const valueAsURI = new URI(expandedPath);
|
|
318
|
-
const autocompleteDirectories = this.directoryCache.tryResolveChildDirectories(valueAsURI);
|
|
319
|
-
if (autocompleteDirectories) {
|
|
320
|
-
this.tryRenderFirstMatch(inputElement, autocompleteDirectories);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
protected tryRenderFirstMatch(inputElement: HTMLInputElement, children: string[]): void {
|
|
327
|
-
const { value, selectionStart } = inputElement;
|
|
328
|
-
if (this.locationTextInput) {
|
|
329
|
-
const expandedPath = Path.untildify(value, this.homeDir);
|
|
330
|
-
const firstMatch = children?.find(child => child.includes(expandedPath));
|
|
331
|
-
if (firstMatch) {
|
|
332
|
-
const contractedPath = value.startsWith('~') ? Path.tildify(firstMatch, this.homeDir) : firstMatch;
|
|
333
|
-
this.locationTextInput.value = contractedPath;
|
|
334
|
-
this.locationTextInput.selectionStart = selectionStart;
|
|
335
|
-
this.locationTextInput.selectionEnd = firstMatch.length;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
protected handleControlKeys(e: React.KeyboardEvent<HTMLInputElement>): void {
|
|
341
|
-
this.doAttemptAutocomplete = e.key !== 'Backspace';
|
|
342
|
-
if (e.key === 'Enter') {
|
|
343
|
-
const locationTextInput = this.locationTextInput;
|
|
344
|
-
if (locationTextInput) {
|
|
345
|
-
// expand '~' if present and remove extra whitespace and any trailing slashes or periods.
|
|
346
|
-
const sanitizedInput = locationTextInput.value.trim().replace(/[\/\\.]*$/, '');
|
|
347
|
-
const untildifiedInput = Path.untildify(sanitizedInput, this.homeDir);
|
|
348
|
-
const uri = new URI(untildifiedInput);
|
|
349
|
-
this.trySetNewLocation(uri);
|
|
350
|
-
this.toggleToSelectInput();
|
|
351
|
-
}
|
|
352
|
-
} else if (e.key === 'Escape') {
|
|
353
|
-
this.toggleToSelectInput();
|
|
354
|
-
} else if (e.key === 'Tab') {
|
|
355
|
-
e.preventDefault();
|
|
356
|
-
const textInput = this.locationTextInput;
|
|
357
|
-
if (textInput) {
|
|
358
|
-
textInput.selectionStart = textInput.value.length;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
e.stopPropagation();
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
get locationList(): HTMLSelectElement | undefined {
|
|
365
|
-
const locationList = this.host.getElementsByClassName(LocationListRenderer.Styles.LOCATION_LIST_CLASS)[0];
|
|
366
|
-
if (locationList instanceof HTMLSelectElement) {
|
|
367
|
-
return locationList;
|
|
368
|
-
}
|
|
369
|
-
return undefined;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
get locationTextInput(): HTMLInputElement | undefined {
|
|
373
|
-
const locationTextInput = this.host.getElementsByClassName(LocationListRenderer.Styles.LOCATION_TEXT_INPUT_CLASS)[0];
|
|
374
|
-
if (locationTextInput instanceof HTMLInputElement) {
|
|
375
|
-
return locationTextInput;
|
|
376
|
-
}
|
|
377
|
-
return undefined;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
override dispose(): void {
|
|
381
|
-
super.dispose();
|
|
382
|
-
this.toDisposeOnNewCache.dispose();
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
export namespace LocationListRenderer {
|
|
387
|
-
|
|
388
|
-
export namespace Styles {
|
|
389
|
-
export const LOCATION_LIST_CLASS = 'theia-LocationList';
|
|
390
|
-
export const LOCATION_INPUT_TOGGLE_CLASS = 'theia-LocationInputToggle';
|
|
391
|
-
export const LOCATION_TEXT_INPUT_CLASS = 'theia-LocationTextInput';
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export namespace Tooltips {
|
|
395
|
-
export const TOGGLE_TEXT_INPUT = 'Switch to text-based input';
|
|
396
|
-
export const TOGGLE_SELECT_INPUT = 'Switch to location list';
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
export interface Location {
|
|
400
|
-
uri: URI;
|
|
401
|
-
isDrive?: boolean;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
}
|
|
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 URI from '@theia/core/lib/common/uri';
|
|
18
|
+
import { LocationService } from './location-service';
|
|
19
|
+
import * as React from '@theia/core/shared/react';
|
|
20
|
+
import { FileService } from '../file-service';
|
|
21
|
+
import { DisposableCollection, Emitter, Path } from '@theia/core/lib/common';
|
|
22
|
+
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
|
23
|
+
import { FileDialogModel } from '../file-dialog/file-dialog-model';
|
|
24
|
+
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
25
|
+
import { ReactRenderer } from '@theia/core/lib/browser/widgets/react-renderer';
|
|
26
|
+
import { codicon } from '@theia/core/lib/browser';
|
|
27
|
+
|
|
28
|
+
interface AutoSuggestDataEvent {
|
|
29
|
+
parent: string;
|
|
30
|
+
children: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class ResolvedDirectoryCache {
|
|
34
|
+
protected pendingResolvedDirectories = new Map<string, Promise<void>>();
|
|
35
|
+
protected cachedDirectories = new Map<string, string[]>();
|
|
36
|
+
|
|
37
|
+
protected directoryResolvedEmitter = new Emitter<AutoSuggestDataEvent>();
|
|
38
|
+
readonly onDirectoryDidResolve = this.directoryResolvedEmitter.event;
|
|
39
|
+
|
|
40
|
+
constructor(protected readonly fileService: FileService) { }
|
|
41
|
+
|
|
42
|
+
tryResolveChildDirectories(inputAsURI: URI): string[] | undefined {
|
|
43
|
+
const parentDirectory = inputAsURI.path.dir.toString();
|
|
44
|
+
const cachedDirectories = this.cachedDirectories.get(parentDirectory);
|
|
45
|
+
const pendingDirectories = this.pendingResolvedDirectories.get(parentDirectory);
|
|
46
|
+
if (cachedDirectories) {
|
|
47
|
+
return cachedDirectories;
|
|
48
|
+
} else if (!pendingDirectories) {
|
|
49
|
+
this.pendingResolvedDirectories.set(parentDirectory, this.createResolutionPromise(parentDirectory));
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
protected async createResolutionPromise(directoryToResolve: string): Promise<void> {
|
|
55
|
+
return this.fileService.resolve(new URI(directoryToResolve)).then(({ children }) => {
|
|
56
|
+
if (children) {
|
|
57
|
+
const childDirectories = children.filter(child => child.isDirectory)
|
|
58
|
+
.map(directory => `${directory.resource.path}/`);
|
|
59
|
+
this.cachedDirectories.set(directoryToResolve, childDirectories);
|
|
60
|
+
this.directoryResolvedEmitter.fire({ parent: directoryToResolve, children: childDirectories });
|
|
61
|
+
}
|
|
62
|
+
}).catch(e => {
|
|
63
|
+
// no-op
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const LocationListRendererFactory = Symbol('LocationListRendererFactory');
|
|
69
|
+
export interface LocationListRendererFactory {
|
|
70
|
+
(options: LocationListRendererOptions): LocationListRenderer;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const LocationListRendererOptions = Symbol('LocationListRendererOptions');
|
|
74
|
+
export interface LocationListRendererOptions {
|
|
75
|
+
model: FileDialogModel;
|
|
76
|
+
host?: HTMLElement;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@injectable()
|
|
80
|
+
export class LocationListRenderer extends ReactRenderer {
|
|
81
|
+
|
|
82
|
+
@inject(FileService) protected readonly fileService: FileService;
|
|
83
|
+
@inject(EnvVariablesServer) protected readonly variablesServer: EnvVariablesServer;
|
|
84
|
+
|
|
85
|
+
protected directoryCache: ResolvedDirectoryCache;
|
|
86
|
+
protected service: LocationService;
|
|
87
|
+
protected toDisposeOnNewCache = new DisposableCollection();
|
|
88
|
+
protected _drives: URI[] | undefined;
|
|
89
|
+
protected _doShowTextInput = false;
|
|
90
|
+
protected homeDir: string;
|
|
91
|
+
|
|
92
|
+
get doShowTextInput(): boolean {
|
|
93
|
+
return this._doShowTextInput;
|
|
94
|
+
}
|
|
95
|
+
set doShowTextInput(doShow: boolean) {
|
|
96
|
+
this._doShowTextInput = doShow;
|
|
97
|
+
if (doShow) {
|
|
98
|
+
this.initResolveDirectoryCache();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
protected lastUniqueTextInputLocation: URI | undefined;
|
|
102
|
+
protected previousAutocompleteMatch: string;
|
|
103
|
+
protected doAttemptAutocomplete = true;
|
|
104
|
+
|
|
105
|
+
constructor(
|
|
106
|
+
@inject(LocationListRendererOptions) readonly options: LocationListRendererOptions
|
|
107
|
+
) {
|
|
108
|
+
super(options.host);
|
|
109
|
+
this.service = options.model;
|
|
110
|
+
this.doLoadDrives();
|
|
111
|
+
this.doAfterRender = this.doAfterRender.bind(this);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@postConstruct()
|
|
115
|
+
protected init(): void {
|
|
116
|
+
this.doInit();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
protected async doInit(): Promise<void> {
|
|
120
|
+
const homeDirWithPrefix = await this.variablesServer.getHomeDirUri();
|
|
121
|
+
this.homeDir = (new URI(homeDirWithPrefix)).path.toString();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
override render(): void {
|
|
125
|
+
this.hostRoot.render(this.doRender());
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
protected initResolveDirectoryCache(): void {
|
|
129
|
+
this.toDisposeOnNewCache.dispose();
|
|
130
|
+
this.directoryCache = new ResolvedDirectoryCache(this.fileService);
|
|
131
|
+
this.toDisposeOnNewCache.push(this.directoryCache.onDirectoryDidResolve(({ parent, children }) => {
|
|
132
|
+
if (this.locationTextInput) {
|
|
133
|
+
const expandedPath = Path.untildify(this.locationTextInput.value, this.homeDir);
|
|
134
|
+
const inputParent = (new URI(expandedPath)).path.dir.toString();
|
|
135
|
+
if (inputParent === parent) {
|
|
136
|
+
this.tryRenderFirstMatch(this.locationTextInput, children);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
protected doAfterRender = (): void => {
|
|
143
|
+
const locationList = this.locationList;
|
|
144
|
+
const locationListTextInput = this.locationTextInput;
|
|
145
|
+
if (locationList) {
|
|
146
|
+
const currentLocation = this.service.location;
|
|
147
|
+
locationList.value = currentLocation ? currentLocation.toString() : '';
|
|
148
|
+
} else if (locationListTextInput) {
|
|
149
|
+
locationListTextInput.focus();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
protected readonly handleLocationChanged = (e: React.ChangeEvent<HTMLSelectElement>) => this.onLocationChanged(e);
|
|
154
|
+
protected readonly handleTextInputOnChange = (e: React.ChangeEvent<HTMLInputElement>) => this.trySuggestDirectory(e);
|
|
155
|
+
protected readonly handleTextInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => this.handleControlKeys(e);
|
|
156
|
+
protected readonly handleIconKeyDown = (e: React.KeyboardEvent<HTMLSpanElement>) => this.toggleInputOnKeyDown(e);
|
|
157
|
+
protected readonly handleTextInputOnBlur = () => this.toggleToSelectInput();
|
|
158
|
+
protected readonly handleTextInputMouseDown = (e: React.MouseEvent<HTMLSpanElement>) => this.toggleToTextInputOnMouseDown(e);
|
|
159
|
+
|
|
160
|
+
protected override doRender(): React.ReactElement {
|
|
161
|
+
return (
|
|
162
|
+
<>
|
|
163
|
+
{this.renderInputIcon()}
|
|
164
|
+
{this.doShowTextInput
|
|
165
|
+
? this.renderTextInput()
|
|
166
|
+
: this.renderSelectInput()
|
|
167
|
+
}
|
|
168
|
+
</>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
protected renderInputIcon(): React.ReactNode {
|
|
173
|
+
return (
|
|
174
|
+
<span
|
|
175
|
+
// onMouseDown is used since it will fire before 'onBlur'. This prevents
|
|
176
|
+
// a re-render when textinput is in focus and user clicks toggle icon
|
|
177
|
+
onMouseDown={this.handleTextInputMouseDown}
|
|
178
|
+
onKeyDown={this.handleIconKeyDown}
|
|
179
|
+
className={LocationListRenderer.Styles.LOCATION_INPUT_TOGGLE_CLASS}
|
|
180
|
+
tabIndex={0}
|
|
181
|
+
id={`${this.doShowTextInput ? 'text-input' : 'select-input'}`}
|
|
182
|
+
title={this.doShowTextInput
|
|
183
|
+
? LocationListRenderer.Tooltips.TOGGLE_SELECT_INPUT
|
|
184
|
+
: LocationListRenderer.Tooltips.TOGGLE_TEXT_INPUT}
|
|
185
|
+
ref={this.doAfterRender}
|
|
186
|
+
>
|
|
187
|
+
<i className={codicon(this.doShowTextInput ? 'folder-opened' : 'edit')} />
|
|
188
|
+
</span>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
protected renderTextInput(): React.ReactNode {
|
|
193
|
+
return (
|
|
194
|
+
<input className={'theia-select ' + LocationListRenderer.Styles.LOCATION_TEXT_INPUT_CLASS}
|
|
195
|
+
defaultValue={this.service.location?.path.fsPath()}
|
|
196
|
+
onBlur={this.handleTextInputOnBlur}
|
|
197
|
+
onChange={this.handleTextInputOnChange}
|
|
198
|
+
onKeyDown={this.handleTextInputKeyDown}
|
|
199
|
+
spellCheck={false}
|
|
200
|
+
/>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
protected renderSelectInput(): React.ReactNode {
|
|
205
|
+
const options = this.collectLocations().map(value => this.renderLocation(value));
|
|
206
|
+
return (
|
|
207
|
+
<select className={`theia-select ${LocationListRenderer.Styles.LOCATION_LIST_CLASS}`}
|
|
208
|
+
onChange={this.handleLocationChanged}>
|
|
209
|
+
{...options}
|
|
210
|
+
</select>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
protected toggleInputOnKeyDown(e: React.KeyboardEvent<HTMLSpanElement>): void {
|
|
215
|
+
if (e.key === 'Enter') {
|
|
216
|
+
this.doShowTextInput = true;
|
|
217
|
+
this.render();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
protected toggleToTextInputOnMouseDown(e: React.MouseEvent<HTMLSpanElement>): void {
|
|
222
|
+
if (e.currentTarget.id === 'select-input') {
|
|
223
|
+
e.preventDefault();
|
|
224
|
+
this.doShowTextInput = true;
|
|
225
|
+
this.render();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
protected toggleToSelectInput(): void {
|
|
230
|
+
if (this.doShowTextInput) {
|
|
231
|
+
this.doShowTextInput = false;
|
|
232
|
+
this.render();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Collects the available locations based on the currently selected, and appends the available drives to it.
|
|
238
|
+
*/
|
|
239
|
+
protected collectLocations(): LocationListRenderer.Location[] {
|
|
240
|
+
const location = this.service.location;
|
|
241
|
+
const locations: LocationListRenderer.Location[] = (!!location ? location.allLocations : []).map(uri => ({ uri }));
|
|
242
|
+
if (this._drives) {
|
|
243
|
+
const drives = this._drives.map(uri => ({ uri, isDrive: true }));
|
|
244
|
+
// `URI.allLocations` returns with the URI without the trailing slash unlike `FileUri.create(fsPath)`.
|
|
245
|
+
// to be able to compare file:///path/to/resource with file:///path/to/resource/.
|
|
246
|
+
const toUriString = (uri: URI) => {
|
|
247
|
+
const toString = uri.toString();
|
|
248
|
+
return toString.endsWith('/') ? toString.slice(0, -1) : toString;
|
|
249
|
+
};
|
|
250
|
+
drives.forEach(drive => {
|
|
251
|
+
const index = locations.findIndex(loc => toUriString(loc.uri) === toUriString(drive.uri));
|
|
252
|
+
// Ignore drives which are already discovered as a location based on the current model root URI.
|
|
253
|
+
if (index === -1) {
|
|
254
|
+
// Make sure, it does not have the trailing slash.
|
|
255
|
+
locations.push({ uri: new URI(toUriString(drive.uri)), isDrive: true });
|
|
256
|
+
} else {
|
|
257
|
+
// This is necessary for Windows to be able to show `/e:/` as a drive and `c:` as "non-drive" in the same way.
|
|
258
|
+
// `URI.path.toString()` Vs. `URI.displayName` behaves a bit differently on Windows.
|
|
259
|
+
// https://github.com/eclipse-theia/theia/pull/3038#issuecomment-425944189
|
|
260
|
+
locations[index].isDrive = true;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
this.doLoadDrives();
|
|
265
|
+
return locations;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Asynchronously loads the drives (if not yet available) and triggers a UI update on success with the new values.
|
|
270
|
+
*/
|
|
271
|
+
protected doLoadDrives(): void {
|
|
272
|
+
if (!this._drives) {
|
|
273
|
+
this.service.drives().then(drives => {
|
|
274
|
+
// If the `drives` are empty, something already went wrong.
|
|
275
|
+
if (drives.length > 0) {
|
|
276
|
+
this._drives = drives;
|
|
277
|
+
this.render();
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
protected renderLocation(location: LocationListRenderer.Location): React.ReactNode {
|
|
284
|
+
const { uri, isDrive } = location;
|
|
285
|
+
const value = uri.toString();
|
|
286
|
+
return <option value={value} key={uri.toString()}>{isDrive ? uri.path.fsPath() : uri.displayName}</option>;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
protected onLocationChanged(e: React.ChangeEvent<HTMLSelectElement>): void {
|
|
290
|
+
const locationList = this.locationList;
|
|
291
|
+
if (locationList) {
|
|
292
|
+
const value = locationList.value;
|
|
293
|
+
const uri = new URI(value);
|
|
294
|
+
this.trySetNewLocation(uri);
|
|
295
|
+
e.preventDefault();
|
|
296
|
+
e.stopPropagation();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
protected trySetNewLocation(newLocation: URI): void {
|
|
301
|
+
if (this.lastUniqueTextInputLocation === undefined) {
|
|
302
|
+
this.lastUniqueTextInputLocation = this.service.location;
|
|
303
|
+
}
|
|
304
|
+
// prevent consecutive repeated locations from being added to location history
|
|
305
|
+
if (this.lastUniqueTextInputLocation?.path.toString() !== newLocation.path.toString()) {
|
|
306
|
+
this.lastUniqueTextInputLocation = newLocation;
|
|
307
|
+
this.service.location = newLocation;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
protected trySuggestDirectory(e: React.ChangeEvent<HTMLInputElement>): void {
|
|
312
|
+
if (this.doAttemptAutocomplete) {
|
|
313
|
+
const inputElement = e.currentTarget;
|
|
314
|
+
const { value } = inputElement;
|
|
315
|
+
if ((value.startsWith('/') || value.startsWith('~/')) && value.slice(-1) !== '/') {
|
|
316
|
+
const expandedPath = Path.untildify(value, this.homeDir);
|
|
317
|
+
const valueAsURI = new URI(expandedPath);
|
|
318
|
+
const autocompleteDirectories = this.directoryCache.tryResolveChildDirectories(valueAsURI);
|
|
319
|
+
if (autocompleteDirectories) {
|
|
320
|
+
this.tryRenderFirstMatch(inputElement, autocompleteDirectories);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
protected tryRenderFirstMatch(inputElement: HTMLInputElement, children: string[]): void {
|
|
327
|
+
const { value, selectionStart } = inputElement;
|
|
328
|
+
if (this.locationTextInput) {
|
|
329
|
+
const expandedPath = Path.untildify(value, this.homeDir);
|
|
330
|
+
const firstMatch = children?.find(child => child.includes(expandedPath));
|
|
331
|
+
if (firstMatch) {
|
|
332
|
+
const contractedPath = value.startsWith('~') ? Path.tildify(firstMatch, this.homeDir) : firstMatch;
|
|
333
|
+
this.locationTextInput.value = contractedPath;
|
|
334
|
+
this.locationTextInput.selectionStart = selectionStart;
|
|
335
|
+
this.locationTextInput.selectionEnd = firstMatch.length;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
protected handleControlKeys(e: React.KeyboardEvent<HTMLInputElement>): void {
|
|
341
|
+
this.doAttemptAutocomplete = e.key !== 'Backspace';
|
|
342
|
+
if (e.key === 'Enter') {
|
|
343
|
+
const locationTextInput = this.locationTextInput;
|
|
344
|
+
if (locationTextInput) {
|
|
345
|
+
// expand '~' if present and remove extra whitespace and any trailing slashes or periods.
|
|
346
|
+
const sanitizedInput = locationTextInput.value.trim().replace(/[\/\\.]*$/, '');
|
|
347
|
+
const untildifiedInput = Path.untildify(sanitizedInput, this.homeDir);
|
|
348
|
+
const uri = new URI(untildifiedInput);
|
|
349
|
+
this.trySetNewLocation(uri);
|
|
350
|
+
this.toggleToSelectInput();
|
|
351
|
+
}
|
|
352
|
+
} else if (e.key === 'Escape') {
|
|
353
|
+
this.toggleToSelectInput();
|
|
354
|
+
} else if (e.key === 'Tab') {
|
|
355
|
+
e.preventDefault();
|
|
356
|
+
const textInput = this.locationTextInput;
|
|
357
|
+
if (textInput) {
|
|
358
|
+
textInput.selectionStart = textInput.value.length;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
e.stopPropagation();
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
get locationList(): HTMLSelectElement | undefined {
|
|
365
|
+
const locationList = this.host.getElementsByClassName(LocationListRenderer.Styles.LOCATION_LIST_CLASS)[0];
|
|
366
|
+
if (locationList instanceof HTMLSelectElement) {
|
|
367
|
+
return locationList;
|
|
368
|
+
}
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
get locationTextInput(): HTMLInputElement | undefined {
|
|
373
|
+
const locationTextInput = this.host.getElementsByClassName(LocationListRenderer.Styles.LOCATION_TEXT_INPUT_CLASS)[0];
|
|
374
|
+
if (locationTextInput instanceof HTMLInputElement) {
|
|
375
|
+
return locationTextInput;
|
|
376
|
+
}
|
|
377
|
+
return undefined;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
override dispose(): void {
|
|
381
|
+
super.dispose();
|
|
382
|
+
this.toDisposeOnNewCache.dispose();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export namespace LocationListRenderer {
|
|
387
|
+
|
|
388
|
+
export namespace Styles {
|
|
389
|
+
export const LOCATION_LIST_CLASS = 'theia-LocationList';
|
|
390
|
+
export const LOCATION_INPUT_TOGGLE_CLASS = 'theia-LocationInputToggle';
|
|
391
|
+
export const LOCATION_TEXT_INPUT_CLASS = 'theia-LocationTextInput';
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export namespace Tooltips {
|
|
395
|
+
export const TOGGLE_TEXT_INPUT = 'Switch to text-based input';
|
|
396
|
+
export const TOGGLE_SELECT_INPUT = 'Switch to location list';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export interface Location {
|
|
400
|
+
uri: URI;
|
|
401
|
+
isDrive?: boolean;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
}
|