1
>
/*---------------------------------------------------------------------------------------------
notifications.ts
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 { INotification, INotificationHandle, INotificationActions, INotificationProgress, NoOpNotification, Severity, NotificationMessage, IPromptChoice, IStatusMessageOptions, NotificationsFilter, INotificationProgressProperties, IPromptChoiceWithMenu, NotificationPriority, INotificationSource, isNotificationSource, IStatusHandle } from '../../platform/notification/common/notification.js';
7
>
import { toErrorMessage, isErrorWithActions } from '../../base/common/errorMessage.js';
8
>
import { Event, Emitter } from '../../base/common/event.js';
9
>
import { Disposable } from '../../base/common/lifecycle.js';
10
>
import { isCancellationError } from '../../base/common/errors.js';
11
>
import { Action } from '../../base/common/actions.js';
12
>
import { equals } from '../../base/common/arrays.js';
13
>
import { parseLinkedText, LinkedText } from '../../base/common/linkedText.js';
14
>
import { mapsStrictEqualIgnoreOrder } from '../../base/common/map.js';
15
>
import { IConfigurationService } from '../../platform/configuration/common/configuration.js';
16
>
17
>
export interface INotificationsModel {
18
>
19
>
//#region Notifications as Toasts/Center
20
>
21
>
readonly notifications: INotificationViewItem[];
22
>
23
>
readonly onDidChangeNotification: Event<INotificationChangeEvent>;
24
>
readonly onDidChangeFilter: Event<Partial<INotificationsFilter>>;
25
>
26
>
addNotification(notification: INotification): INotificationHandle;
27
>
28
>
setFilter(filter: Partial<INotificationsFilter>): void;
29
>
30
>
//#endregion
31
>
32
>
33
>
//#region Notifications as Status
34
>
35
>
readonly statusMessage: IStatusMessageViewItem | undefined;
36
>
37
>
readonly onDidChangeStatusMessage: Event<IStatusMessageChangeEvent>;
38
>
39
>
showStatusMessage(message: NotificationMessage, options?: IStatusMessageOptions): IStatusHandle;
40
>
41
>
//#endregion
42
>
}
43
>
44
>
export const enum NotificationChangeType {
45
>
46
>
/**
47
>
* A notification was added.
48
>
*/
49
>
ADD,
50
>
51
>
/**
52
>
* A notification changed. Check `detail` property
53
>
* on the event for additional information.
54
>
*/
55
>
CHANGE,
56
>
57
>
/**
58
>
* A notification expanded or collapsed.
59
>
*/
60
>
EXPAND_COLLAPSE,
61
>
62
>
/**
63
>
* A notification was removed.
64
>
*/
65
>
REMOVE
66
>
}
67
>
68
>
export interface INotificationChangeEvent {
69
>
70
>
/**
71
>
* The index this notification has in the list of notifications.
72
>
*/
73
>
index: number;
74
>
75
>
/**
76
>
* The notification this change is about.
77
>
*/
78
>
item: INotificationViewItem;
79
>
80
>
/**
81
>
* The kind of notification change.
82
>
*/
83
>
kind: NotificationChangeType;
84
>
85
>
/**
86
>
* Additional detail about the item change. Only applies to
87
>
* `NotificationChangeType.CHANGE`.
88
>
*/
89
>
detail?: NotificationViewItemContentChangeKind;
90
>
}
91
>
92
>
export const enum StatusMessageChangeType {
93
>
ADD,
94
>
REMOVE
95
>
}
96
>
97
>
export interface IStatusMessageViewItem {
98
>
message: string;
99
>
options?: IStatusMessageOptions;
100
>
}
101
>
102
>
export interface IStatusMessageChangeEvent {
103
>
104
>
/**
105
>
* The status message item this change is about.
106
>
*/
107
>
item: IStatusMessageViewItem;
108
>
109
>
/**
110
>
* The kind of status message change.
111
>
*/
112
>
kind: StatusMessageChangeType;
113
>
}
114
>
115
>
export class NotificationHandle extends Disposable implements INotificationHandle {
116
>
117
>
private readonly _onDidClose = this._register(new Emitter<void>());
118
>
readonly onDidClose = this._onDidClose.event;
119
>
120
>
private readonly _onDidChangeVisibility = this._register(new Emitter<boolean>());
121
>
readonly onDidChangeVisibility = this._onDidChangeVisibility.event;
122
>
123
>
constructor(private readonly item: INotificationViewItem, private readonly onClose: (item: INotificationViewItem) => void) {
124
super();
125
126
this.registerListeners();
127
}
129
>
private registerListeners(): void {
130
131
// Visibility