<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import { INotificationsModel, INotificationChangeEvent, NotificationChangeType } from 'vs/workbench/common/notifications';
import { IStatusbarService, StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { HIDE_NOTIFICATIONS_CENTER_COMMAND_ID, SHOW_NOTIFICATIONS_CENTER_COMMAND_ID } from 'vs/workbench/browser/parts/notifications/notificationsCommands';
import { localize } from 'vs/nls';

export class NotificationsStatus {
	private counter: number;
	private statusItem: IDisposable;
	private toDispose: IDisposable[];
	private isNotificationsCenterVisible: boolean;

	constructor(
		private model: INotificationsModel,
		@IStatusbarService private statusbarService: IStatusbarService
	) {
		this.toDispose = [];
		this.counter = 0;

		this.updateNotificationsStatusItem();

		this.registerListeners();
	}

	public update(isCenterVisible: boolean): void {
		if (this.isNotificationsCenterVisible !== isCenterVisible) {
			this.isNotificationsCenterVisible = isCenterVisible;

			// Showing the notification center resets the counter to 0
			this.counter = 0;
			this.updateNotificationsStatusItem();
		}
	}

	private registerListeners(): void {
		this.toDispose.push(this.model.onDidNotificationChange(e => this.onDidNotificationChange(e)));
	}

	private onDidNotificationChange(e: INotificationChangeEvent): void {
		if (e.kind === NotificationChangeType.CHANGE) {
			return; // only interested in add or remove
		}

		if (this.isNotificationsCenterVisible) {
			return; // no change if notification center is visible
		}

		if (e.kind === NotificationChangeType.ADD) {
			this.counter++;
		} else {
			this.counter = Math.max(this.counter - 1, 0);
		}

		this.updateNotificationsStatusItem();
	}

	private updateNotificationsStatusItem(): void {

		// Dispose old first
		if (this.statusItem) {
			this.statusItem.dispose();
		}

		// Create new
		this.statusItem = this.statusbarService.addEntry({
			text: this.counter === 0 ? '$(megaphone)' : `$(megaphone) ${this.counter}`,
			command: this.isNotificationsCenterVisible ? HIDE_NOTIFICATIONS_CENTER_COMMAND_ID : this.model.notifications.length > 0 ? SHOW_NOTIFICATIONS_CENTER_COMMAND_ID : void 0,
			tooltip: this.getTooltip(),
			showBeak: this.isNotificationsCenterVisible
		}, StatusbarAlignment.RIGHT, -1000 /* towards the far end of the right hand side */);
	}

	private getTooltip(): string {
		if (this.isNotificationsCenterVisible) {
			return localize('hideNotifications', "Hide Notifications");
		}

		if (this.counter === 0) {
			return localize('noNotifications', "No New Notifications");
		}

		if (this.model.notifications.length === 0) {
			return localize('zeroNotifications', "No Notifications");
		}

		if (this.counter === 1) {
			return localize('oneNotification', "1 new notification");<commit_msg>notifications - fix status message<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import { INotificationsModel, INotificationChangeEvent, NotificationChangeType } from 'vs/workbench/common/notifications';
import { IStatusbarService, StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { HIDE_NOTIFICATIONS_CENTER_COMMAND_ID, SHOW_NOTIFICATIONS_CENTER_COMMAND_ID } from 'vs/workbench/browser/parts/notifications/notificationsCommands';
import { localize } from 'vs/nls';

export class NotificationsStatus {
	private counter: number;
	private statusItem: IDisposable;
	private toDispose: IDisposable[];
	private isNotificationsCenterVisible: boolean;

	constructor(
		private model: INotificationsModel,
		@IStatusbarService private statusbarService: IStatusbarService
	) {
		this.toDispose = [];
		this.counter = 0;

		this.updateNotificationsStatusItem();

		this.registerListeners();
	}

	public update(isCenterVisible: boolean): void {
		if (this.isNotificationsCenterVisible !== isCenterVisible) {
			this.isNotificationsCenterVisible = isCenterVisible;

			// Showing the notification center resets the counter to 0
			this.counter = 0;
			this.updateNotificationsStatusItem();
		}
	}

	private registerListeners(): void {
		this.toDispose.push(this.model.onDidNotificationChange(e => this.onDidNotificationChange(e)));
	}

	private onDidNotificationChange(e: INotificationChangeEvent): void {
		if (e.kind === NotificationChangeType.CHANGE) {
			return; // only interested in add or remove
		}

		if (this.isNotificationsCenterVisible) {
			return; // no change if notification center is visible
		}

		if (e.kind === NotificationChangeType.ADD) {
			this.counter++;
		} else {
			this.counter = Math.max(this.counter - 1, 0);
		}

		this.updateNotificationsStatusItem();
	}

	private updateNotificationsStatusItem(): void {

		// Dispose old first
		if (this.statusItem) {
			this.statusItem.dispose();
		}

		// Create new
		this.statusItem = this.statusbarService.addEntry({
			text: this.counter === 0 ? '$(megaphone)' : `$(megaphone) ${this.counter}`,
			command: this.isNotificationsCenterVisible ? HIDE_NOTIFICATIONS_CENTER_COMMAND_ID : this.model.notifications.length > 0 ? SHOW_NOTIFICATIONS_CENTER_COMMAND_ID : void 0,
			tooltip: this.getTooltip(),
			showBeak: this.isNotificationsCenterVisible
		}, StatusbarAlignment.RIGHT, -1000 /* towards the far end of the right hand side */);
	}

	private getTooltip(): string {
		if (this.isNotificationsCenterVisible) {
			return localize('hideNotifications', "Hide Notifications");
		}

		if (this.model.notifications.length === 0) {
			return localize('zeroNotifications', "No Notifications");
		}

		if (this.counter === 0) {
			return localize('noNotifications', "No New Notifications");
		}

		if (this.counter === 1) {
			return localize('oneNotification', "1 new notification");
{'fraction_non_alphanumeric': 0.16203348180003072, 'fraction_numerical': 0.004914759637536477, 'mean_word_length': 3.6053748231966054, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3403277', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1819, 'n_words': 424}