using System.ComponentModel; using System.Runtime.CompilerServices; using Avalonia.Controls.Notifications; namespace Ursa.Controls; /// /// A notification that can be shown in a window or by the host operating system. /// /// /// This class represents a notification that can be displayed either in a window using /// or by the host operating system (to be implemented). /// public class Notification : INotification, INotifyPropertyChanged { private string? _title, _content; /// /// Initializes a new instance of the class. /// /// The title of the notification. /// The content to be displayed in the notification. /// The of the notification. /// The expiry time at which the notification will close. /// Use for notifications that will remain open. /// A value indicating whether the notification should show a close button. /// An Action to call when the notification is clicked. /// An Action to call when the notification is closed. public Notification( string? title, string? content, NotificationType type = NotificationType.Information, TimeSpan? expiration = null, bool showClose = true, Action? onClick = null, Action? onClose = null) { Title = title; Content = content; Type = type; Expiration = expiration ?? TimeSpan.FromSeconds(3); ShowClose = showClose; OnClick = onClick; OnClose = onClose; } /// /// Initializes a new instance of the class. /// public Notification() : this(null, null) { } /// public string? Title { get => _title; set { if (_title != value) { _title = value; OnPropertyChanged(); } } } /// public string? Content { get => _content; set { if (_content != value) { _content = value; OnPropertyChanged(); } } } /// public NotificationType Type { get; set; } /// public TimeSpan Expiration { get; set; } /// public bool ShowIcon { get; set; } /// public bool ShowClose { get; } /// public Action? OnClick { get; set; } /// public Action? OnClose { get; set; } public event PropertyChangedEventHandler? PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } }