import { CancellationToken } from "../../../base/common/cancellation.js"; import { ThemeIcon } from "../../../base/common/themables.js"; import { IMarkdownString } from "../../../base/common/htmlContent.js"; import Severity from "../../../base/common/severity.js"; import { URI } from "../../../base/common/uri.js"; import { ITelemetryData } from "../../telemetry/common/telemetry.js"; import { MessageBoxOptions } from "../../../base/parts/sandbox/common/electronTypes.js"; import { IProductService } from "../../product/common/productService.service.js"; export interface IDialogArgs { readonly confirmArgs?: IConfirmDialogArgs; readonly inputArgs?: IInputDialogArgs; readonly promptArgs?: IPromptDialogArgs; } export interface IBaseDialogOptions { readonly type?: Severity | DialogType; readonly title?: string; readonly message: string; readonly detail?: string; readonly checkbox?: ICheckbox; /** * Allows to enforce use of custom dialog even in native environments. */ readonly custom?: boolean | ICustomDialogOptions; /** * An optional cancellation token that can be used to dismiss the dialog * programmatically for custom dialog implementations. * * When cancelled, the custom dialog resolves as if the cancel button was * pressed. Native dialog handlers cannot currently be dismissed * programmatically and ignore this option unless a custom dialog is * explicitly enforced via the {@link custom} option. */ readonly token?: CancellationToken; } export interface IConfirmDialogArgs { readonly confirmation: IConfirmation; } export interface IConfirmation extends IBaseDialogOptions { /** * If not provided, defaults to `Yes`. */ readonly primaryButton?: string; /** * If not provided, defaults to `Cancel`. */ readonly cancelButton?: string; } export interface IConfirmationResult extends ICheckboxResult { /** * Will be true if the dialog was confirmed with the primary button pressed. */ readonly confirmed: boolean; } export interface IInputDialogArgs { readonly input: IInput; } export interface IInput extends IConfirmation { readonly inputs: IInputElement[]; /** * If not provided, defaults to `Ok`. */ readonly primaryButton?: string; } export interface IInputElement { readonly type?: "text" | "password"; readonly value?: string; readonly placeholder?: string; } export interface IInputResult extends IConfirmationResult { /** * Values for the input fields as provided by the user or `undefined` if none. */ readonly values?: string[]; } export interface IPromptDialogArgs { readonly prompt: IPrompt; } export interface IPromptBaseButton { /** * @returns the result of the prompt button will be returned * as result from the `prompt()` call. */ run(checkbox: ICheckboxResult): T | Promise; } export interface IPromptButton extends IPromptBaseButton { readonly label: string; } export interface IPromptCancelButton extends IPromptBaseButton { /** * The cancel button to show in the prompt. Defaults to * `Cancel` if not provided. */ readonly label?: string; } export interface IPrompt extends IBaseDialogOptions { /** * The buttons to show in the prompt. Defaults to `OK` * if no buttons or cancel button is provided. */ readonly buttons?: IPromptButton[]; /** * The cancel button to show in the prompt. Defaults to * `Cancel` if set to `true`. */ readonly cancelButton?: IPromptCancelButton | true | string; } export interface IPromptWithCustomCancel extends IPrompt { readonly cancelButton: IPromptCancelButton; } export interface IPromptWithDefaultCancel extends IPrompt { readonly cancelButton: true | string; } export interface IPromptResult extends ICheckboxResult { /** * The result of the `IPromptButton` that was pressed or `undefined` if none. */ readonly result?: T; } export interface IPromptResultWithCancel extends IPromptResult { readonly result: T; } export interface IAsyncPromptResult extends ICheckboxResult { /** * The result of the `IPromptButton` that was pressed or `undefined` if none. */ readonly result?: Promise; } export interface IAsyncPromptResultWithCancel extends IAsyncPromptResult { readonly result: Promise; } export type IDialogResult = IConfirmationResult | IInputResult | IAsyncPromptResult; export type DialogType = "none" | "info" | "error" | "question" | "warning"; export interface ICheckbox { readonly label: string; readonly checked?: boolean; } export interface ICheckboxResult { /** * This will only be defined if the confirmation was created * with the checkbox option defined. */ readonly checkboxChecked?: boolean; } export interface IPickAndOpenOptions { readonly forceNewWindow?: boolean; defaultUri?: URI; readonly telemetryExtraData?: ITelemetryData; availableFileSystems?: string[]; remoteAuthority?: string | null; } export interface FileFilter { readonly extensions: string[]; readonly name: string; } export interface ISaveDialogOptions { /** * A human-readable string for the dialog title */ title?: string; /** * The resource the dialog shows when opened. */ defaultUri?: URI; /** * A set of file filters that are used by the dialog. Each entry is a human readable label, * like "TypeScript", and an array of extensions. */ filters?: FileFilter[]; /** * A human-readable string for the ok button */ readonly saveLabel?: { readonly withMnemonic: string; readonly withoutMnemonic: string; } | string; /** * Specifies a list of schemas for the file systems the user can save to. If not specified, uses the schema of the defaultURI or, if also not specified, * the schema of the current window. */ availableFileSystems?: readonly string[]; } export interface IOpenDialogOptions { /** * A human-readable string for the dialog title */ readonly title?: string; /** * The resource the dialog shows when opened. */ defaultUri?: URI; /** * A human-readable string for the open button. */ readonly openLabel?: { readonly withMnemonic: string; readonly withoutMnemonic: string; } | string; /** * Allow to select files, defaults to `true`. */ canSelectFiles?: boolean; /** * Allow to select folders, defaults to `false`. */ canSelectFolders?: boolean; /** * Allow to select many files or folders. */ readonly canSelectMany?: boolean; /** * A set of file filters that are used by the dialog. Each entry is a human readable label, * like "TypeScript", and an array of extensions. */ filters?: FileFilter[]; /** * Specifies a list of schemas for the file systems the user can load from. If not specified, uses the schema of the defaultURI or, if also not available, * the schema of the current window. */ availableFileSystems?: readonly string[]; } export interface ICustomDialogOptions { readonly buttonDetails?: string[]; readonly markdownDetails?: ICustomDialogMarkdown[]; readonly classes?: string[]; readonly icon?: ThemeIcon; readonly disableCloseAction?: boolean; } export interface ICustomDialogMarkdown { readonly markdown: IMarkdownString; readonly classes?: string[]; /** Custom link handler for markdown content, see {@link IContentActionHandler}. Defaults to {@link openLinkFromMarkdown}. */ actionHandler?(link: string): Promise; } /** * A handler to bring up modal dialogs. */ export interface IDialogHandler { /** * Ask the user for confirmation with a modal dialog. */ confirm(confirmation: IConfirmation): Promise; /** * Prompt the user with a modal dialog. */ prompt(prompt: IPrompt): Promise>; /** * Present a modal dialog to the user asking for input. */ input(input: IInput): Promise; /** * Present the about dialog to the user. */ about(title: string, details: string, detailsToCopy: string): Promise; } export declare abstract class AbstractDialogHandler implements IDialogHandler { protected getConfirmationButtons(dialog: IConfirmation): string[]; protected getPromptButtons(dialog: IPrompt): string[]; protected getInputButtons(dialog: IInput): string[]; private getButtons; protected getDialogType(type: Severity | DialogType | undefined): DialogType | undefined; protected getPromptResult(prompt: IPrompt, buttonIndex: number, checkboxChecked: boolean | undefined): IAsyncPromptResult; abstract confirm(confirmation: IConfirmation): Promise; abstract input(input: IInput): Promise; abstract prompt(prompt: IPrompt): Promise>; abstract about(title: string, details: string, detailsToCopy: string): Promise; } export declare enum ConfirmResult { SAVE = 0, DONT_SAVE = 1, CANCEL = 2 } export declare function getFileNamesMessage(fileNamesOrResources: readonly (string | URI)[]): string; export interface INativeOpenDialogOptions { readonly forceNewWindow?: boolean; readonly defaultPath?: string; readonly telemetryEventName?: string; readonly telemetryExtraData?: ITelemetryData; } export interface IMassagedMessageBoxOptions { /** * OS massaged message box options. */ readonly options: MessageBoxOptions; /** * Since the massaged result of the message box options potentially * changes the order of buttons, we have to keep a map of these * changes so that we can still return the correct index to the caller. */ readonly buttonIndeces: number[]; } /** * A utility method to ensure the options for the message box dialog * are using properties that are consistent across all platforms and * specific to the platform where necessary. */ export declare function massageMessageBoxOptions(options: MessageBoxOptions, productService: IProductService): IMassagedMessageBoxOptions;