Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/browser/mainThreadDialogs.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { URI } from '../../../base/common/uri.js';
7
import { MainThreadDiaglogsShape, MainContext, MainThreadDialogOpenOptions, MainThreadDialogSaveOptions } from '../common/extHost.protocol.js';
8
import { extHostNamedCustomer, IExtHostContext } from '../../services/extensions/common/extHostCustomers.js';
9
import { IFileDialogService, IOpenDialogOptions, ISaveDialogOptions } from '../../../platform/dialogs/common/dialogs.js';
10
11
@extHostNamedCustomer(MainContext.MainThreadDialogs)
12
export class MainThreadDialogs implements MainThreadDiaglogsShape {
13
14
constructor(
15
context: IExtHostContext,
16
@IFileDialogService private readonly _fileDialogService: IFileDialogService,
17
) {
18
//
19
}
20
21
dispose(): void {
22
//
23
}
24
25
async $showOpenDialog(options?: MainThreadDialogOpenOptions): Promise<URI[] | undefined> {
26
const convertedOptions = MainThreadDialogs._convertOpenOptions(options);
27
if (!convertedOptions.defaultUri) {
28
convertedOptions.defaultUri = await this._fileDialogService.defaultFilePath();
29
}
30
return Promise.resolve(this._fileDialogService.showOpenDialog(convertedOptions));
31
}
32
33
async $showSaveDialog(options?: MainThreadDialogSaveOptions): Promise<URI | undefined> {
34
const convertedOptions = MainThreadDialogs._convertSaveOptions(options);
35
if (!convertedOptions.defaultUri) {
36
convertedOptions.defaultUri = await this._fileDialogService.defaultFilePath();
37
}
38
return Promise.resolve(this._fileDialogService.showSaveDialog(convertedOptions));
39
}
40
41
private static _convertOpenOptions(options?: MainThreadDialogOpenOptions): IOpenDialogOptions {
42
const result: IOpenDialogOptions = {
43
openLabel: options?.openLabel || undefined,
44
canSelectFiles: options?.canSelectFiles || (!options?.canSelectFiles && !options?.canSelectFolders),
45
canSelectFolders: options?.canSelectFolders,
46
canSelectMany: options?.canSelectMany,
47
defaultUri: options?.defaultUri ? URI.revive(options.defaultUri) : undefined,
48
title: options?.title || undefined,
49
availableFileSystems: []
50
};
51
if (options?.filters) {
52
result.filters = [];
53
for (const [key, value] of Object.entries(options.filters)) {
54
result.filters.push({ name: key, extensions: value });
55
}
56
}
57
return result;
58
}
59
60
private static _convertSaveOptions(options?: MainThreadDialogSaveOptions): ISaveDialogOptions {
61
const result: ISaveDialogOptions = {
62
defaultUri: options?.defaultUri ? URI.revive(options.defaultUri) : undefined,
63
saveLabel: options?.saveLabel || undefined,
64
title: options?.title || undefined
65
};
66
if (options?.filters) {
67
result.filters = [];
68
for (const [key, value] of Object.entries(options.filters)) {
69
result.filters.push({ name: key, extensions: value });
70
}
71
}
72
return result;
73
}
74
}
75
76