Path: blob/main/src/vs/workbench/services/dialogs/common/dialogService.ts
3296 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 Severity from '../../../../base/common/severity.js';6import { Disposable } from '../../../../base/common/lifecycle.js';7import { IAsyncPromptResult, IAsyncPromptResultWithCancel, IConfirmation, IConfirmationResult, IDialogService, IInput, IInputResult, IPrompt, IPromptResult, IPromptResultWithCancel, IPromptWithCustomCancel, IPromptWithDefaultCancel } from '../../../../platform/dialogs/common/dialogs.js';8import { DialogsModel } from '../../../common/dialogs.js';9import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';10import { IWorkbenchEnvironmentService } from '../../environment/common/environmentService.js';11import { ILogService } from '../../../../platform/log/common/log.js';1213export class DialogService extends Disposable implements IDialogService {1415declare readonly _serviceBrand: undefined;1617readonly model = this._register(new DialogsModel());1819readonly onWillShowDialog = this.model.onWillShowDialog;2021readonly onDidShowDialog = this.model.onDidShowDialog;2223constructor(24@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,25@ILogService private readonly logService: ILogService26) {27super();28}2930private skipDialogs(): boolean {31if (this.environmentService.enableSmokeTestDriver) {32this.logService.warn('DialogService: Dialog requested during smoke test.');33}34// integration tests35return this.environmentService.isExtensionDevelopment && !!this.environmentService.extensionTestsLocationURI;36}3738async confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {39if (this.skipDialogs()) {40this.logService.trace('DialogService: refused to show confirmation dialog in tests.');4142return { confirmed: true };43}4445const handle = this.model.show({ confirmArgs: { confirmation } });4647return await handle.result as IConfirmationResult;48}4950prompt<T>(prompt: IPromptWithCustomCancel<T>): Promise<IPromptResultWithCancel<T>>;51prompt<T>(prompt: IPromptWithDefaultCancel<T>): Promise<IPromptResult<T>>;52prompt<T>(prompt: IPrompt<T>): Promise<IPromptResult<T>>;53async prompt<T>(prompt: IPrompt<T> | IPromptWithCustomCancel<T> | IPromptWithDefaultCancel<T>): Promise<IPromptResult<T> | IPromptResultWithCancel<T>> {54if (this.skipDialogs()) {55throw new Error(`DialogService: refused to show dialog in tests. Contents: ${prompt.message}`);56}5758const handle = this.model.show({ promptArgs: { prompt } });5960const dialogResult = await handle.result as IAsyncPromptResult<T> | IAsyncPromptResultWithCancel<T>;6162return {63result: await dialogResult.result,64checkboxChecked: dialogResult.checkboxChecked65};66}6768async input(input: IInput): Promise<IInputResult> {69if (this.skipDialogs()) {70throw new Error('DialogService: refused to show input dialog in tests.');71}7273const handle = this.model.show({ inputArgs: { input } });7475return await handle.result as IInputResult;76}7778async info(message: string, detail?: string): Promise<void> {79await this.prompt({ type: Severity.Info, message, detail });80}8182async warn(message: string, detail?: string): Promise<void> {83await this.prompt({ type: Severity.Warning, message, detail });84}8586async error(message: string, detail?: string): Promise<void> {87await this.prompt({ type: Severity.Error, message, detail });88}8990async about(): Promise<void> {91if (this.skipDialogs()) {92throw new Error('DialogService: refused to show about dialog in tests.');93}9495const handle = this.model.show({});96await handle.result;97}98}99100registerSingleton(IDialogService, DialogService, InstantiationType.Delayed);101102103