From cd8bf3adaf7f348da9660aa7148fa38ba4d2bfd9 Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:25:26 +0800 Subject: [PATCH] feat: separate some Notification shared files. --- src/Ursa.Themes.Semi/Controls/Toast.axaml | 6 +- .../Controls/NotificationShared/IMessage.cs | 35 +++ .../NotificationShared/MessageCard.cs | 207 ++++++++++++++++++ .../WindowMessageManager.cs | 80 +++++++ .../Controls/Toast/IManagedToastManager.cs | 22 -- src/Ursa/Controls/Toast/IToast.cs | 35 +-- src/Ursa/Controls/Toast/ToastCard.cs | 204 +---------------- src/Ursa/Controls/Toast/WindowToastManager.cs | 75 +------ 8 files changed, 335 insertions(+), 329 deletions(-) create mode 100644 src/Ursa/Controls/NotificationShared/IMessage.cs create mode 100644 src/Ursa/Controls/NotificationShared/MessageCard.cs create mode 100644 src/Ursa/Controls/NotificationShared/WindowMessageManager.cs delete mode 100644 src/Ursa/Controls/Toast/IManagedToastManager.cs diff --git a/src/Ursa.Themes.Semi/Controls/Toast.axaml b/src/Ursa.Themes.Semi/Controls/Toast.axaml index 256140b..d34388b 100644 --- a/src/Ursa.Themes.Semi/Controls/Toast.axaml +++ b/src/Ursa.Themes.Semi/Controls/Toast.axaml @@ -6,10 +6,10 @@ - Hello, Semi.Avalonia! + Hello, Ursa! - + @@ -87,7 +87,7 @@ Grid.Column="2" Theme="{StaticResource ToastCloseButton}" IsVisible="{TemplateBinding ShowClose}" - u:ToastCard.CloseOnClick="True" /> + u:MessageCard.CloseOnClick="True" /> diff --git a/src/Ursa/Controls/NotificationShared/IMessage.cs b/src/Ursa/Controls/NotificationShared/IMessage.cs new file mode 100644 index 0000000..b1cad33 --- /dev/null +++ b/src/Ursa/Controls/NotificationShared/IMessage.cs @@ -0,0 +1,35 @@ +using Avalonia.Controls.Notifications; + +namespace Ursa.Controls; + +/// +/// Represents a message that can be shown in a window or by the host operating system. +/// +public interface IMessage +{ + /// + /// Gets the of the message. + /// + NotificationType Type { get; } + + /// + /// Gets a value indicating whether the message should show a close button. + /// + bool ShowClose { get; } + + /// + /// Gets the expiration time of the message after which it will automatically close. + /// If the value is then the message will remain open until the user closes it. + /// + TimeSpan Expiration { get; } + + /// + /// Gets an Action to be run when the message is clicked. + /// + Action? OnClick { get; } + + /// + /// Gets an Action to be run when the message is closed. + /// + Action? OnClose { get; } +} \ No newline at end of file diff --git a/src/Ursa/Controls/NotificationShared/MessageCard.cs b/src/Ursa/Controls/NotificationShared/MessageCard.cs new file mode 100644 index 0000000..d244a69 --- /dev/null +++ b/src/Ursa/Controls/NotificationShared/MessageCard.cs @@ -0,0 +1,207 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Metadata; +using Avalonia.Controls.Notifications; +using Avalonia.Interactivity; +using Avalonia.LogicalTree; + +namespace Ursa.Controls; + +/// +/// Control that represents and displays a message. +/// +[PseudoClasses(PC_Information, PC_Success, PC_Warning, PC_Error)] +public abstract class MessageCard : ContentControl +{ + public const string PC_Information = ":information"; + public const string PC_Success = ":success"; + public const string PC_Warning = ":warning"; + public const string PC_Error = ":error"; + + private bool _isClosing; + + static MessageCard() + { + CloseOnClickProperty.Changed.AddClassHandler