Path: blob/main/src/vs/workbench/electron-browser/parts/dialogs/dialog.contribution.ts
5303 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 { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';7import { IDialogHandler, IDialogResult, IDialogService } from '../../../../platform/dialogs/common/dialogs.js';8import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';9import { ILayoutService } from '../../../../platform/layout/browser/layoutService.js';10import { ILogService } from '../../../../platform/log/common/log.js';11import { INativeHostService } from '../../../../platform/native/common/native.js';12import { IProductService } from '../../../../platform/product/common/productService.js';13import { IWorkbenchContribution, WorkbenchPhase, registerWorkbenchContribution2 } from '../../../common/contributions.js';14import { IDialogsModel, IDialogViewItem } from '../../../common/dialogs.js';15import { BrowserDialogHandler } from '../../../browser/parts/dialogs/dialogHandler.js';16import { NativeDialogHandler } from './dialogHandler.js';17import { DialogService } from '../../../services/dialogs/common/dialogService.js';18import { Disposable } from '../../../../base/common/lifecycle.js';19import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';20import { Lazy } from '../../../../base/common/lazy.js';21import { IOpenerService } from '../../../../platform/opener/common/opener.js';22import { createNativeAboutDialogDetails } from '../../../../platform/dialogs/electron-browser/dialog.js';23import { IWorkbenchEnvironmentService } from '../../../services/environment/common/environmentService.js';24import { IMarkdownRendererService } from '../../../../platform/markdown/browser/markdownRenderer.js';2526export class DialogHandlerContribution extends Disposable implements IWorkbenchContribution {2728static readonly ID = 'workbench.contrib.dialogHandler';2930private nativeImpl: Lazy<IDialogHandler>;31private browserImpl: Lazy<IDialogHandler>;3233private model: IDialogsModel;34private currentDialog: IDialogViewItem | undefined;3536constructor(37@IConfigurationService private configurationService: IConfigurationService,38@IDialogService private dialogService: IDialogService,39@ILogService logService: ILogService,40@ILayoutService layoutService: ILayoutService,41@IKeybindingService keybindingService: IKeybindingService,42@IInstantiationService instantiationService: IInstantiationService,43@IProductService private productService: IProductService,44@IClipboardService clipboardService: IClipboardService,45@INativeHostService private nativeHostService: INativeHostService,46@IWorkbenchEnvironmentService private environmentService: IWorkbenchEnvironmentService,47@IOpenerService openerService: IOpenerService,48@IMarkdownRendererService markdownRendererService: IMarkdownRendererService,49) {50super();5152this.browserImpl = new Lazy(() => new BrowserDialogHandler(logService, layoutService, keybindingService, instantiationService, clipboardService, openerService, markdownRendererService));53this.nativeImpl = new Lazy(() => new NativeDialogHandler(logService, nativeHostService, clipboardService));5455this.model = (this.dialogService as DialogService).model;5657this._register(this.model.onWillShowDialog(() => {58if (!this.currentDialog) {59this.processDialogs();60}61}));6263this.processDialogs();64}6566private async processDialogs(): Promise<void> {67while (this.model.dialogs.length) {68this.currentDialog = this.model.dialogs[0];6970let result: IDialogResult | Error | undefined = undefined;71try {7273// Confirm74if (this.currentDialog.args.confirmArgs) {75const args = this.currentDialog.args.confirmArgs;76result = (this.useCustomDialog || args?.confirmation.custom) ?77await this.browserImpl.value.confirm(args.confirmation) :78await this.nativeImpl.value.confirm(args.confirmation);79}8081// Input (custom only)82else if (this.currentDialog.args.inputArgs) {83const args = this.currentDialog.args.inputArgs;84result = await this.browserImpl.value.input(args.input);85}8687// Prompt88else if (this.currentDialog.args.promptArgs) {89const args = this.currentDialog.args.promptArgs;90result = (this.useCustomDialog || args?.prompt.custom) ?91await this.browserImpl.value.prompt(args.prompt) :92await this.nativeImpl.value.prompt(args.prompt);93}9495// About96else {97const aboutDialogDetails = createNativeAboutDialogDetails(this.productService, await this.nativeHostService.getOSProperties());9899if (this.useCustomDialog) {100await this.browserImpl.value.about(aboutDialogDetails.title, aboutDialogDetails.details, aboutDialogDetails.detailsToCopy);101} else {102await this.nativeImpl.value.about(aboutDialogDetails.title, aboutDialogDetails.details, aboutDialogDetails.detailsToCopy);103}104}105} catch (error) {106result = error;107}108109this.currentDialog.close(result);110this.currentDialog = undefined;111}112}113114private get useCustomDialog(): boolean {115return this.configurationService.getValue('window.dialogStyle') === 'custom' ||116// Use the custom dialog while driven so that the driver can interact with it117!!this.environmentService.enableSmokeTestDriver;118}119}120121registerWorkbenchContribution2(122DialogHandlerContribution.ID,123DialogHandlerContribution,124WorkbenchPhase.BlockStartup // Block to allow for dialogs to show before restore finished125);126127128