Path: blob/main/src/vs/workbench/browser/parts/dialogs/dialog.web.contribution.ts
5289 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js';6import { IDialogHandler, IDialogResult, IDialogService } from '../../../../platform/dialogs/common/dialogs.js';7import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';8import { ILayoutService } from '../../../../platform/layout/browser/layoutService.js';9import { ILogService } from '../../../../platform/log/common/log.js';10import { IProductService } from '../../../../platform/product/common/productService.js';11import { IWorkbenchContribution, WorkbenchPhase, registerWorkbenchContribution2 } from '../../../common/contributions.js';12import { IDialogsModel, IDialogViewItem } from '../../../common/dialogs.js';13import { BrowserDialogHandler } from './dialogHandler.js';14import { DialogService } from '../../../services/dialogs/common/dialogService.js';15import { Disposable } from '../../../../base/common/lifecycle.js';16import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';17import { Lazy } from '../../../../base/common/lazy.js';18import { IOpenerService } from '../../../../platform/opener/common/opener.js';19import { createBrowserAboutDialogDetails } from '../../../../platform/dialogs/browser/dialog.js';20import { IMarkdownRendererService } from '../../../../platform/markdown/browser/markdownRenderer.js';2122export class DialogHandlerContribution extends Disposable implements IWorkbenchContribution {2324static readonly ID = 'workbench.contrib.dialogHandler';2526private readonly model: IDialogsModel;27private readonly impl: Lazy<IDialogHandler>;2829private currentDialog: IDialogViewItem | undefined;3031constructor(32@IDialogService private dialogService: IDialogService,33@ILogService logService: ILogService,34@ILayoutService layoutService: ILayoutService,35@IKeybindingService keybindingService: IKeybindingService,36@IInstantiationService instantiationService: IInstantiationService,37@IProductService private productService: IProductService,38@IClipboardService clipboardService: IClipboardService,39@IOpenerService openerService: IOpenerService,40@IMarkdownRendererService markdownRendererService: IMarkdownRendererService,41) {42super();4344this.impl = new Lazy(() => new BrowserDialogHandler(logService, layoutService, keybindingService, instantiationService, clipboardService, openerService, markdownRendererService));45this.model = (this.dialogService as DialogService).model;4647this._register(this.model.onWillShowDialog(() => {48if (!this.currentDialog) {49this.processDialogs();50}51}));5253this.processDialogs();54}5556private async processDialogs(): Promise<void> {57while (this.model.dialogs.length) {58this.currentDialog = this.model.dialogs[0];5960let result: IDialogResult | Error | undefined = undefined;61try {62if (this.currentDialog.args.confirmArgs) {63const args = this.currentDialog.args.confirmArgs;64result = await this.impl.value.confirm(args.confirmation);65} else if (this.currentDialog.args.inputArgs) {66const args = this.currentDialog.args.inputArgs;67result = await this.impl.value.input(args.input);68} else if (this.currentDialog.args.promptArgs) {69const args = this.currentDialog.args.promptArgs;70result = await this.impl.value.prompt(args.prompt);71} else {72const aboutDialogDetails = createBrowserAboutDialogDetails(this.productService);73await this.impl.value.about(aboutDialogDetails.title, aboutDialogDetails.details, aboutDialogDetails.detailsToCopy);74}75} catch (error) {76result = error;77}7879this.currentDialog.close(result);80this.currentDialog = undefined;81}82}83}8485registerWorkbenchContribution2(86DialogHandlerContribution.ID,87DialogHandlerContribution,88WorkbenchPhase.BlockStartup // Block to allow for dialogs to show before restore finished89);909192