Path: blob/main/src/vs/workbench/services/activity/common/activity.ts
4780 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 { Codicon } from '../../../../base/common/codicons.js';6import { Color } from '../../../../base/common/color.js';7import { Event } from '../../../../base/common/event.js';8import { IDisposable } from '../../../../base/common/lifecycle.js';9import { ThemeIcon } from '../../../../base/common/themables.js';10import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';11import { activityErrorBadgeBackground, activityErrorBadgeForeground, activityWarningBadgeBackground, activityWarningBadgeForeground } from '../../../../platform/theme/common/colors/miscColors.js';12import { IColorTheme } from '../../../../platform/theme/common/themeService.js';13import { ViewContainer } from '../../../common/views.js';1415export interface IActivity {16readonly badge: IBadge;17}1819export const IActivityService = createDecorator<IActivityService>('activityService');2021export interface IActivityService {2223readonly _serviceBrand: undefined;2425/**26* Emitted when activity changes for a view container or when the activity of the global actions change.27*/28readonly onDidChangeActivity: Event<string | ViewContainer>;2930/**31* Show activity for the given view container32*/33showViewContainerActivity(viewContainerId: string, badge: IActivity): IDisposable;3435/**36* Returns the activity for the given view container37*/38getViewContainerActivities(viewContainerId: string): IActivity[];3940/**41* Show activity for the given view42*/43showViewActivity(viewId: string, badge: IActivity): IDisposable;4445/**46* Show accounts activity47*/48showAccountsActivity(activity: IActivity): IDisposable;4950/**51* Show global activity52*/53showGlobalActivity(activity: IActivity): IDisposable;5455/**56* Return the activity for the given action57*/58getActivity(id: string): IActivity[];59}6061export interface IBadge {62getDescription(): string;63getColors(theme: IColorTheme): IBadgeStyles | undefined;64}6566export interface IBadgeStyles {67readonly badgeBackground: Color | undefined;68readonly badgeForeground: Color | undefined;69readonly badgeBorder: Color | undefined;70}7172class BaseBadge<T = unknown> implements IBadge {7374constructor(75protected readonly descriptorFn: (arg: T) => string,76private readonly stylesFn: ((theme: IColorTheme) => IBadgeStyles | undefined) | undefined,77) {78}7980getDescription(): string {81return this.descriptorFn(null as T);82}8384getColors(theme: IColorTheme): IBadgeStyles | undefined {85return this.stylesFn?.(theme);86}87}8889export class NumberBadge extends BaseBadge<number> {9091constructor(readonly number: number, descriptorFn: (num: number) => string) {92super(descriptorFn, undefined);9394this.number = number;95}9697override getDescription(): string {98return this.descriptorFn(this.number);99}100}101102export class IconBadge extends BaseBadge<void> {103constructor(104readonly icon: ThemeIcon,105descriptorFn: () => string,106stylesFn?: (theme: IColorTheme) => IBadgeStyles | undefined,107) {108super(descriptorFn, stylesFn);109}110}111112export class ProgressBadge extends BaseBadge<void> {113constructor(descriptorFn: () => string) {114super(descriptorFn, undefined);115}116}117118export class WarningBadge extends IconBadge {119constructor(descriptorFn: () => string) {120super(Codicon.warning, descriptorFn, (theme: IColorTheme) => ({121badgeBackground: theme.getColor(activityWarningBadgeBackground),122badgeForeground: theme.getColor(activityWarningBadgeForeground),123badgeBorder: undefined,124}));125}126}127128export class ErrorBadge extends IconBadge {129constructor(descriptorFn: () => string) {130super(Codicon.error, descriptorFn, (theme: IColorTheme) => ({131badgeBackground: theme.getColor(activityErrorBadgeBackground),132badgeForeground: theme.getColor(activityErrorBadgeForeground),133badgeBorder: undefined,134}));135}136}137138139