@codingame/monaco-vscode-dialogs-service-override 4.3.1 → 4.4.0
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/dialogs.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { IEditorOverrideServices } from 'vscode/vscode/vs/editor/standalone/browser/standaloneServices';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface DialogServiceOverrideProps {
|
|
4
|
+
/**
|
|
5
|
+
* Is an `HTMLFileSystemProvider` is used as only provider for the `file` scheme directly (without overlay)
|
|
6
|
+
* Enable this option to enable browser file dialogs
|
|
7
|
+
*/
|
|
8
|
+
useHtmlFileSystemProvider: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function getServiceOverride({ useHtmlFileSystemProvider }: DialogServiceOverrideProps): IEditorOverrideServices;
|
|
4
11
|
|
|
5
12
|
export { getServiceOverride as default };
|
package/dialogs.js
CHANGED
|
@@ -2,12 +2,13 @@ import { DialogService } from './vscode/src/vs/workbench/services/dialogs/common
|
|
|
2
2
|
import './override/vs/platform/dialogs/common/dialogs.js';
|
|
3
3
|
import { SyncDescriptor } from 'vscode/vscode/vs/platform/instantiation/common/descriptors';
|
|
4
4
|
import { AbstractFileDialogService } from './vscode/src/vs/workbench/services/dialogs/browser/abstractFileDialogService.js';
|
|
5
|
+
import { FileDialogService } from './vscode/src/vs/workbench/services/dialogs/browser/fileDialogService.js';
|
|
5
6
|
import { unsupported } from './tools.js';
|
|
6
7
|
import './vscode/src/vs/workbench/browser/parts/dialogs/dialog.web.contribution.js';
|
|
7
8
|
import './vscode/src/vs/workbench/contrib/welcomeDialog/browser/welcomeDialog.contribution.js';
|
|
8
9
|
import { IDialogService, IFileDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
|
|
9
10
|
|
|
10
|
-
class
|
|
11
|
+
class DialogServiceOverride extends AbstractFileDialogService {
|
|
11
12
|
constructor() {
|
|
12
13
|
super(...arguments);
|
|
13
14
|
this.pickWorkspaceAndOpen = unsupported;
|
|
@@ -47,10 +48,10 @@ class FileDialogService extends AbstractFileDialogService {
|
|
|
47
48
|
return super.pickFileToSaveSimplified(schema, options);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
function getServiceOverride() {
|
|
51
|
+
function getServiceOverride({ useHtmlFileSystemProvider }) {
|
|
51
52
|
return {
|
|
52
53
|
[( IDialogService.toString())]: new SyncDescriptor(DialogService, undefined, true),
|
|
53
|
-
[( IFileDialogService.toString())]: new SyncDescriptor(FileDialogService, undefined, true)
|
|
54
|
+
[( IFileDialogService.toString())]: useHtmlFileSystemProvider ? new SyncDescriptor(FileDialogService, undefined, true) : new SyncDescriptor(DialogServiceOverride, undefined, true)
|
|
54
55
|
};
|
|
55
56
|
}
|
|
56
57
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-dialogs-service-override",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "CodinGame",
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
"module": "index.js",
|
|
19
19
|
"types": "index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"vscode": "npm:@codingame/monaco-vscode-api@4.
|
|
21
|
+
"vscode": "npm:@codingame/monaco-vscode-api@4.4.0"
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { __decorate } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
|
+
import '../../../../../../../override/vs/platform/dialogs/common/dialogs.js';
|
|
3
|
+
import { AbstractFileDialogService } from './abstractFileDialogService.js';
|
|
4
|
+
import { Schemas } from 'vscode/vscode/vs/base/common/network';
|
|
5
|
+
import { memoize } from 'vscode/vscode/vs/base/common/decorators';
|
|
6
|
+
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
7
|
+
import { getMediaOrTextMime } from 'vscode/vscode/vs/base/common/mime';
|
|
8
|
+
import { basename } from 'vscode/vscode/vs/base/common/resources';
|
|
9
|
+
import { getActiveWindow, triggerDownload, triggerUpload } from 'vscode/vscode/vs/base/browser/dom';
|
|
10
|
+
import Severity$1 from 'vscode/vscode/vs/base/common/severity';
|
|
11
|
+
import { VSBuffer } from 'vscode/vscode/vs/base/common/buffer';
|
|
12
|
+
import { extractFileListData } from 'vscode/vscode/vs/platform/dnd/browser/dnd';
|
|
13
|
+
import { Iterable } from 'vscode/vscode/vs/base/common/iterator';
|
|
14
|
+
import { WebFileSystemAccess } from 'vscode/vscode/vs/platform/files/browser/webFileSystemAccess';
|
|
15
|
+
import { EmbeddedCodeEditorWidget } from 'vscode/vscode/vs/editor/browser/widget/codeEditor/embeddedCodeEditorWidget';
|
|
16
|
+
|
|
17
|
+
class FileDialogService extends AbstractFileDialogService {
|
|
18
|
+
get fileSystemProvider() {
|
|
19
|
+
return this.fileService.getProvider(Schemas.file);
|
|
20
|
+
}
|
|
21
|
+
async pickFileFolderAndOpen(options) {
|
|
22
|
+
const schema = this.getFileSystemSchema(options);
|
|
23
|
+
if (!options.defaultUri) {
|
|
24
|
+
options.defaultUri = await this.defaultFilePath(schema);
|
|
25
|
+
}
|
|
26
|
+
if (this.shouldUseSimplified(schema)) {
|
|
27
|
+
return super.pickFileFolderAndOpenSimplified(schema, options, false);
|
|
28
|
+
}
|
|
29
|
+
throw new Error(localizeWithPath('vs/workbench/services/dialogs/browser/fileDialogService', 'pickFolderAndOpen', "Can't open folders, try adding a folder to the workspace instead."));
|
|
30
|
+
}
|
|
31
|
+
addFileSchemaIfNeeded(schema, isFolder) {
|
|
32
|
+
return (schema === Schemas.untitled) ? [Schemas.file]
|
|
33
|
+
: (((schema !== Schemas.file) && (!isFolder || (schema !== Schemas.vscodeRemote))) ? [schema, Schemas.file] : [schema]);
|
|
34
|
+
}
|
|
35
|
+
async pickFileAndOpen(options) {
|
|
36
|
+
const schema = this.getFileSystemSchema(options);
|
|
37
|
+
if (!options.defaultUri) {
|
|
38
|
+
options.defaultUri = await this.defaultFilePath(schema);
|
|
39
|
+
}
|
|
40
|
+
if (this.shouldUseSimplified(schema)) {
|
|
41
|
+
return super.pickFileAndOpenSimplified(schema, options, false);
|
|
42
|
+
}
|
|
43
|
+
const activeWindow = getActiveWindow();
|
|
44
|
+
if (!WebFileSystemAccess.supported(activeWindow)) {
|
|
45
|
+
return this.showUnsupportedBrowserWarning('open');
|
|
46
|
+
}
|
|
47
|
+
let fileHandle = undefined;
|
|
48
|
+
try {
|
|
49
|
+
([fileHandle] = await activeWindow.showOpenFilePicker({ multiple: false }));
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!WebFileSystemAccess.isFileSystemFileHandle(fileHandle)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const uri = await this.fileSystemProvider.registerFileHandle(fileHandle);
|
|
58
|
+
this.addFileToRecentlyOpened(uri);
|
|
59
|
+
await this.openerService.open(uri, { fromUserGesture: true, editorOptions: { pinned: true } });
|
|
60
|
+
}
|
|
61
|
+
async pickFolderAndOpen(options) {
|
|
62
|
+
const schema = this.getFileSystemSchema(options);
|
|
63
|
+
if (!options.defaultUri) {
|
|
64
|
+
options.defaultUri = await this.defaultFolderPath(schema);
|
|
65
|
+
}
|
|
66
|
+
if (this.shouldUseSimplified(schema)) {
|
|
67
|
+
return super.pickFolderAndOpenSimplified(schema, options);
|
|
68
|
+
}
|
|
69
|
+
throw new Error(localizeWithPath('vs/workbench/services/dialogs/browser/fileDialogService', 'pickFolderAndOpen', "Can't open folders, try adding a folder to the workspace instead."));
|
|
70
|
+
}
|
|
71
|
+
async pickWorkspaceAndOpen(options) {
|
|
72
|
+
options.availableFileSystems = this.getWorkspaceAvailableFileSystems(options);
|
|
73
|
+
const schema = this.getFileSystemSchema(options);
|
|
74
|
+
if (!options.defaultUri) {
|
|
75
|
+
options.defaultUri = await this.defaultWorkspacePath(schema);
|
|
76
|
+
}
|
|
77
|
+
if (this.shouldUseSimplified(schema)) {
|
|
78
|
+
return super.pickWorkspaceAndOpenSimplified(schema, options);
|
|
79
|
+
}
|
|
80
|
+
throw new Error(localizeWithPath('vs/workbench/services/dialogs/browser/fileDialogService', 'pickWorkspaceAndOpen', "Can't open workspaces, try adding a folder to the workspace instead."));
|
|
81
|
+
}
|
|
82
|
+
async pickFileToSave(defaultUri, availableFileSystems) {
|
|
83
|
+
const schema = this.getFileSystemSchema({ defaultUri, availableFileSystems });
|
|
84
|
+
const options = this.getPickFileToSaveDialogOptions(defaultUri, availableFileSystems);
|
|
85
|
+
if (this.shouldUseSimplified(schema)) {
|
|
86
|
+
return super.pickFileToSaveSimplified(schema, options);
|
|
87
|
+
}
|
|
88
|
+
const activeWindow = getActiveWindow();
|
|
89
|
+
if (!WebFileSystemAccess.supported(activeWindow)) {
|
|
90
|
+
return this.showUnsupportedBrowserWarning('save');
|
|
91
|
+
}
|
|
92
|
+
let fileHandle = undefined;
|
|
93
|
+
const startIn = Iterable.first(this.fileSystemProvider.directories);
|
|
94
|
+
try {
|
|
95
|
+
fileHandle = await activeWindow.showSaveFilePicker({ types: this.getFilePickerTypes(options.filters), ...{ suggestedName: basename(defaultUri), startIn } });
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!WebFileSystemAccess.isFileSystemFileHandle(fileHandle)) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
return this.fileSystemProvider.registerFileHandle(fileHandle);
|
|
104
|
+
}
|
|
105
|
+
getFilePickerTypes(filters) {
|
|
106
|
+
return filters?.filter(filter => {
|
|
107
|
+
return !((filter.extensions.length === 1) && ((filter.extensions[0] === '*') || filter.extensions[0] === ''));
|
|
108
|
+
}).map(filter => {
|
|
109
|
+
const accept = {};
|
|
110
|
+
const extensions = filter.extensions.filter(ext => (ext.indexOf('-') < 0) && (ext.indexOf('*') < 0) && (ext.indexOf('_') < 0));
|
|
111
|
+
accept[getMediaOrTextMime(`fileName.${filter.extensions[0]}`) ?? 'text/plain'] = ( extensions.map(ext => ext.startsWith('.') ? ext : `.${ext}`));
|
|
112
|
+
return {
|
|
113
|
+
description: filter.name,
|
|
114
|
+
accept
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async showSaveDialog(options) {
|
|
119
|
+
const schema = this.getFileSystemSchema(options);
|
|
120
|
+
if (this.shouldUseSimplified(schema)) {
|
|
121
|
+
return super.showSaveDialogSimplified(schema, options);
|
|
122
|
+
}
|
|
123
|
+
const activeWindow = getActiveWindow();
|
|
124
|
+
if (!WebFileSystemAccess.supported(activeWindow)) {
|
|
125
|
+
return this.showUnsupportedBrowserWarning('save');
|
|
126
|
+
}
|
|
127
|
+
let fileHandle = undefined;
|
|
128
|
+
const startIn = Iterable.first(this.fileSystemProvider.directories);
|
|
129
|
+
try {
|
|
130
|
+
fileHandle = await activeWindow.showSaveFilePicker({ types: this.getFilePickerTypes(options.filters), ...(options.defaultUri ? { suggestedName: basename(options.defaultUri) } : undefined), ...{ startIn } });
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
if (!WebFileSystemAccess.isFileSystemFileHandle(fileHandle)) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
return this.fileSystemProvider.registerFileHandle(fileHandle);
|
|
139
|
+
}
|
|
140
|
+
async showOpenDialog(options) {
|
|
141
|
+
const schema = this.getFileSystemSchema(options);
|
|
142
|
+
if (this.shouldUseSimplified(schema)) {
|
|
143
|
+
return super.showOpenDialogSimplified(schema, options);
|
|
144
|
+
}
|
|
145
|
+
const activeWindow = getActiveWindow();
|
|
146
|
+
if (!WebFileSystemAccess.supported(activeWindow)) {
|
|
147
|
+
return this.showUnsupportedBrowserWarning('open');
|
|
148
|
+
}
|
|
149
|
+
let uri;
|
|
150
|
+
const startIn = Iterable.first(this.fileSystemProvider.directories) ?? 'documents';
|
|
151
|
+
try {
|
|
152
|
+
if (options.canSelectFiles) {
|
|
153
|
+
const handle = await activeWindow.showOpenFilePicker({ multiple: false, types: this.getFilePickerTypes(options.filters), ...{ startIn } });
|
|
154
|
+
if (handle.length === 1 && WebFileSystemAccess.isFileSystemFileHandle(handle[0])) {
|
|
155
|
+
uri = await this.fileSystemProvider.registerFileHandle(handle[0]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const handle = await activeWindow.showDirectoryPicker({ ...{ startIn } });
|
|
160
|
+
uri = await this.fileSystemProvider.registerDirectoryHandle(handle);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
}
|
|
165
|
+
return uri ? [uri] : undefined;
|
|
166
|
+
}
|
|
167
|
+
async showUnsupportedBrowserWarning(context) {
|
|
168
|
+
if (context === 'save') {
|
|
169
|
+
const activeCodeEditor = this.codeEditorService.getActiveCodeEditor();
|
|
170
|
+
if (!(activeCodeEditor instanceof EmbeddedCodeEditorWidget)) {
|
|
171
|
+
const activeTextModel = activeCodeEditor?.getModel();
|
|
172
|
+
if (activeTextModel) {
|
|
173
|
+
triggerDownload(VSBuffer.fromString(activeTextModel.getValue()).buffer, basename(activeTextModel.uri));
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const buttons = [
|
|
179
|
+
{
|
|
180
|
+
label: ( localizeWithPath(
|
|
181
|
+
'vs/workbench/services/dialogs/browser/fileDialogService',
|
|
182
|
+
{ key: 'openRemote', comment: ['&& denotes a mnemonic'] },
|
|
183
|
+
"&&Open Remote..."
|
|
184
|
+
)),
|
|
185
|
+
run: async () => { await this.commandService.executeCommand('workbench.action.remote.showMenu'); }
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
label: ( localizeWithPath(
|
|
189
|
+
'vs/workbench/services/dialogs/browser/fileDialogService',
|
|
190
|
+
{ key: 'learnMore', comment: ['&& denotes a mnemonic'] },
|
|
191
|
+
"&&Learn More"
|
|
192
|
+
)),
|
|
193
|
+
run: async () => { await this.openerService.open('https://aka.ms/VSCodeWebLocalFileSystemAccess'); }
|
|
194
|
+
}
|
|
195
|
+
];
|
|
196
|
+
if (context === 'open') {
|
|
197
|
+
buttons.push({
|
|
198
|
+
label: ( localizeWithPath(
|
|
199
|
+
'vs/workbench/services/dialogs/browser/fileDialogService',
|
|
200
|
+
{ key: 'openFiles', comment: ['&& denotes a mnemonic'] },
|
|
201
|
+
"Open &&Files..."
|
|
202
|
+
)),
|
|
203
|
+
run: async () => {
|
|
204
|
+
const files = await triggerUpload();
|
|
205
|
+
if (files) {
|
|
206
|
+
const filesData = (await this.instantiationService.invokeFunction(accessor => extractFileListData(accessor, files))).filter(fileData => !fileData.isDirectory);
|
|
207
|
+
if (filesData.length > 0) {
|
|
208
|
+
this.editorService.openEditors(( filesData.map(fileData => {
|
|
209
|
+
return {
|
|
210
|
+
resource: fileData.resource,
|
|
211
|
+
contents: fileData.contents?.toString(),
|
|
212
|
+
options: { pinned: true }
|
|
213
|
+
};
|
|
214
|
+
})));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
await this.dialogService.prompt({
|
|
221
|
+
type: Severity$1.Warning,
|
|
222
|
+
message: ( localizeWithPath(
|
|
223
|
+
'vs/workbench/services/dialogs/browser/fileDialogService',
|
|
224
|
+
'unsupportedBrowserMessage',
|
|
225
|
+
"Opening Local Folders is Unsupported"
|
|
226
|
+
)),
|
|
227
|
+
detail: ( localizeWithPath(
|
|
228
|
+
'vs/workbench/services/dialogs/browser/fileDialogService',
|
|
229
|
+
'unsupportedBrowserDetail',
|
|
230
|
+
"Your browser doesn't support opening local folders.\nYou can either open single files or open a remote repository."
|
|
231
|
+
)),
|
|
232
|
+
buttons
|
|
233
|
+
});
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
shouldUseSimplified(scheme) {
|
|
237
|
+
return ![Schemas.file, Schemas.vscodeUserData, Schemas.tmp].includes(scheme);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
FileDialogService.__decorator = ( __decorate([
|
|
241
|
+
memoize
|
|
242
|
+
], FileDialogService.prototype, "fileSystemProvider", null));
|
|
243
|
+
|
|
244
|
+
export { FileDialogService };
|