/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { CancellationToken } from 'vs/base/common/cancellation'; import { ResolvedKeybinding } from 'vs/base/common/keyCodes'; import { URI } from 'vs/base/common/uri'; import { Event } from 'vs/base/common/event'; export interface IQuickPickItem { type?: 'item'; id?: string; label: string; description?: string; detail?: string; iconClasses?: string[]; buttons?: IQuickInputButton[]; picked?: boolean; alwaysShow?: boolean; } export interface IQuickPickSeparator { type: 'separator'; label?: string; } export interface IKeyMods { readonly ctrlCmd: boolean; readonly alt: boolean; } export interface IQuickNavigateConfiguration { keybindings: ResolvedKeybinding[]; } export interface IPickOptions { /** * an optional string to show as place holder in the input box to guide the user what she picks on */ placeHolder?: string; /** * an optional flag to include the description when filtering the picks */ matchOnDescription?: boolean; /** * an optional flag to include the detail when filtering the picks */ matchOnDetail?: boolean; /** * an optional flag to filter the picks based on label. Defaults to true. */ matchOnLabel?: boolean; /** * an option flag to control whether focus is always automatically brought to a list item. Defaults to true. */ autoFocusOnList?: boolean; /** * an optional flag to not close the picker on focus lost */ ignoreFocusLost?: boolean; /** * an optional flag to make this picker multi-select */ canPickMany?: boolean; /** * enables quick navigate in the picker to open an element without typing */ quickNavigate?: IQuickNavigateConfiguration; /** * a context key to set when this picker is active */ contextKey?: string; /** * an optional property for the item to focus initially. */ activeItem?: Promise | T; onKeyMods?: (keyMods: IKeyMods) => void; onDidFocus?: (entry: T) => void; onDidTriggerItemButton?: (context: IQuickPickItemButtonContext) => void; } export interface IInputOptions { /** * the value to prefill in the input box */ value?: string; /** * the selection of value, default to the whole word */ valueSelection?: [number, number]; /** * the text to display underneath the input box */ prompt?: string; /** * an optional string to show as place holder in the input box to guide the user what to type */ placeHolder?: string; /** * set to true to show a password prompt that will not show the typed value */ password?: boolean; ignoreFocusLost?: boolean; /** * an optional function that is used to validate user input. */ validateInput?: (input: string) => Promise; } export interface IQuickInput { title: string | undefined; step: number | undefined; totalSteps: number | undefined; enabled: boolean; contextKey: string | undefined; busy: boolean; ignoreFocusOut: boolean; show(): void; hide(): void; onDidHide: Event; dispose(): void; } export interface IQuickPick extends IQuickInput { value: string; placeholder: string | undefined; readonly onDidChangeValue: Event; readonly onDidAccept: Event; ok: boolean; readonly onDidCustom: Event; customButton: boolean; customLabel: string; customHover: string; buttons: ReadonlyArray; readonly onDidTriggerButton: Event; readonly onDidTriggerItemButton: Event>; items: ReadonlyArray; canSelectMany: boolean; matchOnDescription: boolean; matchOnDetail: boolean; matchOnLabel: boolean; autoFocusOnList: boolean; quickNavigate: IQuickNavigateConfiguration | undefined; activeItems: ReadonlyArray; readonly onDidChangeActive: Event; selectedItems: ReadonlyArray; readonly onDidChangeSelection: Event; readonly keyMods: IKeyMods; valueSelection: Readonly<[number, number]> | undefined; validationMessage: string | undefined; inputHasFocus(): boolean; } export interface IInputBox extends IQuickInput { value: string; valueSelection: Readonly<[number, number]> | undefined; placeholder: string | undefined; password: boolean; readonly onDidChangeValue: Event; readonly onDidAccept: Event; buttons: ReadonlyArray; readonly onDidTriggerButton: Event; prompt: string | undefined; validationMessage: string | undefined; } export interface IQuickInputButton { /** iconPath or iconClass required */ iconPath?: { dark: URI; light?: URI; }; /** iconPath or iconClass required */ iconClass?: string; tooltip?: string; } export interface IQuickPickItemButtonEvent { button: IQuickInputButton; item: T; } export interface IQuickPickItemButtonContext extends IQuickPickItemButtonEvent { removeItem(): void; } export const IQuickInputService = createDecorator('quickInputService'); export type Omit = Pick>; export type QuickPickInput = T | IQuickPickSeparator; export interface IQuickInputService { _serviceBrand: any; /** * Opens the quick input box for selecting items and returns a promise with the user selected item(s) if any. */ pick(picks: Promise[]> | QuickPickInput[], options?: IPickOptions & { canPickMany: true }, token?: CancellationToken): Promise; pick(picks: Promise[]> | QuickPickInput[], options?: IPickOptions & { canPickMany: false }, token?: CancellationToken): Promise; pick(picks: Promise[]> | QuickPickInput[], options?: Omit, 'canPickMany'>, token?: CancellationToken): Promise; /** * Opens the quick input box for text input and returns a promise with the user typed value if any. */ input(options?: IInputOptions, token?: CancellationToken): Promise; backButton: IQuickInputButton; createQuickPick(): IQuickPick; createInputBox(): IInputBox; focus(): void; toggle(): void; navigate(next: boolean, quickNavigate?: IQuickNavigateConfiguration): void; accept(): Promise; back(): Promise; cancel(): Promise; }