Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/activity/common/activity.ts
4780 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 { Codicon } from '../../../../base/common/codicons.js';
7
import { Color } from '../../../../base/common/color.js';
8
import { Event } from '../../../../base/common/event.js';
9
import { IDisposable } from '../../../../base/common/lifecycle.js';
10
import { ThemeIcon } from '../../../../base/common/themables.js';
11
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
12
import { activityErrorBadgeBackground, activityErrorBadgeForeground, activityWarningBadgeBackground, activityWarningBadgeForeground } from '../../../../platform/theme/common/colors/miscColors.js';
13
import { IColorTheme } from '../../../../platform/theme/common/themeService.js';
14
import { ViewContainer } from '../../../common/views.js';
15
16
export interface IActivity {
17
readonly badge: IBadge;
18
}
19
20
export const IActivityService = createDecorator<IActivityService>('activityService');
21
22
export interface IActivityService {
23
24
readonly _serviceBrand: undefined;
25
26
/**
27
* Emitted when activity changes for a view container or when the activity of the global actions change.
28
*/
29
readonly onDidChangeActivity: Event<string | ViewContainer>;
30
31
/**
32
* Show activity for the given view container
33
*/
34
showViewContainerActivity(viewContainerId: string, badge: IActivity): IDisposable;
35
36
/**
37
* Returns the activity for the given view container
38
*/
39
getViewContainerActivities(viewContainerId: string): IActivity[];
40
41
/**
42
* Show activity for the given view
43
*/
44
showViewActivity(viewId: string, badge: IActivity): IDisposable;
45
46
/**
47
* Show accounts activity
48
*/
49
showAccountsActivity(activity: IActivity): IDisposable;
50
51
/**
52
* Show global activity
53
*/
54
showGlobalActivity(activity: IActivity): IDisposable;
55
56
/**
57
* Return the activity for the given action
58
*/
59
getActivity(id: string): IActivity[];
60
}
61
62
export interface IBadge {
63
getDescription(): string;
64
getColors(theme: IColorTheme): IBadgeStyles | undefined;
65
}
66
67
export interface IBadgeStyles {
68
readonly badgeBackground: Color | undefined;
69
readonly badgeForeground: Color | undefined;
70
readonly badgeBorder: Color | undefined;
71
}
72
73
class BaseBadge<T = unknown> implements IBadge {
74
75
constructor(
76
protected readonly descriptorFn: (arg: T) => string,
77
private readonly stylesFn: ((theme: IColorTheme) => IBadgeStyles | undefined) | undefined,
78
) {
79
}
80
81
getDescription(): string {
82
return this.descriptorFn(null as T);
83
}
84
85
getColors(theme: IColorTheme): IBadgeStyles | undefined {
86
return this.stylesFn?.(theme);
87
}
88
}
89
90
export class NumberBadge extends BaseBadge<number> {
91
92
constructor(readonly number: number, descriptorFn: (num: number) => string) {
93
super(descriptorFn, undefined);
94
95
this.number = number;
96
}
97
98
override getDescription(): string {
99
return this.descriptorFn(this.number);
100
}
101
}
102
103
export class IconBadge extends BaseBadge<void> {
104
constructor(
105
readonly icon: ThemeIcon,
106
descriptorFn: () => string,
107
stylesFn?: (theme: IColorTheme) => IBadgeStyles | undefined,
108
) {
109
super(descriptorFn, stylesFn);
110
}
111
}
112
113
export class ProgressBadge extends BaseBadge<void> {
114
constructor(descriptorFn: () => string) {
115
super(descriptorFn, undefined);
116
}
117
}
118
119
export class WarningBadge extends IconBadge {
120
constructor(descriptorFn: () => string) {
121
super(Codicon.warning, descriptorFn, (theme: IColorTheme) => ({
122
badgeBackground: theme.getColor(activityWarningBadgeBackground),
123
badgeForeground: theme.getColor(activityWarningBadgeForeground),
124
badgeBorder: undefined,
125
}));
126
}
127
}
128
129
export class ErrorBadge extends IconBadge {
130
constructor(descriptorFn: () => string) {
131
super(Codicon.error, descriptorFn, (theme: IColorTheme) => ({
132
badgeBackground: theme.getColor(activityErrorBadgeBackground),
133
badgeForeground: theme.getColor(activityErrorBadgeForeground),
134
badgeBorder: undefined,
135
}));
136
}
137
}
138
139