Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/action/common/action.ts
3294 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { URI, UriDto } from '../../../base/common/uri.js';
7
import { ContextKeyExpression } from '../../contextkey/common/contextkey.js';
8
import { ThemeIcon } from '../../../base/common/themables.js';
9
import { Categories } from './actionCommonCategories.js';
10
import { ICommandMetadata } from '../../commands/common/commands.js';
11
12
export interface ILocalizedString {
13
14
/**
15
* The localized value of the string.
16
*/
17
value: string;
18
19
/**
20
* The original (non localized value of the string)
21
*/
22
original: string;
23
}
24
25
export function isLocalizedString(thing: any): thing is ILocalizedString {
26
return thing
27
&& typeof thing === 'object'
28
&& typeof thing.original === 'string'
29
&& typeof thing.value === 'string';
30
}
31
32
export interface ICommandActionTitle extends ILocalizedString {
33
34
/**
35
* The title with a mnemonic designation. && precedes the mnemonic.
36
*/
37
mnemonicTitle?: string;
38
}
39
40
export type Icon = { dark?: URI; light?: URI } | ThemeIcon;
41
42
export interface ICommandActionToggleInfo {
43
44
/**
45
* The condition that marks the action as toggled.
46
*/
47
condition: ContextKeyExpression;
48
49
icon?: Icon;
50
51
tooltip?: string;
52
53
/**
54
* The title that goes well with a a check mark, e.g "(check) Line Numbers" vs "Toggle Line Numbers"
55
*/
56
title?: string;
57
58
/**
59
* Like title but with a mnemonic designation.
60
*/
61
mnemonicTitle?: string;
62
}
63
64
export function isICommandActionToggleInfo(thing: ContextKeyExpression | ICommandActionToggleInfo | undefined): thing is ICommandActionToggleInfo {
65
return thing ? (<ICommandActionToggleInfo>thing).condition !== undefined : false;
66
}
67
68
export interface ICommandActionSource {
69
readonly id: string;
70
readonly title: string;
71
}
72
73
export interface ICommandAction {
74
id: string;
75
title: string | ICommandActionTitle;
76
shortTitle?: string | ICommandActionTitle;
77
/**
78
* Metadata about this command, used for:
79
* - API commands
80
* - when showing keybindings that have no other UX
81
* - when searching for commands in the Command Palette
82
*/
83
metadata?: ICommandMetadata;
84
category?: keyof typeof Categories | ILocalizedString | string;
85
tooltip?: string | ILocalizedString;
86
icon?: Icon;
87
source?: ICommandActionSource;
88
/**
89
* Precondition controls enablement (for example for a menu item, show
90
* it in grey or for a command, do not allow to invoke it)
91
*/
92
precondition?: ContextKeyExpression;
93
94
/**
95
* The action is a toggle action. Define the context key expression that reflects its toggle-state
96
* or define toggle-info including an icon and a title that goes well with a checkmark.
97
*/
98
toggled?: ContextKeyExpression | ICommandActionToggleInfo;
99
}
100
101
export type ISerializableCommandAction = UriDto<ICommandAction>;
102
103