Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/dialogs/common/dialogService.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 Severity from '../../../../base/common/severity.js';
7
import { Disposable } from '../../../../base/common/lifecycle.js';
8
import { IAsyncPromptResult, IAsyncPromptResultWithCancel, IConfirmation, IConfirmationResult, IDialogService, IInput, IInputResult, IPrompt, IPromptResult, IPromptResultWithCancel, IPromptWithCustomCancel, IPromptWithDefaultCancel } from '../../../../platform/dialogs/common/dialogs.js';
9
import { DialogsModel } from '../../../common/dialogs.js';
10
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
11
import { IWorkbenchEnvironmentService } from '../../environment/common/environmentService.js';
12
import { ILogService } from '../../../../platform/log/common/log.js';
13
14
export class DialogService extends Disposable implements IDialogService {
15
16
declare readonly _serviceBrand: undefined;
17
18
readonly model = this._register(new DialogsModel());
19
20
readonly onWillShowDialog = this.model.onWillShowDialog;
21
22
readonly onDidShowDialog = this.model.onDidShowDialog;
23
24
constructor(
25
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
26
@ILogService private readonly logService: ILogService
27
) {
28
super();
29
}
30
31
private skipDialogs(): boolean {
32
if (this.environmentService.enableSmokeTestDriver) {
33
this.logService.warn('DialogService: Dialog requested during smoke test.');
34
}
35
// integration tests
36
return this.environmentService.isExtensionDevelopment && !!this.environmentService.extensionTestsLocationURI;
37
}
38
39
async confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
40
if (this.skipDialogs()) {
41
this.logService.trace('DialogService: refused to show confirmation dialog in tests.');
42
43
return { confirmed: true };
44
}
45
46
const handle = this.model.show({ confirmArgs: { confirmation } });
47
48
return await handle.result as IConfirmationResult;
49
}
50
51
prompt<T>(prompt: IPromptWithCustomCancel<T>): Promise<IPromptResultWithCancel<T>>;
52
prompt<T>(prompt: IPromptWithDefaultCancel<T>): Promise<IPromptResult<T>>;
53
prompt<T>(prompt: IPrompt<T>): Promise<IPromptResult<T>>;
54
async prompt<T>(prompt: IPrompt<T> | IPromptWithCustomCancel<T> | IPromptWithDefaultCancel<T>): Promise<IPromptResult<T> | IPromptResultWithCancel<T>> {
55
if (this.skipDialogs()) {
56
throw new Error(`DialogService: refused to show dialog in tests. Contents: ${prompt.message}`);
57
}
58
59
const handle = this.model.show({ promptArgs: { prompt } });
60
61
const dialogResult = await handle.result as IAsyncPromptResult<T> | IAsyncPromptResultWithCancel<T>;
62
63
return {
64
result: await dialogResult.result,
65
checkboxChecked: dialogResult.checkboxChecked
66
};
67
}
68
69
async input(input: IInput): Promise<IInputResult> {
70
if (this.skipDialogs()) {
71
throw new Error('DialogService: refused to show input dialog in tests.');
72
}
73
74
const handle = this.model.show({ inputArgs: { input } });
75
76
return await handle.result as IInputResult;
77
}
78
79
async info(message: string, detail?: string): Promise<void> {
80
await this.prompt({ type: Severity.Info, message, detail });
81
}
82
83
async warn(message: string, detail?: string): Promise<void> {
84
await this.prompt({ type: Severity.Warning, message, detail });
85
}
86
87
async error(message: string, detail?: string): Promise<void> {
88
await this.prompt({ type: Severity.Error, message, detail });
89
}
90
91
async about(): Promise<void> {
92
if (this.skipDialogs()) {
93
throw new Error('DialogService: refused to show about dialog in tests.');
94
}
95
96
const handle = this.model.show({});
97
await handle.result;
98
}
99
}
100
101
registerSingleton(IDialogService, DialogService, InstantiationType.Delayed);
102
103