Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/electron-browser/parts/dialogs/dialogHandler.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 { localize } from '../../../../nls.js';
7
import { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js';
8
import { AbstractDialogHandler, IConfirmation, IConfirmationResult, IPrompt, IAsyncPromptResult } from '../../../../platform/dialogs/common/dialogs.js';
9
import { ILogService } from '../../../../platform/log/common/log.js';
10
import { INativeHostService } from '../../../../platform/native/common/native.js';
11
import { getActiveWindow } from '../../../../base/browser/dom.js';
12
13
export class NativeDialogHandler extends AbstractDialogHandler {
14
15
constructor(
16
@ILogService private readonly logService: ILogService,
17
@INativeHostService private readonly nativeHostService: INativeHostService,
18
@IClipboardService private readonly clipboardService: IClipboardService
19
) {
20
super();
21
}
22
23
async prompt<T>(prompt: IPrompt<T>): Promise<IAsyncPromptResult<T>> {
24
this.logService.trace('DialogService#prompt', prompt.message);
25
26
const buttons = this.getPromptButtons(prompt);
27
28
const { response, checkboxChecked } = await this.nativeHostService.showMessageBox({
29
type: this.getDialogType(prompt.type),
30
title: prompt.title,
31
message: prompt.message,
32
detail: prompt.detail,
33
buttons,
34
cancelId: prompt.cancelButton ? buttons.length - 1 : -1 /* Disabled */,
35
checkboxLabel: prompt.checkbox?.label,
36
checkboxChecked: prompt.checkbox?.checked,
37
targetWindowId: getActiveWindow().vscodeWindowId
38
});
39
40
return this.getPromptResult(prompt, response, checkboxChecked);
41
}
42
43
async confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
44
this.logService.trace('DialogService#confirm', confirmation.message);
45
46
const buttons = this.getConfirmationButtons(confirmation);
47
48
const { response, checkboxChecked } = await this.nativeHostService.showMessageBox({
49
type: this.getDialogType(confirmation.type) ?? 'question',
50
title: confirmation.title,
51
message: confirmation.message,
52
detail: confirmation.detail,
53
buttons,
54
cancelId: buttons.length - 1,
55
checkboxLabel: confirmation.checkbox?.label,
56
checkboxChecked: confirmation.checkbox?.checked,
57
targetWindowId: getActiveWindow().vscodeWindowId
58
});
59
60
return { confirmed: response === 0, checkboxChecked };
61
}
62
63
input(): never {
64
throw new Error('Unsupported'); // we have no native API for password dialogs in Electron
65
}
66
67
async about(title: string, details: string, detailsToCopy: string): Promise<void> {
68
const { response } = await this.nativeHostService.showMessageBox({
69
type: 'info',
70
message: title,
71
detail: `\n${details}`,
72
buttons: [
73
localize({ key: 'copy', comment: ['&& denotes a mnemonic'] }, "&&Copy"),
74
localize('okButton', "OK")
75
],
76
targetWindowId: getActiveWindow().vscodeWindowId
77
});
78
79
if (response === 0) {
80
this.clipboardService.writeText(detailsToCopy);
81
}
82
}
83
}
84
85