UNPKG

@sussudio/platform

Version:

Internal APIs for VS Code's service injection the base services.

329 lines (327 loc) 11.1 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { Event } from '@sussudio/base/common/event.mjs'; import { Codicon } from '@sussudio/base/common/codicons.mjs'; import { IMarkdownString } from '@sussudio/base/common/htmlContent.mjs'; import Severity from '@sussudio/base/common/severity.mjs'; import { URI } from '@sussudio/base/common/uri.mjs'; import { ITelemetryData } from '../../telemetry/common/telemetry.mjs'; export interface FileFilter { readonly extensions: string[]; readonly name: string; } export type DialogType = 'none' | 'info' | 'error' | 'question' | 'warning'; export interface ICheckbox { readonly label: string; readonly checked?: boolean; } export interface IConfirmDialogArgs { readonly confirmation: IConfirmation; } export interface IShowDialogArgs { readonly severity: Severity; readonly message: string; readonly buttons?: string[]; readonly options?: IDialogOptions; } export interface IInputDialogArgs extends IShowDialogArgs { readonly buttons: string[]; readonly inputs: IInput[]; } export interface IDialog { readonly confirmArgs?: IConfirmDialogArgs; readonly showArgs?: IShowDialogArgs; readonly inputArgs?: IInputDialogArgs; } export type IDialogResult = IConfirmationResult | IInputResult | IShowResult; export interface IConfirmation { readonly title?: string; readonly type?: DialogType; readonly message: string; readonly detail?: string; readonly primaryButton?: string; readonly secondaryButton?: string; readonly checkbox?: ICheckbox; } export interface IConfirmationResult { /** * Will be true if the dialog was confirmed with the primary button * pressed. */ readonly confirmed: boolean; /** * This will only be defined if the confirmation was created * with the checkbox option defined. */ readonly checkboxChecked?: boolean; } export interface IShowResult { /** * Selected choice index. If the user refused to choose, * then a promise with index of `cancelId` option is returned. If there is no such * option then promise with index `0` is returned. */ readonly choice: number; /** * This will only be defined if the confirmation was created * with the checkbox option defined. */ readonly checkboxChecked?: boolean; } export interface IInputResult extends IShowResult { /** * Values for the input fields as provided by the user * or `undefined` if none. */ readonly values?: string[]; } export interface IPickAndOpenOptions { forceNewWindow?: boolean; defaultUri?: URI; telemetryExtraData?: ITelemetryData; availableFileSystems?: string[]; remoteAuthority?: string | null; } 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 */ saveLabel?: 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 */ title?: string; /** * The resource the dialog shows when opened. */ defaultUri?: URI; /** * A human-readable string for the open button. */ openLabel?: 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. */ 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 declare const IDialogService: import('../../instantiation/common/instantiation.mjs').ServiceIdentifier<IDialogService>; export interface ICustomDialogOptions { readonly buttonDetails?: string[]; readonly markdownDetails?: ICustomDialogMarkdown[]; readonly classes?: string[]; readonly icon?: Codicon; readonly disableCloseAction?: boolean; } export interface ICustomDialogMarkdown { readonly markdown: IMarkdownString; readonly classes?: string[]; } export interface IDialogOptions { readonly cancelId?: number; readonly detail?: string; readonly checkbox?: ICheckbox; readonly custom?: boolean | ICustomDialogOptions; } export interface IInput { readonly placeholder?: string; readonly type?: 'text' | 'password'; readonly value?: string; } /** * A handler to bring up modal dialogs. */ export interface IDialogHandler { /** * Ask the user for confirmation with a modal dialog. */ confirm(confirmation: IConfirmation): Promise<IConfirmationResult>; /** * Present a modal dialog to the user. * * @returns A promise with the selected choice index. If the user refused to choose, * then a promise with index of `cancelId` option is returned. If there is no such * option then promise with index `0` is returned. */ show(severity: Severity, message: string, buttons?: string[], options?: IDialogOptions): Promise<IShowResult>; /** * Present a modal dialog to the user asking for input. * * @returns A promise with the selected choice index. If the user refused to choose, * then a promise with index of `cancelId` option is returned. If there is no such * option then promise with index `0` is returned. In addition, the values for the * inputs are returned as well. */ input( severity: Severity, message: string, buttons: string[], inputs: IInput[], options?: IDialogOptions, ): Promise<IInputResult>; /** * Present the about dialog to the user. */ about(): Promise<void>; } /** * A service to bring up modal dialogs. * * Note: use the `INotificationService.prompt()` method for a non-modal way to ask * the user for input. */ export interface IDialogService { readonly _serviceBrand: undefined; /** * An event that fires when a dialog is about to show. */ onWillShowDialog: Event<void>; /** * An event that fires when a dialog did show (closed). */ onDidShowDialog: Event<void>; /** * Ask the user for confirmation with a modal dialog. */ confirm(confirmation: IConfirmation): Promise<IConfirmationResult>; /** * Present a modal dialog to the user. * * @param severity the severity of the message * @param message the message to show * @param buttons the buttons to show. By convention, the first button should be the * primary action and the last button the "Cancel" action. * * @returns A promise with the selected choice index. If the user refused to choose, * then a promise with index of `cancelId` option is returned. If there is no such * option then promise with index `0` is returned. */ show(severity: Severity, message: string, buttons?: string[], options?: IDialogOptions): Promise<IShowResult>; /** * Present a modal dialog to the user asking for input. * * @returns A promise with the selected choice index. If the user refused to choose, * then a promise with index of `cancelId` option is returned. If there is no such * option then promise with index `0` is returned. In addition, the values for the * inputs are returned as well. */ input( severity: Severity, message: string, buttons: string[], inputs: IInput[], options?: IDialogOptions, ): Promise<IInputResult>; /** * Present the about dialog to the user. */ about(): Promise<void>; } export declare const IFileDialogService: import('../../instantiation/common/instantiation.mjs').ServiceIdentifier<IFileDialogService>; /** * A service to bring up file dialogs. */ export interface IFileDialogService { readonly _serviceBrand: undefined; /** * The default path for a new file based on previously used files. * @param schemeFilter The scheme of the file path. If no filter given, the scheme of the current window is used. * Falls back to user home in the absence of enough information to find a better URI. */ defaultFilePath(schemeFilter?: string): Promise<URI>; /** * The default path for a new folder based on previously used folders. * @param schemeFilter The scheme of the folder path. If no filter given, the scheme of the current window is used. * Falls back to user home in the absence of enough information to find a better URI. */ defaultFolderPath(schemeFilter?: string): Promise<URI>; /** * The default path for a new workspace based on previously used workspaces. * @param schemeFilter The scheme of the workspace path. If no filter given, the scheme of the current window is used. * Falls back to user home in the absence of enough information to find a better URI. */ defaultWorkspacePath(schemeFilter?: string): Promise<URI>; /** * Shows a file-folder selection dialog and opens the selected entry. */ pickFileFolderAndOpen(options: IPickAndOpenOptions): Promise<void>; /** * Shows a file selection dialog and opens the selected entry. */ pickFileAndOpen(options: IPickAndOpenOptions): Promise<void>; /** * Shows a folder selection dialog and opens the selected entry. */ pickFolderAndOpen(options: IPickAndOpenOptions): Promise<void>; /** * Shows a workspace selection dialog and opens the selected entry. */ pickWorkspaceAndOpen(options: IPickAndOpenOptions): Promise<void>; /** * Shows a save file dialog and save the file at the chosen file URI. */ pickFileToSave(defaultUri: URI, availableFileSystems?: string[]): Promise<URI | undefined>; /** * Shows a save file dialog and returns the chosen file URI. */ showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined>; /** * Shows a confirm dialog for saving 1-N files. */ showSaveConfirm(fileNamesOrResources: (string | URI)[]): Promise<ConfirmResult>; /** * Shows a open file dialog and returns the chosen file URI. */ showOpenDialog(options: IOpenDialogOptions): Promise<URI[] | undefined>; } export declare const 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; }