Path: blob/main/src/vs/platform/action/common/action.ts
3294 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 { URI, UriDto } from '../../../base/common/uri.js';6import { ContextKeyExpression } from '../../contextkey/common/contextkey.js';7import { ThemeIcon } from '../../../base/common/themables.js';8import { Categories } from './actionCommonCategories.js';9import { ICommandMetadata } from '../../commands/common/commands.js';1011export interface ILocalizedString {1213/**14* The localized value of the string.15*/16value: string;1718/**19* The original (non localized value of the string)20*/21original: string;22}2324export function isLocalizedString(thing: any): thing is ILocalizedString {25return thing26&& typeof thing === 'object'27&& typeof thing.original === 'string'28&& typeof thing.value === 'string';29}3031export interface ICommandActionTitle extends ILocalizedString {3233/**34* The title with a mnemonic designation. && precedes the mnemonic.35*/36mnemonicTitle?: string;37}3839export type Icon = { dark?: URI; light?: URI } | ThemeIcon;4041export interface ICommandActionToggleInfo {4243/**44* The condition that marks the action as toggled.45*/46condition: ContextKeyExpression;4748icon?: Icon;4950tooltip?: string;5152/**53* The title that goes well with a a check mark, e.g "(check) Line Numbers" vs "Toggle Line Numbers"54*/55title?: string;5657/**58* Like title but with a mnemonic designation.59*/60mnemonicTitle?: string;61}6263export function isICommandActionToggleInfo(thing: ContextKeyExpression | ICommandActionToggleInfo | undefined): thing is ICommandActionToggleInfo {64return thing ? (<ICommandActionToggleInfo>thing).condition !== undefined : false;65}6667export interface ICommandActionSource {68readonly id: string;69readonly title: string;70}7172export interface ICommandAction {73id: string;74title: string | ICommandActionTitle;75shortTitle?: string | ICommandActionTitle;76/**77* Metadata about this command, used for:78* - API commands79* - when showing keybindings that have no other UX80* - when searching for commands in the Command Palette81*/82metadata?: ICommandMetadata;83category?: keyof typeof Categories | ILocalizedString | string;84tooltip?: string | ILocalizedString;85icon?: Icon;86source?: ICommandActionSource;87/**88* Precondition controls enablement (for example for a menu item, show89* it in grey or for a command, do not allow to invoke it)90*/91precondition?: ContextKeyExpression;9293/**94* The action is a toggle action. Define the context key expression that reflects its toggle-state95* or define toggle-info including an icon and a title that goes well with a checkmark.96*/97toggled?: ContextKeyExpression | ICommandActionToggleInfo;98}99100export type ISerializableCommandAction = UriDto<ICommandAction>;101102103