| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ClosableNotification.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | |
| | | 10 | | namespace MyNet.UI.Notifications.Models; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Represents a notification that can be closed by the user or programmatically. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <remarks> |
| | | 16 | | /// Initializes a new instance of the <see cref="ClosableNotification"/> class. |
| | | 17 | | /// </remarks> |
| | | 18 | | /// <param name="message">The message content.</param> |
| | | 19 | | /// <param name="title">The title of the notification.</param> |
| | | 20 | | /// <param name="severity">The severity of the notification.</param> |
| | | 21 | | /// <param name="isClosable">Indicates whether the notification can be closed.</param> |
| | 33 | 22 | | public class ClosableNotification(string message, string title, NotificationSeverity severity, bool isClosable = true) : |
| | | 23 | | { |
| | | 24 | | /// <summary> |
| | | 25 | | /// Gets a value indicating whether the notification can be closed. |
| | | 26 | | /// </summary> |
| | | 27 | | public bool IsClosable { get; } = isClosable; |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Event raised when a request to close the notification is made, either by the user or programmatically. |
| | | 31 | | /// </summary> |
| | | 32 | | public event EventHandler<CloseRequestedEventArgs>? CloseRequested; |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Determines asynchronously whether the notification can be closed. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <returns>A task that returns true if the notification can be closed; otherwise, false.</returns> |
| | 0 | 38 | | public Task<bool> CanCloseAsync() => Task.FromResult(IsClosable); |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Closes the notification and raises the <see cref="CloseRequested"/> event. |
| | | 42 | | /// </summary> |
| | 6 | 43 | | public void RequestClose() => CloseRequested?.Invoke(this, new()); |
| | | 44 | | } |
| | | 45 | | |