@codingame/monaco-vscode-api 1.79.2-next.0 → 1.79.2-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rollup-vsix-plugin.js +1 -1
- package/dist/service-override/dialogs.js +16 -1
- package/dist/vscode/vs/platform/window/common/window.js +7 -1
- package/dist/vscode/vs/workbench/services/dialogs/browser/abstractFileDialogService.js +302 -0
- package/dist/vscode/vs/workbench/services/dialogs/browser/simpleFileDialog.js +971 -0
- package/package.json +1 -1
|
@@ -81,7 +81,7 @@ function plugin({ include = '**/*.vsix', exclude, rollupPlugins, withCode = () =
|
|
|
81
81
|
map: { mappings: '' }
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
const content = vsixFile[resourcePath];
|
|
84
|
+
const content = vsixFile[getVsixPath(resourcePath)];
|
|
85
85
|
if (isBinaryFileSync_1(content)) {
|
|
86
86
|
return {
|
|
87
87
|
code: `export default Uint8Array.from(window.atob(${JSON.stringify(content.toString('base64'))}), v => v.charCodeAt(0));`,
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import '../vscode-services/missing-services.js';
|
|
2
2
|
import '../vscode/vs/workbench/browser/parts/dialogs/dialog.web.contribution.js';
|
|
3
3
|
import { DialogService } from '../vscode/vs/workbench/services/dialogs/common/dialogService.js';
|
|
4
|
-
import { IDialogService } from 'monaco-editor/esm/vs/platform/dialogs/common/dialogs.js';
|
|
4
|
+
import { IDialogService, IFileDialogService } from 'monaco-editor/esm/vs/platform/dialogs/common/dialogs.js';
|
|
5
5
|
import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/common/descriptors.js';
|
|
6
|
+
import { AbstractFileDialogService } from '../vscode/vs/workbench/services/dialogs/browser/abstractFileDialogService.js';
|
|
6
7
|
import getServiceOverride$1 from './layout.js';
|
|
8
|
+
import { unsupported } from '../tools.js';
|
|
9
|
+
class FileDialogService extends AbstractFileDialogService {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.pickFileFolderAndOpen = unsupported;
|
|
13
|
+
this.pickFileAndOpen = unsupported;
|
|
14
|
+
this.pickFolderAndOpen = unsupported;
|
|
15
|
+
this.pickWorkspaceAndOpen = unsupported;
|
|
16
|
+
this.showSaveDialog = unsupported;
|
|
17
|
+
this.showOpenDialog = unsupported;
|
|
18
|
+
this.pickFileToSave = unsupported;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
7
21
|
function getServiceOverride(container) {
|
|
8
22
|
return {
|
|
9
23
|
[( IDialogService.toString())]: new SyncDescriptor(DialogService, undefined, true),
|
|
24
|
+
[( IFileDialogService.toString())]: new SyncDescriptor(FileDialogService, undefined, true),
|
|
10
25
|
...getServiceOverride$1(container)
|
|
11
26
|
};
|
|
12
27
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { isMacintosh, isNative, isWeb, isLinux } from 'monaco-editor/esm/vs/base/common/platform.js';
|
|
2
|
+
function isWorkspaceToOpen(uriToOpen) {
|
|
3
|
+
return !!uriToOpen.workspaceUri;
|
|
4
|
+
}
|
|
5
|
+
function isFileToOpen(uriToOpen) {
|
|
6
|
+
return !!uriToOpen.fileUri;
|
|
7
|
+
}
|
|
2
8
|
function getMenuBarVisibility(configurationService) {
|
|
3
9
|
const titleBarStyle = getTitleBarStyle(configurationService);
|
|
4
10
|
const menuBarVisibility = configurationService.getValue('window.menuBarVisibility');
|
|
@@ -30,4 +36,4 @@ function getTitleBarStyle(configurationService) {
|
|
|
30
36
|
}
|
|
31
37
|
return isLinux ? 'native' : 'custom';
|
|
32
38
|
}
|
|
33
|
-
export { getMenuBarVisibility, getTitleBarStyle };
|
|
39
|
+
export { getMenuBarVisibility, getTitleBarStyle, isFileToOpen, isWorkspaceToOpen };
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import * as nls from 'monaco-editor/esm/vs/nls.js';
|
|
3
|
+
import { isWorkspaceToOpen, isFileToOpen } from '../../../../platform/window/common/window.js';
|
|
4
|
+
import { getFileNamesMessage, IDialogService } from 'monaco-editor/esm/vs/platform/dialogs/common/dialogs.js';
|
|
5
|
+
import { isSavedWorkspace, isTemporaryWorkspace, IWorkspaceContextService, WORKSPACE_EXTENSION } from 'monaco-editor/esm/vs/platform/workspace/common/workspace.js';
|
|
6
|
+
import { IHistoryService } from '../../history/common/history.js';
|
|
7
|
+
import { IWorkbenchEnvironmentService } from '../../environment/common/environmentService.js';
|
|
8
|
+
import * as resources from 'monaco-editor/esm/vs/base/common/resources.js';
|
|
9
|
+
import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
|
|
10
|
+
import { SimpleFileDialog } from './simpleFileDialog.js';
|
|
11
|
+
import { IWorkspacesService } from '../../../../platform/workspaces/common/workspaces.js';
|
|
12
|
+
import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
|
|
13
|
+
import { IFileService } from 'monaco-editor/esm/vs/platform/files/common/files.js';
|
|
14
|
+
import { IOpenerService } from 'monaco-editor/esm/vs/platform/opener/common/opener.js';
|
|
15
|
+
import { IHostService } from '../../host/browser/host.js';
|
|
16
|
+
import Severity from 'monaco-editor/esm/vs/base/common/severity.js';
|
|
17
|
+
import { coalesce, distinct } from 'monaco-editor/esm/vs/base/common/arrays.js';
|
|
18
|
+
import { trim } from 'monaco-editor/esm/vs/base/common/strings.js';
|
|
19
|
+
import { ILanguageService } from 'monaco-editor/esm/vs/editor/common/languages/language.js';
|
|
20
|
+
import { ILabelService } from 'monaco-editor/esm/vs/platform/label/common/label.js';
|
|
21
|
+
import { IPathService } from '../../path/common/pathService.js';
|
|
22
|
+
import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
|
|
23
|
+
import { PLAINTEXT_EXTENSION } from 'monaco-editor/esm/vs/editor/common/languages/modesRegistry.js';
|
|
24
|
+
import { ICommandService } from 'monaco-editor/esm/vs/platform/commands/common/commands.js';
|
|
25
|
+
import { ICodeEditorService } from 'monaco-editor/esm/vs/editor/browser/services/codeEditorService.js';
|
|
26
|
+
import { IEditorService } from '../../editor/common/editorService.js';
|
|
27
|
+
import { EditorOpenSource } from 'monaco-editor/esm/vs/platform/editor/common/editor.js';
|
|
28
|
+
import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
|
|
29
|
+
let AbstractFileDialogService = class AbstractFileDialogService {
|
|
30
|
+
constructor(hostService, contextService, historyService, environmentService, instantiationService, configurationService, fileService, openerService, dialogService, languageService, workspacesService, labelService, pathService, commandService, editorService, codeEditorService, logService) {
|
|
31
|
+
this.hostService = hostService;
|
|
32
|
+
this.contextService = contextService;
|
|
33
|
+
this.historyService = historyService;
|
|
34
|
+
this.environmentService = environmentService;
|
|
35
|
+
this.instantiationService = instantiationService;
|
|
36
|
+
this.configurationService = configurationService;
|
|
37
|
+
this.fileService = fileService;
|
|
38
|
+
this.openerService = openerService;
|
|
39
|
+
this.dialogService = dialogService;
|
|
40
|
+
this.languageService = languageService;
|
|
41
|
+
this.workspacesService = workspacesService;
|
|
42
|
+
this.labelService = labelService;
|
|
43
|
+
this.pathService = pathService;
|
|
44
|
+
this.commandService = commandService;
|
|
45
|
+
this.editorService = editorService;
|
|
46
|
+
this.codeEditorService = codeEditorService;
|
|
47
|
+
this.logService = logService;
|
|
48
|
+
}
|
|
49
|
+
async defaultFilePath(schemeFilter = this.getSchemeFilterForWindow()) {
|
|
50
|
+
let candidate = this.historyService.getLastActiveFile(schemeFilter);
|
|
51
|
+
if (!candidate) {
|
|
52
|
+
candidate = this.historyService.getLastActiveWorkspaceRoot(schemeFilter);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
candidate = resources.dirname(candidate);
|
|
56
|
+
}
|
|
57
|
+
if (!candidate) {
|
|
58
|
+
candidate = await this.pathService.userHome({ preferLocal: schemeFilter === Schemas.file });
|
|
59
|
+
}
|
|
60
|
+
return candidate;
|
|
61
|
+
}
|
|
62
|
+
async defaultFolderPath(schemeFilter = this.getSchemeFilterForWindow()) {
|
|
63
|
+
let candidate = this.historyService.getLastActiveWorkspaceRoot(schemeFilter);
|
|
64
|
+
if (!candidate) {
|
|
65
|
+
candidate = this.historyService.getLastActiveFile(schemeFilter);
|
|
66
|
+
}
|
|
67
|
+
if (!candidate) {
|
|
68
|
+
return this.pathService.userHome({ preferLocal: schemeFilter === Schemas.file });
|
|
69
|
+
}
|
|
70
|
+
return resources.dirname(candidate);
|
|
71
|
+
}
|
|
72
|
+
async defaultWorkspacePath(schemeFilter = this.getSchemeFilterForWindow()) {
|
|
73
|
+
let defaultWorkspacePath;
|
|
74
|
+
if (this.contextService.getWorkbenchState() === 3 ) {
|
|
75
|
+
const configuration = this.contextService.getWorkspace().configuration;
|
|
76
|
+
if (configuration?.scheme === schemeFilter && isSavedWorkspace(configuration, this.environmentService) && !isTemporaryWorkspace(configuration)) {
|
|
77
|
+
defaultWorkspacePath = resources.dirname(configuration);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!defaultWorkspacePath) {
|
|
81
|
+
defaultWorkspacePath = await this.defaultFilePath(schemeFilter);
|
|
82
|
+
}
|
|
83
|
+
return defaultWorkspacePath;
|
|
84
|
+
}
|
|
85
|
+
async showSaveConfirm(fileNamesOrResources) {
|
|
86
|
+
if (this.skipDialogs()) {
|
|
87
|
+
this.logService.trace('FileDialogService: refused to show save confirmation dialog in tests.');
|
|
88
|
+
return 1 ;
|
|
89
|
+
}
|
|
90
|
+
return this.doShowSaveConfirm(fileNamesOrResources);
|
|
91
|
+
}
|
|
92
|
+
skipDialogs() {
|
|
93
|
+
if (this.environmentService.isExtensionDevelopment && this.environmentService.extensionTestsLocationURI) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return !!this.environmentService.enableSmokeTestDriver;
|
|
97
|
+
}
|
|
98
|
+
async doShowSaveConfirm(fileNamesOrResources) {
|
|
99
|
+
if (fileNamesOrResources.length === 0) {
|
|
100
|
+
return 1 ;
|
|
101
|
+
}
|
|
102
|
+
let message;
|
|
103
|
+
let detail = ( nls.localize('saveChangesDetail', "Your changes will be lost if you don't save them."));
|
|
104
|
+
if (fileNamesOrResources.length === 1) {
|
|
105
|
+
message = ( nls.localize(
|
|
106
|
+
'saveChangesMessage',
|
|
107
|
+
"Do you want to save the changes you made to {0}?",
|
|
108
|
+
typeof fileNamesOrResources[0] === 'string' ? fileNamesOrResources[0] : resources.basename(fileNamesOrResources[0])
|
|
109
|
+
));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
message = ( nls.localize(
|
|
113
|
+
'saveChangesMessages',
|
|
114
|
+
"Do you want to save the changes to the following {0} files?",
|
|
115
|
+
fileNamesOrResources.length
|
|
116
|
+
));
|
|
117
|
+
detail = getFileNamesMessage(fileNamesOrResources) + '\n' + detail;
|
|
118
|
+
}
|
|
119
|
+
const { result } = await this.dialogService.prompt({
|
|
120
|
+
type: Severity.Warning,
|
|
121
|
+
message,
|
|
122
|
+
detail,
|
|
123
|
+
buttons: [
|
|
124
|
+
{
|
|
125
|
+
label: fileNamesOrResources.length > 1 ?
|
|
126
|
+
( nls.localize({ key: 'saveAll', comment: ['&& denotes a mnemonic'] }, "&&Save All")) :
|
|
127
|
+
( nls.localize({ key: 'save', comment: ['&& denotes a mnemonic'] }, "&&Save")),
|
|
128
|
+
run: () => 0
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
label: ( nls.localize({ key: 'dontSave', comment: ['&& denotes a mnemonic'] }, "Do&&n't Save")),
|
|
132
|
+
run: () => 1
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
cancelButton: {
|
|
136
|
+
run: () => 2
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
addFileSchemaIfNeeded(schema, _isFolder) {
|
|
142
|
+
return schema === Schemas.untitled ? [Schemas.file] : (schema !== Schemas.file ? [schema, Schemas.file] : [schema]);
|
|
143
|
+
}
|
|
144
|
+
async pickFileFolderAndOpenSimplified(schema, options, preferNewWindow) {
|
|
145
|
+
const title = ( nls.localize('openFileOrFolder.title', 'Open File or Folder'));
|
|
146
|
+
const availableFileSystems = this.addFileSchemaIfNeeded(schema);
|
|
147
|
+
const uri = await this.pickResource({ canSelectFiles: true, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });
|
|
148
|
+
if (uri) {
|
|
149
|
+
const stat = await this.fileService.stat(uri);
|
|
150
|
+
const toOpen = stat.isDirectory ? { folderUri: uri } : { fileUri: uri };
|
|
151
|
+
if (!isWorkspaceToOpen(toOpen) && isFileToOpen(toOpen)) {
|
|
152
|
+
this.addFileToRecentlyOpened(toOpen.fileUri);
|
|
153
|
+
}
|
|
154
|
+
if (stat.isDirectory || options.forceNewWindow || preferNewWindow) {
|
|
155
|
+
await this.hostService.openWindow([toOpen], { forceNewWindow: options.forceNewWindow, remoteAuthority: options.remoteAuthority });
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
await this.editorService.openEditors([{ resource: uri, options: { source: EditorOpenSource.USER, pinned: true } }], undefined, { validateTrust: true });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async pickFileAndOpenSimplified(schema, options, preferNewWindow) {
|
|
163
|
+
const title = ( nls.localize('openFile.title', 'Open File'));
|
|
164
|
+
const availableFileSystems = this.addFileSchemaIfNeeded(schema);
|
|
165
|
+
const uri = await this.pickResource({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });
|
|
166
|
+
if (uri) {
|
|
167
|
+
this.addFileToRecentlyOpened(uri);
|
|
168
|
+
if (options.forceNewWindow || preferNewWindow) {
|
|
169
|
+
await this.hostService.openWindow([{ fileUri: uri }], { forceNewWindow: options.forceNewWindow, remoteAuthority: options.remoteAuthority });
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
await this.editorService.openEditors([{ resource: uri, options: { source: EditorOpenSource.USER, pinned: true } }], undefined, { validateTrust: true });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
addFileToRecentlyOpened(uri) {
|
|
177
|
+
this.workspacesService.addRecentlyOpened([{ fileUri: uri, label: this.labelService.getUriLabel(uri) }]);
|
|
178
|
+
}
|
|
179
|
+
async pickFolderAndOpenSimplified(schema, options) {
|
|
180
|
+
const title = ( nls.localize('openFolder.title', 'Open Folder'));
|
|
181
|
+
const availableFileSystems = this.addFileSchemaIfNeeded(schema, true);
|
|
182
|
+
const uri = await this.pickResource({ canSelectFiles: false, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });
|
|
183
|
+
if (uri) {
|
|
184
|
+
return this.hostService.openWindow([{ folderUri: uri }], { forceNewWindow: options.forceNewWindow, remoteAuthority: options.remoteAuthority });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async pickWorkspaceAndOpenSimplified(schema, options) {
|
|
188
|
+
const title = ( nls.localize('openWorkspace.title', 'Open Workspace from File'));
|
|
189
|
+
const filters = [{ name: ( nls.localize('filterName.workspace', 'Workspace')), extensions: [WORKSPACE_EXTENSION] }];
|
|
190
|
+
const availableFileSystems = this.addFileSchemaIfNeeded(schema, true);
|
|
191
|
+
const uri = await this.pickResource({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, filters, availableFileSystems });
|
|
192
|
+
if (uri) {
|
|
193
|
+
return this.hostService.openWindow([{ workspaceUri: uri }], { forceNewWindow: options.forceNewWindow, remoteAuthority: options.remoteAuthority });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async pickFileToSaveSimplified(schema, options) {
|
|
197
|
+
if (!options.availableFileSystems) {
|
|
198
|
+
options.availableFileSystems = this.addFileSchemaIfNeeded(schema);
|
|
199
|
+
}
|
|
200
|
+
options.title = ( nls.localize('saveFileAs.title', 'Save As'));
|
|
201
|
+
const uri = await this.saveRemoteResource(options);
|
|
202
|
+
if (uri) {
|
|
203
|
+
this.addFileToRecentlyOpened(uri);
|
|
204
|
+
}
|
|
205
|
+
return uri;
|
|
206
|
+
}
|
|
207
|
+
async showSaveDialogSimplified(schema, options) {
|
|
208
|
+
if (!options.availableFileSystems) {
|
|
209
|
+
options.availableFileSystems = this.addFileSchemaIfNeeded(schema);
|
|
210
|
+
}
|
|
211
|
+
return this.saveRemoteResource(options);
|
|
212
|
+
}
|
|
213
|
+
async showOpenDialogSimplified(schema, options) {
|
|
214
|
+
if (!options.availableFileSystems) {
|
|
215
|
+
options.availableFileSystems = this.addFileSchemaIfNeeded(schema, options.canSelectFolders);
|
|
216
|
+
}
|
|
217
|
+
const uri = await this.pickResource(options);
|
|
218
|
+
return uri ? [uri] : undefined;
|
|
219
|
+
}
|
|
220
|
+
getSimpleFileDialog() {
|
|
221
|
+
return this.instantiationService.createInstance(SimpleFileDialog);
|
|
222
|
+
}
|
|
223
|
+
pickResource(options) {
|
|
224
|
+
return this.getSimpleFileDialog().showOpenDialog(options);
|
|
225
|
+
}
|
|
226
|
+
saveRemoteResource(options) {
|
|
227
|
+
return this.getSimpleFileDialog().showSaveDialog(options);
|
|
228
|
+
}
|
|
229
|
+
getSchemeFilterForWindow(defaultUriScheme) {
|
|
230
|
+
return defaultUriScheme ?? this.pathService.defaultUriScheme;
|
|
231
|
+
}
|
|
232
|
+
getFileSystemSchema(options) {
|
|
233
|
+
return options.availableFileSystems && options.availableFileSystems[0] || this.getSchemeFilterForWindow(options.defaultUri?.scheme);
|
|
234
|
+
}
|
|
235
|
+
getWorkspaceAvailableFileSystems(options) {
|
|
236
|
+
if (options.availableFileSystems && (options.availableFileSystems.length > 0)) {
|
|
237
|
+
return options.availableFileSystems;
|
|
238
|
+
}
|
|
239
|
+
const availableFileSystems = [Schemas.file];
|
|
240
|
+
if (this.environmentService.remoteAuthority) {
|
|
241
|
+
availableFileSystems.unshift(Schemas.vscodeRemote);
|
|
242
|
+
}
|
|
243
|
+
return availableFileSystems;
|
|
244
|
+
}
|
|
245
|
+
getPickFileToSaveDialogOptions(defaultUri, availableFileSystems) {
|
|
246
|
+
const options = {
|
|
247
|
+
defaultUri,
|
|
248
|
+
title: ( nls.localize('saveAsTitle', "Save As")),
|
|
249
|
+
availableFileSystems
|
|
250
|
+
};
|
|
251
|
+
const ext = defaultUri ? resources.extname(defaultUri) : undefined;
|
|
252
|
+
let matchingFilter;
|
|
253
|
+
const registeredLanguageNames = this.languageService.getSortedRegisteredLanguageNames();
|
|
254
|
+
const registeredLanguageFilters = coalesce(( registeredLanguageNames.map(({ languageName, languageId }) => {
|
|
255
|
+
const extensions = this.languageService.getExtensions(languageId);
|
|
256
|
+
if (!extensions.length) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const filter = { name: languageName, extensions: ( distinct(extensions).slice(0, 10).map(e => trim(e, '.'))) };
|
|
260
|
+
const extOrPlaintext = ext || PLAINTEXT_EXTENSION;
|
|
261
|
+
if (!matchingFilter && extensions.includes(extOrPlaintext)) {
|
|
262
|
+
matchingFilter = filter;
|
|
263
|
+
const trimmedExt = trim(extOrPlaintext, '.');
|
|
264
|
+
if (!filter.extensions.includes(trimmedExt)) {
|
|
265
|
+
filter.extensions.unshift(trimmedExt);
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
return filter;
|
|
270
|
+
})));
|
|
271
|
+
if (!matchingFilter && ext) {
|
|
272
|
+
matchingFilter = { name: trim(ext, '.').toUpperCase(), extensions: [trim(ext, '.')] };
|
|
273
|
+
}
|
|
274
|
+
options.filters = coalesce([
|
|
275
|
+
{ name: ( nls.localize('allFiles', "All Files")), extensions: ['*'] },
|
|
276
|
+
matchingFilter,
|
|
277
|
+
...registeredLanguageFilters,
|
|
278
|
+
{ name: ( nls.localize('noExt', "No Extension")), extensions: [''] }
|
|
279
|
+
]);
|
|
280
|
+
return options;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
AbstractFileDialogService = ( __decorate([
|
|
284
|
+
( __param(0, IHostService)),
|
|
285
|
+
( __param(1, IWorkspaceContextService)),
|
|
286
|
+
( __param(2, IHistoryService)),
|
|
287
|
+
( __param(3, IWorkbenchEnvironmentService)),
|
|
288
|
+
( __param(4, IInstantiationService)),
|
|
289
|
+
( __param(5, IConfigurationService)),
|
|
290
|
+
( __param(6, IFileService)),
|
|
291
|
+
( __param(7, IOpenerService)),
|
|
292
|
+
( __param(8, IDialogService)),
|
|
293
|
+
( __param(9, ILanguageService)),
|
|
294
|
+
( __param(10, IWorkspacesService)),
|
|
295
|
+
( __param(11, ILabelService)),
|
|
296
|
+
( __param(12, IPathService)),
|
|
297
|
+
( __param(13, ICommandService)),
|
|
298
|
+
( __param(14, IEditorService)),
|
|
299
|
+
( __param(15, ICodeEditorService)),
|
|
300
|
+
( __param(16, ILogService))
|
|
301
|
+
], AbstractFileDialogService));
|
|
302
|
+
export { AbstractFileDialogService };
|
|
@@ -0,0 +1,971 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import * as nls from 'monaco-editor/esm/vs/nls.js';
|
|
3
|
+
import * as resources from 'monaco-editor/esm/vs/base/common/resources.js';
|
|
4
|
+
import * as objects from 'monaco-editor/esm/vs/base/common/objects.js';
|
|
5
|
+
import { FileKind, IFileService } from 'monaco-editor/esm/vs/platform/files/common/files.js';
|
|
6
|
+
import { IQuickInputService } from 'monaco-editor/esm/vs/platform/quickinput/common/quickInput.js';
|
|
7
|
+
import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
|
|
8
|
+
import { isWindows } from 'monaco-editor/esm/vs/base/common/platform.js';
|
|
9
|
+
import { IFileDialogService } from 'monaco-editor/esm/vs/platform/dialogs/common/dialogs.js';
|
|
10
|
+
import { ILabelService } from 'monaco-editor/esm/vs/platform/label/common/label.js';
|
|
11
|
+
import { IWorkspaceContextService } from 'monaco-editor/esm/vs/platform/workspace/common/workspace.js';
|
|
12
|
+
import { INotificationService } from 'monaco-editor/esm/vs/platform/notification/common/notification.js';
|
|
13
|
+
import { IModelService } from 'monaco-editor/esm/vs/editor/common/services/model.js';
|
|
14
|
+
import { ILanguageService } from 'monaco-editor/esm/vs/editor/common/languages/language.js';
|
|
15
|
+
import { getIconClasses } from 'monaco-editor/esm/vs/editor/common/services/getIconClasses.js';
|
|
16
|
+
import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
|
|
17
|
+
import { IWorkbenchEnvironmentService } from '../../environment/common/environmentService.js';
|
|
18
|
+
import { IRemoteAgentService } from '../../remote/common/remoteAgentService.js';
|
|
19
|
+
import { IContextKeyService, RawContextKey } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey.js';
|
|
20
|
+
import { format, equalsIgnoreCase, startsWithIgnoreCase } from 'monaco-editor/esm/vs/base/common/strings.js';
|
|
21
|
+
import { IKeybindingService } from 'monaco-editor/esm/vs/platform/keybinding/common/keybinding.js';
|
|
22
|
+
import { isValidBasename } from 'monaco-editor/esm/vs/base/common/extpath.js';
|
|
23
|
+
import { Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
|
|
24
|
+
import { dispose } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
|
|
25
|
+
import { createCancelablePromise } from 'monaco-editor/esm/vs/base/common/async.js';
|
|
26
|
+
import { IEditorService } from '../../editor/common/editorService.js';
|
|
27
|
+
import { normalizeDriveLetter } from 'monaco-editor/esm/vs/base/common/labels.js';
|
|
28
|
+
import { IPathService } from '../../path/common/pathService.js';
|
|
29
|
+
import { IAccessibilityService } from 'monaco-editor/esm/vs/platform/accessibility/common/accessibility.js';
|
|
30
|
+
var OpenLocalFileCommand;
|
|
31
|
+
( (function(OpenLocalFileCommand) {
|
|
32
|
+
OpenLocalFileCommand.ID = 'workbench.action.files.openLocalFile';
|
|
33
|
+
OpenLocalFileCommand.LABEL = ( nls.localize('openLocalFile', "Open Local File..."));
|
|
34
|
+
function handler() {
|
|
35
|
+
return accessor => {
|
|
36
|
+
const dialogService = accessor.get(IFileDialogService);
|
|
37
|
+
return dialogService.pickFileAndOpen({ forceNewWindow: false, availableFileSystems: [Schemas.file] });
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
OpenLocalFileCommand.handler = handler;
|
|
41
|
+
})(OpenLocalFileCommand || (OpenLocalFileCommand = {})));
|
|
42
|
+
var SaveLocalFileCommand;
|
|
43
|
+
( (function(SaveLocalFileCommand) {
|
|
44
|
+
SaveLocalFileCommand.ID = 'workbench.action.files.saveLocalFile';
|
|
45
|
+
SaveLocalFileCommand.LABEL = ( nls.localize('saveLocalFile', "Save Local File..."));
|
|
46
|
+
function handler() {
|
|
47
|
+
return accessor => {
|
|
48
|
+
const editorService = accessor.get(IEditorService);
|
|
49
|
+
const activeEditorPane = editorService.activeEditorPane;
|
|
50
|
+
if (activeEditorPane) {
|
|
51
|
+
return editorService.save({ groupId: activeEditorPane.group.id, editor: activeEditorPane.input }, { saveAs: true, availableFileSystems: [Schemas.file], reason: 1 });
|
|
52
|
+
}
|
|
53
|
+
return Promise.resolve(undefined);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
SaveLocalFileCommand.handler = handler;
|
|
57
|
+
})(SaveLocalFileCommand || (SaveLocalFileCommand = {})));
|
|
58
|
+
var OpenLocalFolderCommand;
|
|
59
|
+
( (function(OpenLocalFolderCommand) {
|
|
60
|
+
OpenLocalFolderCommand.ID = 'workbench.action.files.openLocalFolder';
|
|
61
|
+
OpenLocalFolderCommand.LABEL = ( nls.localize('openLocalFolder', "Open Local Folder..."));
|
|
62
|
+
function handler() {
|
|
63
|
+
return accessor => {
|
|
64
|
+
const dialogService = accessor.get(IFileDialogService);
|
|
65
|
+
return dialogService.pickFolderAndOpen({ forceNewWindow: false, availableFileSystems: [Schemas.file] });
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
OpenLocalFolderCommand.handler = handler;
|
|
69
|
+
})(OpenLocalFolderCommand || (OpenLocalFolderCommand = {})));
|
|
70
|
+
var OpenLocalFileFolderCommand;
|
|
71
|
+
( (function(OpenLocalFileFolderCommand) {
|
|
72
|
+
OpenLocalFileFolderCommand.ID = 'workbench.action.files.openLocalFileFolder';
|
|
73
|
+
OpenLocalFileFolderCommand.LABEL = ( nls.localize('openLocalFileFolder', "Open Local..."));
|
|
74
|
+
function handler() {
|
|
75
|
+
return accessor => {
|
|
76
|
+
const dialogService = accessor.get(IFileDialogService);
|
|
77
|
+
return dialogService.pickFileFolderAndOpen({ forceNewWindow: false, availableFileSystems: [Schemas.file] });
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
OpenLocalFileFolderCommand.handler = handler;
|
|
81
|
+
})(OpenLocalFileFolderCommand || (OpenLocalFileFolderCommand = {})));
|
|
82
|
+
var UpdateResult;
|
|
83
|
+
( (function(UpdateResult) {
|
|
84
|
+
UpdateResult[UpdateResult["Updated"] = 0] = "Updated";
|
|
85
|
+
UpdateResult[UpdateResult["UpdatedWithTrailing"] = 1] = "UpdatedWithTrailing";
|
|
86
|
+
UpdateResult[UpdateResult["Updating"] = 2] = "Updating";
|
|
87
|
+
UpdateResult[UpdateResult["NotUpdated"] = 3] = "NotUpdated";
|
|
88
|
+
UpdateResult[UpdateResult["InvalidPath"] = 4] = "InvalidPath";
|
|
89
|
+
})(UpdateResult || (UpdateResult = {})));
|
|
90
|
+
const RemoteFileDialogContext = ( new RawContextKey('remoteFileDialogVisible', false));
|
|
91
|
+
let SimpleFileDialog = class SimpleFileDialog {
|
|
92
|
+
constructor(fileService, quickInputService, labelService, workspaceContextService, notificationService, fileDialogService, modelService, languageService, environmentService, remoteAgentService, pathService, keybindingService, contextKeyService, accessibilityService) {
|
|
93
|
+
this.fileService = fileService;
|
|
94
|
+
this.quickInputService = quickInputService;
|
|
95
|
+
this.labelService = labelService;
|
|
96
|
+
this.workspaceContextService = workspaceContextService;
|
|
97
|
+
this.notificationService = notificationService;
|
|
98
|
+
this.fileDialogService = fileDialogService;
|
|
99
|
+
this.modelService = modelService;
|
|
100
|
+
this.languageService = languageService;
|
|
101
|
+
this.environmentService = environmentService;
|
|
102
|
+
this.remoteAgentService = remoteAgentService;
|
|
103
|
+
this.pathService = pathService;
|
|
104
|
+
this.keybindingService = keybindingService;
|
|
105
|
+
this.accessibilityService = accessibilityService;
|
|
106
|
+
this.hidden = false;
|
|
107
|
+
this.allowFileSelection = true;
|
|
108
|
+
this.allowFolderSelection = false;
|
|
109
|
+
this.requiresTrailing = false;
|
|
110
|
+
this.userEnteredPathSegment = '';
|
|
111
|
+
this.autoCompletePathSegment = '';
|
|
112
|
+
this.isWindows = false;
|
|
113
|
+
this.separator = '/';
|
|
114
|
+
this.onBusyChangeEmitter = ( new Emitter());
|
|
115
|
+
this.disposables = [
|
|
116
|
+
this.onBusyChangeEmitter
|
|
117
|
+
];
|
|
118
|
+
this.remoteAuthority = this.environmentService.remoteAuthority;
|
|
119
|
+
this.contextKey = RemoteFileDialogContext.bindTo(contextKeyService);
|
|
120
|
+
this.scheme = this.pathService.defaultUriScheme;
|
|
121
|
+
}
|
|
122
|
+
set busy(busy) {
|
|
123
|
+
if (this.filePickBox.busy !== busy) {
|
|
124
|
+
this.filePickBox.busy = busy;
|
|
125
|
+
this.onBusyChangeEmitter.fire(busy);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
get busy() {
|
|
129
|
+
return this.filePickBox.busy;
|
|
130
|
+
}
|
|
131
|
+
async showOpenDialog(options = {}) {
|
|
132
|
+
this.scheme = this.getScheme(options.availableFileSystems, options.defaultUri);
|
|
133
|
+
this.userHome = await this.getUserHome();
|
|
134
|
+
const newOptions = this.getOptions(options);
|
|
135
|
+
if (!newOptions) {
|
|
136
|
+
return Promise.resolve(undefined);
|
|
137
|
+
}
|
|
138
|
+
this.options = newOptions;
|
|
139
|
+
return this.pickResource();
|
|
140
|
+
}
|
|
141
|
+
async showSaveDialog(options) {
|
|
142
|
+
this.scheme = this.getScheme(options.availableFileSystems, options.defaultUri);
|
|
143
|
+
this.userHome = await this.getUserHome();
|
|
144
|
+
this.requiresTrailing = true;
|
|
145
|
+
const newOptions = this.getOptions(options, true);
|
|
146
|
+
if (!newOptions) {
|
|
147
|
+
return Promise.resolve(undefined);
|
|
148
|
+
}
|
|
149
|
+
this.options = newOptions;
|
|
150
|
+
this.options.canSelectFolders = true;
|
|
151
|
+
this.options.canSelectFiles = true;
|
|
152
|
+
return ( new Promise((resolve) => {
|
|
153
|
+
this.pickResource(true).then(folderUri => {
|
|
154
|
+
resolve(folderUri);
|
|
155
|
+
});
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
getOptions(options, isSave = false) {
|
|
159
|
+
let defaultUri = undefined;
|
|
160
|
+
let filename = undefined;
|
|
161
|
+
if (options.defaultUri) {
|
|
162
|
+
defaultUri = (this.scheme === options.defaultUri.scheme) ? options.defaultUri : undefined;
|
|
163
|
+
filename = isSave ? resources.basename(options.defaultUri) : undefined;
|
|
164
|
+
}
|
|
165
|
+
if (!defaultUri) {
|
|
166
|
+
defaultUri = this.userHome;
|
|
167
|
+
if (filename) {
|
|
168
|
+
defaultUri = resources.joinPath(defaultUri, filename);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if ((this.scheme !== Schemas.file) && !this.fileService.hasProvider(defaultUri)) {
|
|
172
|
+
this.notificationService.info(( nls.localize(
|
|
173
|
+
'remoteFileDialog.notConnectedToRemote',
|
|
174
|
+
'File system provider for {0} is not available.',
|
|
175
|
+
( defaultUri.toString())
|
|
176
|
+
)));
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
const newOptions = objects.deepClone(options);
|
|
180
|
+
newOptions.defaultUri = defaultUri;
|
|
181
|
+
return newOptions;
|
|
182
|
+
}
|
|
183
|
+
remoteUriFrom(path, hintUri) {
|
|
184
|
+
if (!path.startsWith('\\\\')) {
|
|
185
|
+
path = path.replace(/\\/g, '/');
|
|
186
|
+
}
|
|
187
|
+
const uri = this.scheme === Schemas.file ? URI.file(path) : ( URI.from(
|
|
188
|
+
{ scheme: this.scheme, path, query: hintUri?.query, fragment: hintUri?.fragment }
|
|
189
|
+
));
|
|
190
|
+
const authority = (uri.scheme === Schemas.file) ? undefined : (this.remoteAuthority ?? hintUri?.authority);
|
|
191
|
+
return resources.toLocalResource(uri, authority,
|
|
192
|
+
authority ? this.pathService.defaultUriScheme : uri.scheme);
|
|
193
|
+
}
|
|
194
|
+
getScheme(available, defaultUri) {
|
|
195
|
+
if (available && available.length > 0) {
|
|
196
|
+
if (defaultUri && (available.indexOf(defaultUri.scheme) >= 0)) {
|
|
197
|
+
return defaultUri.scheme;
|
|
198
|
+
}
|
|
199
|
+
return available[0];
|
|
200
|
+
}
|
|
201
|
+
else if (defaultUri) {
|
|
202
|
+
return defaultUri.scheme;
|
|
203
|
+
}
|
|
204
|
+
return Schemas.file;
|
|
205
|
+
}
|
|
206
|
+
async getRemoteAgentEnvironment() {
|
|
207
|
+
if (this.remoteAgentEnvironment === undefined) {
|
|
208
|
+
this.remoteAgentEnvironment = await this.remoteAgentService.getEnvironment();
|
|
209
|
+
}
|
|
210
|
+
return this.remoteAgentEnvironment;
|
|
211
|
+
}
|
|
212
|
+
getUserHome() {
|
|
213
|
+
return this.pathService.userHome({ preferLocal: this.scheme === Schemas.file });
|
|
214
|
+
}
|
|
215
|
+
async pickResource(isSave = false) {
|
|
216
|
+
this.allowFolderSelection = !!this.options.canSelectFolders;
|
|
217
|
+
this.allowFileSelection = !!this.options.canSelectFiles;
|
|
218
|
+
this.separator = this.labelService.getSeparator(this.scheme, this.remoteAuthority);
|
|
219
|
+
this.hidden = false;
|
|
220
|
+
this.isWindows = await this.checkIsWindowsOS();
|
|
221
|
+
let homedir = this.options.defaultUri ? this.options.defaultUri : this.workspaceContextService.getWorkspace().folders[0].uri;
|
|
222
|
+
let stat;
|
|
223
|
+
const ext = resources.extname(homedir);
|
|
224
|
+
if (this.options.defaultUri) {
|
|
225
|
+
try {
|
|
226
|
+
stat = await this.fileService.stat(this.options.defaultUri);
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
}
|
|
230
|
+
if (!stat || !stat.isDirectory) {
|
|
231
|
+
homedir = resources.dirname(this.options.defaultUri);
|
|
232
|
+
this.trailing = resources.basename(this.options.defaultUri);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return ( new Promise((resolve) => {
|
|
236
|
+
this.filePickBox = this.quickInputService.createQuickPick();
|
|
237
|
+
this.busy = true;
|
|
238
|
+
this.filePickBox.matchOnLabel = false;
|
|
239
|
+
this.filePickBox.sortByLabel = false;
|
|
240
|
+
this.filePickBox.autoFocusOnList = false;
|
|
241
|
+
this.filePickBox.ignoreFocusOut = true;
|
|
242
|
+
this.filePickBox.ok = true;
|
|
243
|
+
if ((this.scheme !== Schemas.file) && this.options && this.options.availableFileSystems && (this.options.availableFileSystems.length > 1) && (this.options.availableFileSystems.indexOf(Schemas.file) > -1)) {
|
|
244
|
+
this.filePickBox.customButton = true;
|
|
245
|
+
this.filePickBox.customLabel = ( nls.localize('remoteFileDialog.local', 'Show Local'));
|
|
246
|
+
let action;
|
|
247
|
+
if (isSave) {
|
|
248
|
+
action = SaveLocalFileCommand;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
action = this.allowFileSelection ? (this.allowFolderSelection ? OpenLocalFileFolderCommand : OpenLocalFileCommand) : OpenLocalFolderCommand;
|
|
252
|
+
}
|
|
253
|
+
const keybinding = this.keybindingService.lookupKeybinding(action.ID);
|
|
254
|
+
if (keybinding) {
|
|
255
|
+
const label = keybinding.getLabel();
|
|
256
|
+
if (label) {
|
|
257
|
+
this.filePickBox.customHover = format('{0} ({1})', action.LABEL, label);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
let isResolving = 0;
|
|
262
|
+
let isAcceptHandled = false;
|
|
263
|
+
this.currentFolder = resources.dirname(homedir);
|
|
264
|
+
this.userEnteredPathSegment = '';
|
|
265
|
+
this.autoCompletePathSegment = '';
|
|
266
|
+
this.filePickBox.title = this.options.title;
|
|
267
|
+
this.filePickBox.value = this.pathFromUri(this.currentFolder, true);
|
|
268
|
+
this.filePickBox.valueSelection = [this.filePickBox.value.length, this.filePickBox.value.length];
|
|
269
|
+
this.filePickBox.items = [];
|
|
270
|
+
function doResolve(dialog, uri) {
|
|
271
|
+
if (uri) {
|
|
272
|
+
uri = resources.addTrailingPathSeparator(uri, dialog.separator);
|
|
273
|
+
uri = resources.removeTrailingPathSeparator(uri);
|
|
274
|
+
}
|
|
275
|
+
resolve(uri);
|
|
276
|
+
dialog.contextKey.set(false);
|
|
277
|
+
dialog.filePickBox.dispose();
|
|
278
|
+
dispose(dialog.disposables);
|
|
279
|
+
}
|
|
280
|
+
this.filePickBox.onDidCustom(() => {
|
|
281
|
+
if (isAcceptHandled || this.busy) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
isAcceptHandled = true;
|
|
285
|
+
isResolving++;
|
|
286
|
+
if (this.options.availableFileSystems && (this.options.availableFileSystems.length > 1)) {
|
|
287
|
+
this.options.availableFileSystems = this.options.availableFileSystems.slice(1);
|
|
288
|
+
}
|
|
289
|
+
this.filePickBox.hide();
|
|
290
|
+
if (isSave) {
|
|
291
|
+
return this.fileDialogService.showSaveDialog(this.options).then(result => {
|
|
292
|
+
doResolve(this, result);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
return this.fileDialogService.showOpenDialog(this.options).then(result => {
|
|
297
|
+
doResolve(this, result ? result[0] : undefined);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
function handleAccept(dialog) {
|
|
302
|
+
if (dialog.busy) {
|
|
303
|
+
dialog.onBusyChangeEmitter.event((busy) => {
|
|
304
|
+
if (!busy) {
|
|
305
|
+
handleAccept(dialog);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
else if (isAcceptHandled) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
isAcceptHandled = true;
|
|
314
|
+
isResolving++;
|
|
315
|
+
dialog.onDidAccept().then(resolveValue => {
|
|
316
|
+
if (resolveValue) {
|
|
317
|
+
dialog.filePickBox.hide();
|
|
318
|
+
doResolve(dialog, resolveValue);
|
|
319
|
+
}
|
|
320
|
+
else if (dialog.hidden) {
|
|
321
|
+
doResolve(dialog, undefined);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
isResolving--;
|
|
325
|
+
isAcceptHandled = false;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
this.filePickBox.onDidAccept(_ => {
|
|
330
|
+
handleAccept(this);
|
|
331
|
+
});
|
|
332
|
+
this.filePickBox.onDidChangeActive(i => {
|
|
333
|
+
isAcceptHandled = false;
|
|
334
|
+
if ((i.length === 1) && this.isSelectionChangeFromUser()) {
|
|
335
|
+
this.filePickBox.validationMessage = undefined;
|
|
336
|
+
const userPath = this.constructFullUserPath();
|
|
337
|
+
if (!equalsIgnoreCase(this.filePickBox.value.substring(0, userPath.length), userPath)) {
|
|
338
|
+
this.filePickBox.valueSelection = [0, this.filePickBox.value.length];
|
|
339
|
+
this.insertText(userPath, userPath);
|
|
340
|
+
}
|
|
341
|
+
this.setAutoComplete(userPath, this.userEnteredPathSegment, i[0], true);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
this.filePickBox.onDidChangeValue(async (value) => {
|
|
345
|
+
return this.handleValueChange(value);
|
|
346
|
+
});
|
|
347
|
+
this.filePickBox.onDidHide(() => {
|
|
348
|
+
this.hidden = true;
|
|
349
|
+
if (isResolving === 0) {
|
|
350
|
+
doResolve(this, undefined);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
this.filePickBox.show();
|
|
354
|
+
this.contextKey.set(true);
|
|
355
|
+
this.updateItems(homedir, true, this.trailing).then(() => {
|
|
356
|
+
if (this.trailing) {
|
|
357
|
+
this.filePickBox.valueSelection = [this.filePickBox.value.length - this.trailing.length, this.filePickBox.value.length - ext.length];
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
this.filePickBox.valueSelection = [this.filePickBox.value.length, this.filePickBox.value.length];
|
|
361
|
+
}
|
|
362
|
+
this.busy = false;
|
|
363
|
+
});
|
|
364
|
+
}));
|
|
365
|
+
}
|
|
366
|
+
async handleValueChange(value) {
|
|
367
|
+
try {
|
|
368
|
+
if (this.isValueChangeFromUser()) {
|
|
369
|
+
if (!equalsIgnoreCase(value, this.constructFullUserPath()) && !this.isBadSubpath(value)) {
|
|
370
|
+
this.filePickBox.validationMessage = undefined;
|
|
371
|
+
const filePickBoxUri = this.filePickBoxValue();
|
|
372
|
+
let updated = UpdateResult.NotUpdated;
|
|
373
|
+
if (!resources.extUriIgnorePathCase.isEqual(this.currentFolder, filePickBoxUri)) {
|
|
374
|
+
updated = await this.tryUpdateItems(value, filePickBoxUri);
|
|
375
|
+
}
|
|
376
|
+
if ((updated === UpdateResult.NotUpdated) || (updated === UpdateResult.UpdatedWithTrailing)) {
|
|
377
|
+
this.setActiveItems(value);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
this.filePickBox.activeItems = [];
|
|
382
|
+
this.userEnteredPathSegment = '';
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
isBadSubpath(value) {
|
|
390
|
+
return this.badPath && (value.length > this.badPath.length) && equalsIgnoreCase(value.substring(0, this.badPath.length), this.badPath);
|
|
391
|
+
}
|
|
392
|
+
isValueChangeFromUser() {
|
|
393
|
+
if (equalsIgnoreCase(this.filePickBox.value, this.pathAppend(this.currentFolder, this.userEnteredPathSegment + this.autoCompletePathSegment))) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
isSelectionChangeFromUser() {
|
|
399
|
+
if (this.activeItem === (this.filePickBox.activeItems ? this.filePickBox.activeItems[0] : undefined)) {
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
constructFullUserPath() {
|
|
405
|
+
const currentFolderPath = this.pathFromUri(this.currentFolder);
|
|
406
|
+
if (equalsIgnoreCase(this.filePickBox.value.substr(0, this.userEnteredPathSegment.length), this.userEnteredPathSegment)) {
|
|
407
|
+
if (equalsIgnoreCase(this.filePickBox.value.substr(0, currentFolderPath.length), currentFolderPath)) {
|
|
408
|
+
return currentFolderPath;
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
return this.userEnteredPathSegment;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
return this.pathAppend(this.currentFolder, this.userEnteredPathSegment);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
filePickBoxValue() {
|
|
419
|
+
const directUri = this.remoteUriFrom(this.filePickBox.value.trimRight(), this.currentFolder);
|
|
420
|
+
const currentPath = this.pathFromUri(this.currentFolder);
|
|
421
|
+
if (equalsIgnoreCase(this.filePickBox.value, currentPath)) {
|
|
422
|
+
return this.currentFolder;
|
|
423
|
+
}
|
|
424
|
+
const currentDisplayUri = this.remoteUriFrom(currentPath, this.currentFolder);
|
|
425
|
+
const relativePath = resources.relativePath(currentDisplayUri, directUri);
|
|
426
|
+
const isSameRoot = (this.filePickBox.value.length > 1 && currentPath.length > 1) ? equalsIgnoreCase(this.filePickBox.value.substr(0, 2), currentPath.substr(0, 2)) : false;
|
|
427
|
+
if (relativePath && isSameRoot) {
|
|
428
|
+
let path = resources.joinPath(this.currentFolder, relativePath);
|
|
429
|
+
const directBasename = resources.basename(directUri);
|
|
430
|
+
if ((directBasename === '.') || (directBasename === '..')) {
|
|
431
|
+
path = this.remoteUriFrom(this.pathAppend(path, directBasename), this.currentFolder);
|
|
432
|
+
}
|
|
433
|
+
return resources.hasTrailingPathSeparator(directUri) ? resources.addTrailingPathSeparator(path) : path;
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
return directUri;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
async onDidAccept() {
|
|
440
|
+
this.busy = true;
|
|
441
|
+
if (this.filePickBox.activeItems.length === 1) {
|
|
442
|
+
const item = this.filePickBox.selectedItems[0];
|
|
443
|
+
if (item.isFolder) {
|
|
444
|
+
if (this.trailing) {
|
|
445
|
+
await this.updateItems(item.uri, true, this.trailing);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
const newPath = this.pathFromUri(item.uri);
|
|
449
|
+
if (startsWithIgnoreCase(newPath, this.filePickBox.value) && (equalsIgnoreCase(item.label, resources.basename(item.uri)))) {
|
|
450
|
+
this.filePickBox.valueSelection = [this.pathFromUri(this.currentFolder).length, this.filePickBox.value.length];
|
|
451
|
+
this.insertText(newPath, this.basenameWithTrailingSlash(item.uri));
|
|
452
|
+
}
|
|
453
|
+
else if ((item.label === '..') && startsWithIgnoreCase(this.filePickBox.value, newPath)) {
|
|
454
|
+
this.filePickBox.valueSelection = [newPath.length, this.filePickBox.value.length];
|
|
455
|
+
this.insertText(newPath, '');
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
await this.updateItems(item.uri, true);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
this.filePickBox.busy = false;
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
if ((await this.tryUpdateItems(this.filePickBox.value, this.filePickBoxValue())) !== UpdateResult.NotUpdated) {
|
|
467
|
+
this.filePickBox.busy = false;
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
let resolveValue;
|
|
472
|
+
if (this.filePickBox.activeItems.length === 0) {
|
|
473
|
+
resolveValue = this.filePickBoxValue();
|
|
474
|
+
}
|
|
475
|
+
else if (this.filePickBox.activeItems.length === 1) {
|
|
476
|
+
resolveValue = this.filePickBox.selectedItems[0].uri;
|
|
477
|
+
}
|
|
478
|
+
if (resolveValue) {
|
|
479
|
+
resolveValue = this.addPostfix(resolveValue);
|
|
480
|
+
}
|
|
481
|
+
if (await this.validate(resolveValue)) {
|
|
482
|
+
this.busy = false;
|
|
483
|
+
return resolveValue;
|
|
484
|
+
}
|
|
485
|
+
this.busy = false;
|
|
486
|
+
return undefined;
|
|
487
|
+
}
|
|
488
|
+
root(value) {
|
|
489
|
+
let lastDir = value;
|
|
490
|
+
let dir = resources.dirname(value);
|
|
491
|
+
while (!resources.isEqual(lastDir, dir)) {
|
|
492
|
+
lastDir = dir;
|
|
493
|
+
dir = resources.dirname(dir);
|
|
494
|
+
}
|
|
495
|
+
return dir;
|
|
496
|
+
}
|
|
497
|
+
tildaReplace(value) {
|
|
498
|
+
const home = this.userHome;
|
|
499
|
+
if ((value.length > 0) && (value[0] === '~')) {
|
|
500
|
+
return resources.joinPath(home, value.substring(1));
|
|
501
|
+
}
|
|
502
|
+
return this.remoteUriFrom(value);
|
|
503
|
+
}
|
|
504
|
+
tryAddTrailingSeparatorToDirectory(uri, stat) {
|
|
505
|
+
if (stat.isDirectory) {
|
|
506
|
+
if (!this.endsWithSlash(uri.path)) {
|
|
507
|
+
return resources.addTrailingPathSeparator(uri);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return uri;
|
|
511
|
+
}
|
|
512
|
+
async tryUpdateItems(value, valueUri) {
|
|
513
|
+
if ((value.length > 0) && (value[0] === '~')) {
|
|
514
|
+
const newDir = this.tildaReplace(value);
|
|
515
|
+
return (await this.updateItems(newDir, true)) ? UpdateResult.UpdatedWithTrailing : UpdateResult.Updated;
|
|
516
|
+
}
|
|
517
|
+
else if (value === '\\') {
|
|
518
|
+
valueUri = this.root(this.currentFolder);
|
|
519
|
+
value = this.pathFromUri(valueUri);
|
|
520
|
+
return (await this.updateItems(valueUri, true)) ? UpdateResult.UpdatedWithTrailing : UpdateResult.Updated;
|
|
521
|
+
}
|
|
522
|
+
else if (!resources.extUriIgnorePathCase.isEqual(this.currentFolder, valueUri) && (this.endsWithSlash(value) || (!resources.extUriIgnorePathCase.isEqual(this.currentFolder, resources.dirname(valueUri)) && resources.extUriIgnorePathCase.isEqualOrParent(this.currentFolder, resources.dirname(valueUri))))) {
|
|
523
|
+
let stat;
|
|
524
|
+
try {
|
|
525
|
+
stat = await this.fileService.stat(valueUri);
|
|
526
|
+
}
|
|
527
|
+
catch (e) {
|
|
528
|
+
}
|
|
529
|
+
if (stat && stat.isDirectory && (resources.basename(valueUri) !== '.') && this.endsWithSlash(value)) {
|
|
530
|
+
valueUri = this.tryAddTrailingSeparatorToDirectory(valueUri, stat);
|
|
531
|
+
return (await this.updateItems(valueUri)) ? UpdateResult.UpdatedWithTrailing : UpdateResult.Updated;
|
|
532
|
+
}
|
|
533
|
+
else if (this.endsWithSlash(value)) {
|
|
534
|
+
this.filePickBox.validationMessage = ( nls.localize('remoteFileDialog.badPath', 'The path does not exist.'));
|
|
535
|
+
this.badPath = value;
|
|
536
|
+
return UpdateResult.InvalidPath;
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
let inputUriDirname = resources.dirname(valueUri);
|
|
540
|
+
const currentFolderWithoutSep = resources.removeTrailingPathSeparator(resources.addTrailingPathSeparator(this.currentFolder));
|
|
541
|
+
const inputUriDirnameWithoutSep = resources.removeTrailingPathSeparator(resources.addTrailingPathSeparator(inputUriDirname));
|
|
542
|
+
if (!resources.extUriIgnorePathCase.isEqual(currentFolderWithoutSep, inputUriDirnameWithoutSep)
|
|
543
|
+
&& (!/^[a-zA-Z]:$/.test(this.filePickBox.value)
|
|
544
|
+
|| !equalsIgnoreCase(this.pathFromUri(this.currentFolder).substring(0, this.filePickBox.value.length), this.filePickBox.value))) {
|
|
545
|
+
let statWithoutTrailing;
|
|
546
|
+
try {
|
|
547
|
+
statWithoutTrailing = await this.fileService.stat(inputUriDirname);
|
|
548
|
+
}
|
|
549
|
+
catch (e) {
|
|
550
|
+
}
|
|
551
|
+
if (statWithoutTrailing && statWithoutTrailing.isDirectory) {
|
|
552
|
+
this.badPath = undefined;
|
|
553
|
+
inputUriDirname = this.tryAddTrailingSeparatorToDirectory(inputUriDirname, statWithoutTrailing);
|
|
554
|
+
return (await this.updateItems(inputUriDirname, false, resources.basename(valueUri))) ? UpdateResult.UpdatedWithTrailing : UpdateResult.Updated;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
this.badPath = undefined;
|
|
560
|
+
return UpdateResult.NotUpdated;
|
|
561
|
+
}
|
|
562
|
+
tryUpdateTrailing(value) {
|
|
563
|
+
const ext = resources.extname(value);
|
|
564
|
+
if (this.trailing && ext) {
|
|
565
|
+
this.trailing = resources.basename(value);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
setActiveItems(value) {
|
|
569
|
+
value = this.pathFromUri(this.tildaReplace(value));
|
|
570
|
+
const asUri = this.remoteUriFrom(value);
|
|
571
|
+
const inputBasename = resources.basename(asUri);
|
|
572
|
+
const userPath = this.constructFullUserPath();
|
|
573
|
+
const pathsEqual = equalsIgnoreCase(userPath, value.substring(0, userPath.length)) ||
|
|
574
|
+
equalsIgnoreCase(value, userPath.substring(0, value.length));
|
|
575
|
+
if (pathsEqual) {
|
|
576
|
+
let hasMatch = false;
|
|
577
|
+
for (let i = 0; i < this.filePickBox.items.length; i++) {
|
|
578
|
+
const item = this.filePickBox.items[i];
|
|
579
|
+
if (this.setAutoComplete(value, inputBasename, item)) {
|
|
580
|
+
hasMatch = true;
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (!hasMatch) {
|
|
585
|
+
const userBasename = inputBasename.length >= 2 ? userPath.substring(userPath.length - inputBasename.length + 2) : '';
|
|
586
|
+
this.userEnteredPathSegment = (userBasename === inputBasename) ? inputBasename : '';
|
|
587
|
+
this.autoCompletePathSegment = '';
|
|
588
|
+
this.filePickBox.activeItems = [];
|
|
589
|
+
this.tryUpdateTrailing(asUri);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
this.userEnteredPathSegment = inputBasename;
|
|
594
|
+
this.autoCompletePathSegment = '';
|
|
595
|
+
this.filePickBox.activeItems = [];
|
|
596
|
+
this.tryUpdateTrailing(asUri);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
setAutoComplete(startingValue, startingBasename, quickPickItem, force = false) {
|
|
600
|
+
if (this.busy) {
|
|
601
|
+
this.userEnteredPathSegment = startingBasename;
|
|
602
|
+
this.autoCompletePathSegment = '';
|
|
603
|
+
return false;
|
|
604
|
+
}
|
|
605
|
+
const itemBasename = quickPickItem.label;
|
|
606
|
+
if (itemBasename === '..') {
|
|
607
|
+
this.userEnteredPathSegment = '';
|
|
608
|
+
this.autoCompletePathSegment = '';
|
|
609
|
+
this.activeItem = quickPickItem;
|
|
610
|
+
if (force) {
|
|
611
|
+
document.execCommand('insertText', false, '');
|
|
612
|
+
}
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
else if (!force && (itemBasename.length >= startingBasename.length) && equalsIgnoreCase(itemBasename.substr(0, startingBasename.length), startingBasename)) {
|
|
616
|
+
this.userEnteredPathSegment = startingBasename;
|
|
617
|
+
this.activeItem = quickPickItem;
|
|
618
|
+
this.autoCompletePathSegment = '';
|
|
619
|
+
if (quickPickItem.isFolder || !this.trailing) {
|
|
620
|
+
this.filePickBox.activeItems = [quickPickItem];
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
this.filePickBox.activeItems = [];
|
|
624
|
+
}
|
|
625
|
+
return true;
|
|
626
|
+
}
|
|
627
|
+
else if (force && (!equalsIgnoreCase(this.basenameWithTrailingSlash(quickPickItem.uri), (this.userEnteredPathSegment + this.autoCompletePathSegment)))) {
|
|
628
|
+
this.userEnteredPathSegment = '';
|
|
629
|
+
if (!this.accessibilityService.isScreenReaderOptimized()) {
|
|
630
|
+
this.autoCompletePathSegment = this.trimTrailingSlash(itemBasename);
|
|
631
|
+
}
|
|
632
|
+
this.activeItem = quickPickItem;
|
|
633
|
+
if (!this.accessibilityService.isScreenReaderOptimized()) {
|
|
634
|
+
this.filePickBox.valueSelection = [this.pathFromUri(this.currentFolder, true).length, this.filePickBox.value.length];
|
|
635
|
+
this.insertText(this.pathAppend(this.currentFolder, this.autoCompletePathSegment), this.autoCompletePathSegment);
|
|
636
|
+
this.filePickBox.valueSelection = [this.filePickBox.value.length - this.autoCompletePathSegment.length, this.filePickBox.value.length];
|
|
637
|
+
}
|
|
638
|
+
return true;
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
this.userEnteredPathSegment = startingBasename;
|
|
642
|
+
this.autoCompletePathSegment = '';
|
|
643
|
+
return false;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
insertText(wholeValue, insertText) {
|
|
647
|
+
if (this.filePickBox.inputHasFocus()) {
|
|
648
|
+
document.execCommand('insertText', false, insertText);
|
|
649
|
+
if (this.filePickBox.value !== wholeValue) {
|
|
650
|
+
this.filePickBox.value = wholeValue;
|
|
651
|
+
this.handleValueChange(wholeValue);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
this.filePickBox.value = wholeValue;
|
|
656
|
+
this.handleValueChange(wholeValue);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
addPostfix(uri) {
|
|
660
|
+
let result = uri;
|
|
661
|
+
if (this.requiresTrailing && this.options.filters && this.options.filters.length > 0 && !resources.hasTrailingPathSeparator(uri)) {
|
|
662
|
+
let hasExt = false;
|
|
663
|
+
const currentExt = resources.extname(uri).substr(1);
|
|
664
|
+
for (let i = 0; i < this.options.filters.length; i++) {
|
|
665
|
+
for (let j = 0; j < this.options.filters[i].extensions.length; j++) {
|
|
666
|
+
if ((this.options.filters[i].extensions[j] === '*') || (this.options.filters[i].extensions[j] === currentExt)) {
|
|
667
|
+
hasExt = true;
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (hasExt) {
|
|
672
|
+
break;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
if (!hasExt) {
|
|
676
|
+
result = resources.joinPath(resources.dirname(uri), resources.basename(uri) + '.' + this.options.filters[0].extensions[0]);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return result;
|
|
680
|
+
}
|
|
681
|
+
trimTrailingSlash(path) {
|
|
682
|
+
return ((path.length > 1) && this.endsWithSlash(path)) ? path.substr(0, path.length - 1) : path;
|
|
683
|
+
}
|
|
684
|
+
yesNoPrompt(uri, message) {
|
|
685
|
+
const prompt = this.quickInputService.createQuickPick();
|
|
686
|
+
prompt.title = message;
|
|
687
|
+
prompt.ignoreFocusOut = true;
|
|
688
|
+
prompt.ok = true;
|
|
689
|
+
prompt.customButton = true;
|
|
690
|
+
prompt.customLabel = ( nls.localize('remoteFileDialog.cancel', 'Cancel'));
|
|
691
|
+
prompt.value = this.pathFromUri(uri);
|
|
692
|
+
let isResolving = false;
|
|
693
|
+
return ( new Promise(resolve => {
|
|
694
|
+
prompt.onDidAccept(() => {
|
|
695
|
+
isResolving = true;
|
|
696
|
+
prompt.hide();
|
|
697
|
+
resolve(true);
|
|
698
|
+
});
|
|
699
|
+
prompt.onDidHide(() => {
|
|
700
|
+
if (!isResolving) {
|
|
701
|
+
resolve(false);
|
|
702
|
+
}
|
|
703
|
+
this.filePickBox.show();
|
|
704
|
+
this.hidden = false;
|
|
705
|
+
this.filePickBox.items = this.filePickBox.items;
|
|
706
|
+
prompt.dispose();
|
|
707
|
+
});
|
|
708
|
+
prompt.onDidChangeValue(() => {
|
|
709
|
+
prompt.hide();
|
|
710
|
+
});
|
|
711
|
+
prompt.onDidCustom(() => {
|
|
712
|
+
prompt.hide();
|
|
713
|
+
});
|
|
714
|
+
prompt.show();
|
|
715
|
+
}));
|
|
716
|
+
}
|
|
717
|
+
async validate(uri) {
|
|
718
|
+
if (uri === undefined) {
|
|
719
|
+
this.filePickBox.validationMessage = ( nls.localize('remoteFileDialog.invalidPath', 'Please enter a valid path.'));
|
|
720
|
+
return Promise.resolve(false);
|
|
721
|
+
}
|
|
722
|
+
let stat;
|
|
723
|
+
let statDirname;
|
|
724
|
+
try {
|
|
725
|
+
statDirname = await this.fileService.stat(resources.dirname(uri));
|
|
726
|
+
stat = await this.fileService.stat(uri);
|
|
727
|
+
}
|
|
728
|
+
catch (e) {
|
|
729
|
+
}
|
|
730
|
+
if (this.requiresTrailing) {
|
|
731
|
+
if (stat && stat.isDirectory) {
|
|
732
|
+
this.filePickBox.validationMessage = ( nls.localize(
|
|
733
|
+
'remoteFileDialog.validateFolder',
|
|
734
|
+
'The folder already exists. Please use a new file name.'
|
|
735
|
+
));
|
|
736
|
+
return Promise.resolve(false);
|
|
737
|
+
}
|
|
738
|
+
else if (stat) {
|
|
739
|
+
const message = ( nls.localize(
|
|
740
|
+
'remoteFileDialog.validateExisting',
|
|
741
|
+
'{0} already exists. Are you sure you want to overwrite it?',
|
|
742
|
+
resources.basename(uri)
|
|
743
|
+
));
|
|
744
|
+
return this.yesNoPrompt(uri, message);
|
|
745
|
+
}
|
|
746
|
+
else if (!(isValidBasename(resources.basename(uri), this.isWindows))) {
|
|
747
|
+
this.filePickBox.validationMessage = ( nls.localize('remoteFileDialog.validateBadFilename', 'Please enter a valid file name.'));
|
|
748
|
+
return Promise.resolve(false);
|
|
749
|
+
}
|
|
750
|
+
else if (!statDirname) {
|
|
751
|
+
const message = ( nls.localize(
|
|
752
|
+
'remoteFileDialog.validateCreateDirectory',
|
|
753
|
+
'The folder {0} does not exist. Would you like to create it?',
|
|
754
|
+
resources.basename(resources.dirname(uri))
|
|
755
|
+
));
|
|
756
|
+
return this.yesNoPrompt(uri, message);
|
|
757
|
+
}
|
|
758
|
+
else if (!statDirname.isDirectory) {
|
|
759
|
+
this.filePickBox.validationMessage = ( nls.localize(
|
|
760
|
+
'remoteFileDialog.validateNonexistentDir',
|
|
761
|
+
'Please enter a path that exists.'
|
|
762
|
+
));
|
|
763
|
+
return Promise.resolve(false);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
else {
|
|
767
|
+
if (!stat) {
|
|
768
|
+
this.filePickBox.validationMessage = ( nls.localize(
|
|
769
|
+
'remoteFileDialog.validateNonexistentDir',
|
|
770
|
+
'Please enter a path that exists.'
|
|
771
|
+
));
|
|
772
|
+
return Promise.resolve(false);
|
|
773
|
+
}
|
|
774
|
+
else if (uri.path === '/' && this.isWindows) {
|
|
775
|
+
this.filePickBox.validationMessage = ( nls.localize(
|
|
776
|
+
'remoteFileDialog.windowsDriveLetter',
|
|
777
|
+
'Please start the path with a drive letter.'
|
|
778
|
+
));
|
|
779
|
+
return Promise.resolve(false);
|
|
780
|
+
}
|
|
781
|
+
else if (stat.isDirectory && !this.allowFolderSelection) {
|
|
782
|
+
this.filePickBox.validationMessage = ( nls.localize('remoteFileDialog.validateFileOnly', 'Please select a file.'));
|
|
783
|
+
return Promise.resolve(false);
|
|
784
|
+
}
|
|
785
|
+
else if (!stat.isDirectory && !this.allowFileSelection) {
|
|
786
|
+
this.filePickBox.validationMessage = ( nls.localize('remoteFileDialog.validateFolderOnly', 'Please select a folder.'));
|
|
787
|
+
return Promise.resolve(false);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
return Promise.resolve(true);
|
|
791
|
+
}
|
|
792
|
+
async updateItems(newFolder, force = false, trailing) {
|
|
793
|
+
this.busy = true;
|
|
794
|
+
this.autoCompletePathSegment = '';
|
|
795
|
+
const isSave = !!trailing;
|
|
796
|
+
let result = false;
|
|
797
|
+
const updatingPromise = createCancelablePromise(async (token) => {
|
|
798
|
+
let folderStat;
|
|
799
|
+
try {
|
|
800
|
+
folderStat = await this.fileService.resolve(newFolder);
|
|
801
|
+
if (!folderStat.isDirectory) {
|
|
802
|
+
trailing = resources.basename(newFolder);
|
|
803
|
+
newFolder = resources.dirname(newFolder);
|
|
804
|
+
folderStat = undefined;
|
|
805
|
+
result = true;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
catch (e) {
|
|
809
|
+
}
|
|
810
|
+
const newValue = trailing ? this.pathAppend(newFolder, trailing) : this.pathFromUri(newFolder, true);
|
|
811
|
+
this.currentFolder = this.endsWithSlash(newFolder.path) ? newFolder : resources.addTrailingPathSeparator(newFolder, this.separator);
|
|
812
|
+
this.userEnteredPathSegment = trailing ? trailing : '';
|
|
813
|
+
return this.createItems(folderStat, this.currentFolder, token).then(items => {
|
|
814
|
+
if (token.isCancellationRequested) {
|
|
815
|
+
this.busy = false;
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
818
|
+
this.filePickBox.items = items;
|
|
819
|
+
this.filePickBox.activeItems = [this.filePickBox.items[0]];
|
|
820
|
+
this.filePickBox.activeItems = [];
|
|
821
|
+
if (!equalsIgnoreCase(this.filePickBox.value, newValue) && force) {
|
|
822
|
+
this.filePickBox.valueSelection = [0, this.filePickBox.value.length];
|
|
823
|
+
this.insertText(newValue, newValue);
|
|
824
|
+
}
|
|
825
|
+
if (force && trailing && isSave) {
|
|
826
|
+
this.filePickBox.valueSelection = [this.filePickBox.value.length - trailing.length, this.filePickBox.value.length - trailing.length];
|
|
827
|
+
}
|
|
828
|
+
else if (!trailing) {
|
|
829
|
+
this.filePickBox.valueSelection = [this.filePickBox.value.length, this.filePickBox.value.length];
|
|
830
|
+
}
|
|
831
|
+
this.busy = false;
|
|
832
|
+
this.updatingPromise = undefined;
|
|
833
|
+
return result;
|
|
834
|
+
});
|
|
835
|
+
});
|
|
836
|
+
if (this.updatingPromise !== undefined) {
|
|
837
|
+
this.updatingPromise.cancel();
|
|
838
|
+
}
|
|
839
|
+
this.updatingPromise = updatingPromise;
|
|
840
|
+
return updatingPromise;
|
|
841
|
+
}
|
|
842
|
+
pathFromUri(uri, endWithSeparator = false) {
|
|
843
|
+
let result = normalizeDriveLetter(uri.fsPath, this.isWindows).replace(/\n/g, '');
|
|
844
|
+
if (this.separator === '/') {
|
|
845
|
+
result = result.replace(/\\/g, this.separator);
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
result = result.replace(/\//g, this.separator);
|
|
849
|
+
}
|
|
850
|
+
if (endWithSeparator && !this.endsWithSlash(result)) {
|
|
851
|
+
result = result + this.separator;
|
|
852
|
+
}
|
|
853
|
+
return result;
|
|
854
|
+
}
|
|
855
|
+
pathAppend(uri, additional) {
|
|
856
|
+
if ((additional === '..') || (additional === '.')) {
|
|
857
|
+
const basePath = this.pathFromUri(uri, true);
|
|
858
|
+
return basePath + additional;
|
|
859
|
+
}
|
|
860
|
+
else {
|
|
861
|
+
return this.pathFromUri(resources.joinPath(uri, additional));
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
async checkIsWindowsOS() {
|
|
865
|
+
let isWindowsOS = isWindows;
|
|
866
|
+
const env = await this.getRemoteAgentEnvironment();
|
|
867
|
+
if (env) {
|
|
868
|
+
isWindowsOS = env.os === 1 ;
|
|
869
|
+
}
|
|
870
|
+
return isWindowsOS;
|
|
871
|
+
}
|
|
872
|
+
endsWithSlash(s) {
|
|
873
|
+
return /[\/\\]$/.test(s);
|
|
874
|
+
}
|
|
875
|
+
basenameWithTrailingSlash(fullPath) {
|
|
876
|
+
const child = this.pathFromUri(fullPath, true);
|
|
877
|
+
const parent = this.pathFromUri(resources.dirname(fullPath), true);
|
|
878
|
+
return child.substring(parent.length);
|
|
879
|
+
}
|
|
880
|
+
async createBackItem(currFolder) {
|
|
881
|
+
const fileRepresentationCurr = this.currentFolder.with({ scheme: Schemas.file, authority: '' });
|
|
882
|
+
const fileRepresentationParent = resources.dirname(fileRepresentationCurr);
|
|
883
|
+
if (!resources.isEqual(fileRepresentationCurr, fileRepresentationParent)) {
|
|
884
|
+
const parentFolder = resources.dirname(currFolder);
|
|
885
|
+
if (await this.fileService.exists(parentFolder)) {
|
|
886
|
+
return { label: '..', uri: resources.addTrailingPathSeparator(parentFolder, this.separator), isFolder: true };
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
return undefined;
|
|
890
|
+
}
|
|
891
|
+
async createItems(folder, currentFolder, token) {
|
|
892
|
+
const result = [];
|
|
893
|
+
const backDir = await this.createBackItem(currentFolder);
|
|
894
|
+
try {
|
|
895
|
+
if (!folder) {
|
|
896
|
+
folder = await this.fileService.resolve(currentFolder);
|
|
897
|
+
}
|
|
898
|
+
const items = folder.children ? await Promise.all(( folder.children.map(child => this.createItem(child, currentFolder, token)))) : [];
|
|
899
|
+
for (const item of items) {
|
|
900
|
+
if (item) {
|
|
901
|
+
result.push(item);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
catch (e) {
|
|
906
|
+
console.log(e);
|
|
907
|
+
}
|
|
908
|
+
if (token.isCancellationRequested) {
|
|
909
|
+
return [];
|
|
910
|
+
}
|
|
911
|
+
const sorted = result.sort((i1, i2) => {
|
|
912
|
+
if (i1.isFolder !== i2.isFolder) {
|
|
913
|
+
return i1.isFolder ? -1 : 1;
|
|
914
|
+
}
|
|
915
|
+
const trimmed1 = this.endsWithSlash(i1.label) ? i1.label.substr(0, i1.label.length - 1) : i1.label;
|
|
916
|
+
const trimmed2 = this.endsWithSlash(i2.label) ? i2.label.substr(0, i2.label.length - 1) : i2.label;
|
|
917
|
+
return trimmed1.localeCompare(trimmed2);
|
|
918
|
+
});
|
|
919
|
+
if (backDir) {
|
|
920
|
+
sorted.unshift(backDir);
|
|
921
|
+
}
|
|
922
|
+
return sorted;
|
|
923
|
+
}
|
|
924
|
+
filterFile(file) {
|
|
925
|
+
if (this.options.filters) {
|
|
926
|
+
const ext = resources.extname(file);
|
|
927
|
+
for (let i = 0; i < this.options.filters.length; i++) {
|
|
928
|
+
for (let j = 0; j < this.options.filters[i].extensions.length; j++) {
|
|
929
|
+
const testExt = this.options.filters[i].extensions[j];
|
|
930
|
+
if ((testExt === '*') || (ext === ('.' + testExt))) {
|
|
931
|
+
return true;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return false;
|
|
936
|
+
}
|
|
937
|
+
return true;
|
|
938
|
+
}
|
|
939
|
+
async createItem(stat, parent, token) {
|
|
940
|
+
if (token.isCancellationRequested) {
|
|
941
|
+
return undefined;
|
|
942
|
+
}
|
|
943
|
+
let fullPath = resources.joinPath(parent, stat.name);
|
|
944
|
+
if (stat.isDirectory) {
|
|
945
|
+
const filename = resources.basename(fullPath);
|
|
946
|
+
fullPath = resources.addTrailingPathSeparator(fullPath, this.separator);
|
|
947
|
+
return { label: filename, uri: fullPath, isFolder: true, iconClasses: getIconClasses(this.modelService, this.languageService, fullPath || undefined, FileKind.FOLDER) };
|
|
948
|
+
}
|
|
949
|
+
else if (!stat.isDirectory && this.allowFileSelection && this.filterFile(fullPath)) {
|
|
950
|
+
return { label: stat.name, uri: fullPath, isFolder: false, iconClasses: getIconClasses(this.modelService, this.languageService, fullPath || undefined) };
|
|
951
|
+
}
|
|
952
|
+
return undefined;
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
SimpleFileDialog = ( __decorate([
|
|
956
|
+
( __param(0, IFileService)),
|
|
957
|
+
( __param(1, IQuickInputService)),
|
|
958
|
+
( __param(2, ILabelService)),
|
|
959
|
+
( __param(3, IWorkspaceContextService)),
|
|
960
|
+
( __param(4, INotificationService)),
|
|
961
|
+
( __param(5, IFileDialogService)),
|
|
962
|
+
( __param(6, IModelService)),
|
|
963
|
+
( __param(7, ILanguageService)),
|
|
964
|
+
( __param(8, IWorkbenchEnvironmentService)),
|
|
965
|
+
( __param(9, IRemoteAgentService)),
|
|
966
|
+
( __param(10, IPathService)),
|
|
967
|
+
( __param(11, IKeybindingService)),
|
|
968
|
+
( __param(12, IContextKeyService)),
|
|
969
|
+
( __param(13, IAccessibilityService))
|
|
970
|
+
], SimpleFileDialog));
|
|
971
|
+
export { OpenLocalFileCommand, OpenLocalFileFolderCommand, OpenLocalFolderCommand, RemoteFileDialogContext, SaveLocalFileCommand, SimpleFileDialog };
|