214
215
addNotification(notification: INotification): INotificationHandle {
217
>
if (!item) {
218
return NotificationsModel.NO_OP_NOTIFICATION; // return early if this is a no-op
219
}
221
>
// Deduplicate
222
>
const duplicate = this.findNotification(item);
223
>
duplicate?.close();
224
>
225
>
// Add to list as first entry
226
>
this._notifications.splice(0, 0, item);
227
>
228
>
// Events
229
>
this._onDidChangeNotification.fire({ item, index: 0, kind: NotificationChangeType.ADD });
230
>
231
>
// Wrap into handle
232
>
return new NotificationHandle(item, item => this.onClose(item));
233
>
}
234
235
private onClose(item: INotificationViewItem): void {
237
>
if (liveItem && liveItem !== item) {
238
>
liveItem.close(); // item could have been replaced with another one, make sure to close the live item
239
>
} else {
240
>
item.close(); // otherwise just close the item that was passed in
241
>
}
242
>
}
243
244
private findNotification(item: INotificationViewItem): INotificationViewItem | undefined {
245
>
return this._notifications.find(notification => notification.equals(item));
notifications.ts
246
>
}
247
248
private createViewItem(notification: INotification): INotificationViewItem | undefined {
249
>
const item = NotificationViewItem.create(notification, this.filter);
notifications.ts
250
>
if (!item) {
251
return undefined;
252
}
254
>
// Item Events
255
>
const fireNotificationChangeEvent = (kind: NotificationChangeType, detail?: NotificationViewItemContentChangeKind) => {
256
>
const index = this._notifications.indexOf(item);
257
>
if (index >= 0) {
258
>
this._onDidChangeNotification.fire({ item, index, kind, detail });
259
>
}
260
>
};
261
>
262
>
const itemExpansionChangeListener = item.onDidChangeExpansion(() => fireNotificationChangeEvent(NotificationChangeType.EXPAND_COLLAPSE));
263
>
const itemContentChangeListener = item.onDidChangeContent(e => fireNotificationChangeEvent(NotificationChangeType.CHANGE, e.kind));
264
>
265
>
Event.once(item.onDidClose)(() => {
266
>
itemExpansionChangeListener.dispose();
267
>
itemContentChangeListener.dispose();
268
>
269
>
const index = this._notifications.indexOf(item);
270
>
if (index >= 0) {
271
>
this._notifications.splice(index, 1);
272
>
this._onDidChangeNotification.fire({ item, index, kind: NotificationChangeType.REMOVE });
273
>
}
274
>
});
275
>
276
>
return item;
277
>
}
278
279
showStatusMessage(message: NotificationMessage, options?: IStatusMessageOptions): IStatusHandle {
280
>
const item = StatusMessageViewItem.create(message, options);
notifications.ts
281
>
if (!item) {
282
return { close: () => { } };
283
}
285
>
this._statusMessage = item;
286
>
this._onDidChangeStatusMessage.fire({ kind: StatusMessageChangeType.ADD, item });
287
>
288
>
return {
289
>
close: () => {
290
>
if (this._statusMessage === item) {
291
>
this._statusMessage = undefined;
292
>
this._onDidChangeStatusMessage.fire({ kind: StatusMessageChangeType.REMOVE, item });
293
>
}
294
>
}
295
>
};
296
>
}
297
}
298