Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/browser/parts/dialogs/dialog.web.contribution.ts
5289 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 { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js';
7
import { IDialogHandler, IDialogResult, IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
8
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';
9
import { ILayoutService } from '../../../../platform/layout/browser/layoutService.js';
10
import { ILogService } from '../../../../platform/log/common/log.js';
11
import { IProductService } from '../../../../platform/product/common/productService.js';
12
import { IWorkbenchContribution, WorkbenchPhase, registerWorkbenchContribution2 } from '../../../common/contributions.js';
13
import { IDialogsModel, IDialogViewItem } from '../../../common/dialogs.js';
14
import { BrowserDialogHandler } from './dialogHandler.js';
15
import { DialogService } from '../../../services/dialogs/common/dialogService.js';
16
import { Disposable } from '../../../../base/common/lifecycle.js';
17
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
18
import { Lazy } from '../../../../base/common/lazy.js';
19
import { IOpenerService } from '../../../../platform/opener/common/opener.js';
20
import { createBrowserAboutDialogDetails } from '../../../../platform/dialogs/browser/dialog.js';
21
import { IMarkdownRendererService } from '../../../../platform/markdown/browser/markdownRenderer.js';
22
23
export class DialogHandlerContribution extends Disposable implements IWorkbenchContribution {
24
25
static readonly ID = 'workbench.contrib.dialogHandler';
26
27
private readonly model: IDialogsModel;
28
private readonly impl: Lazy<IDialogHandler>;
29
30
private currentDialog: IDialogViewItem | undefined;
31
32
constructor(
33
@IDialogService private dialogService: IDialogService,
34
@ILogService logService: ILogService,
35
@ILayoutService layoutService: ILayoutService,
36
@IKeybindingService keybindingService: IKeybindingService,
37
@IInstantiationService instantiationService: IInstantiationService,
38
@IProductService private productService: IProductService,
39
@IClipboardService clipboardService: IClipboardService,
40
@IOpenerService openerService: IOpenerService,
41
@IMarkdownRendererService markdownRendererService: IMarkdownRendererService,
42
) {
43
super();
44
45
this.impl = new Lazy(() => new BrowserDialogHandler(logService, layoutService, keybindingService, instantiationService, clipboardService, openerService, markdownRendererService));
46
this.model = (this.dialogService as DialogService).model;
47
48
this._register(this.model.onWillShowDialog(() => {
49
if (!this.currentDialog) {
50
this.processDialogs();
51
}
52
}));
53
54
this.processDialogs();
55
}
56
57
private async processDialogs(): Promise<void> {
58
while (this.model.dialogs.length) {
59
this.currentDialog = this.model.dialogs[0];
60
61
let result: IDialogResult | Error | undefined = undefined;
62
try {
63
if (this.currentDialog.args.confirmArgs) {
64
const args = this.currentDialog.args.confirmArgs;
65
result = await this.impl.value.confirm(args.confirmation);
66
} else if (this.currentDialog.args.inputArgs) {
67
const args = this.currentDialog.args.inputArgs;
68
result = await this.impl.value.input(args.input);
69
} else if (this.currentDialog.args.promptArgs) {
70
const args = this.currentDialog.args.promptArgs;
71
result = await this.impl.value.prompt(args.prompt);
72
} else {
73
const aboutDialogDetails = createBrowserAboutDialogDetails(this.productService);
74
await this.impl.value.about(aboutDialogDetails.title, aboutDialogDetails.details, aboutDialogDetails.detailsToCopy);
75
}
76
} catch (error) {
77
result = error;
78
}
79
80
this.currentDialog.close(result);
81
this.currentDialog = undefined;
82
}
83
}
84
}
85
86
registerWorkbenchContribution2(
87
DialogHandlerContribution.ID,
88
DialogHandlerContribution,
89
WorkbenchPhase.BlockStartup // Block to allow for dialogs to show before restore finished
90
);
91
92