From 4996c0b1730f17f1a5dc2aeecaa5de56b0b603d3 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 10 May 2019 19:30:14 +0100 Subject: [PATCH] add xml comments. --- .../IManagedNotificationManager.cs | 18 +++++ .../Notifications/INotification.cs | 44 ++++++++++++ .../Notifications/INotificationManager.cs | 30 +++----- .../Notifications/Notification.cs | 24 ++++++- .../Notifications/NotificationCard.cs | 72 +++++++++---------- .../Notifications/NotificationPosition.cs | 16 +++++ .../Notifications/NotificationType.cs | 8 ++- .../Notifications/ReversibleStackPanel.cs | 13 ++-- .../WindowNotificationManager.cs | 40 ++++++++--- 9 files changed, 191 insertions(+), 74 deletions(-) create mode 100644 src/Avalonia.Controls/Notifications/IManagedNotificationManager.cs create mode 100644 src/Avalonia.Controls/Notifications/INotification.cs create mode 100644 src/Avalonia.Controls/Notifications/NotificationPosition.cs diff --git a/src/Avalonia.Controls/Notifications/IManagedNotificationManager.cs b/src/Avalonia.Controls/Notifications/IManagedNotificationManager.cs new file mode 100644 index 0000000000..330013317f --- /dev/null +++ b/src/Avalonia.Controls/Notifications/IManagedNotificationManager.cs @@ -0,0 +1,18 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +namespace Avalonia.Controls.Notifications +{ + /// + /// Interface for a managed notification manager. + /// Managed notification managers can show any content. + /// + public interface IManagedNotificationManager : INotificationManager + { + /// + /// Shows a notification. + /// + /// The content to be displayed. + void Show(object content); + } +} diff --git a/src/Avalonia.Controls/Notifications/INotification.cs b/src/Avalonia.Controls/Notifications/INotification.cs new file mode 100644 index 0000000000..7ad2c770a6 --- /dev/null +++ b/src/Avalonia.Controls/Notifications/INotification.cs @@ -0,0 +1,44 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using System; + +namespace Avalonia.Controls.Notifications +{ + /// + /// Interface for a notification. + /// + public interface INotification + { + /// + /// Gets the Title of the notification. + /// + string Title { get; } + + /// + /// Gets the Message of the notification. + /// + string Message { get; } + + /// + /// Gets the of the notification. + /// + NotificationType Type { get; } + + /// + /// Gets the expiration time of the notification after which it will automatically close. + /// If the value is then the notification will remain open until the user closes it. + /// + TimeSpan Expiration { get; } + + /// + /// Gets an Action to be run when the notification is clicked. + /// + Action OnClick { get; } + + /// + /// Gets an Action to be run when the notification is closed. + /// + Action OnClose { get; } + } +} diff --git a/src/Avalonia.Controls/Notifications/INotificationManager.cs b/src/Avalonia.Controls/Notifications/INotificationManager.cs index f2af87fb4a..53c3d68f8e 100644 --- a/src/Avalonia.Controls/Notifications/INotificationManager.cs +++ b/src/Avalonia.Controls/Notifications/INotificationManager.cs @@ -1,29 +1,17 @@ -using System; +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. namespace Avalonia.Controls.Notifications { - public interface INotification - { - string Title { get; } - - string Message { get; } - - NotificationType Type { get; } - - TimeSpan Expiration { get; } - - Action OnClick { get; } - - Action OnClose { get; } - } - + /// + /// Defines the interfaces for NotificationManagers. + /// public interface INotificationManager { + /// + /// Show a notification. + /// + /// The notification to be displayed. void Show(INotification notification); } - - public interface IManagedNotificationManager : INotificationManager - { - void Show(object content); - } } diff --git a/src/Avalonia.Controls/Notifications/Notification.cs b/src/Avalonia.Controls/Notifications/Notification.cs index 4aea4e5f9d..b488d3a487 100644 --- a/src/Avalonia.Controls/Notifications/Notification.cs +++ b/src/Avalonia.Controls/Notifications/Notification.cs @@ -1,15 +1,29 @@ -using System; +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using System; namespace Avalonia.Controls.Notifications { /// - /// Defines content for a control. + /// Implements the INotification interfaces. + /// Can be displayed by both and /// /// /// This notification content type is compatible with native notifications. /// public class Notification : INotification { + /// + /// Instantiates an instance of + /// + /// The title of the notification. + /// The message 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. + /// The Action to call when the notification is clicked. + /// The Action to call when the notification is closed. public Notification(string title, string message, NotificationType type = NotificationType.Information, @@ -25,16 +39,22 @@ namespace Avalonia.Controls.Notifications OnClose = onClose; } + /// public string Title { get; private set; } + /// public string Message { get; private set; } + /// public NotificationType Type { get; private set; } + /// public TimeSpan Expiration { get; private set; } + /// public Action OnClick { get; private set; } + /// public Action OnClose { get; private set; } } } diff --git a/src/Avalonia.Controls/Notifications/NotificationCard.cs b/src/Avalonia.Controls/Notifications/NotificationCard.cs index feb9479a19..6b326073a6 100644 --- a/src/Avalonia.Controls/Notifications/NotificationCard.cs +++ b/src/Avalonia.Controls/Notifications/NotificationCard.cs @@ -1,24 +1,38 @@ -using System; +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using System; using System.Linq; using System.Reactive.Linq; -using Avalonia.Controls.Primitives; using Avalonia.Interactivity; using Avalonia.LogicalTree; namespace Avalonia.Controls.Notifications { + /// + /// Control that represents and displays a notification. + /// public class NotificationCard : ContentControl { private bool _isClosed; private bool _isClosing; - static NotificationCard() - { - IsClosedProperty.Changed.AddClassHandler(IsClosedChanged); - } - + /// + /// Instantiates a new instance of . + /// public NotificationCard() { + this.GetObservable(IsClosedProperty) + .Subscribe(x => + { + if (!IsClosing & !IsClosed) + { + return; + } + + RaiseEvent(new RoutedEventArgs(NotificationClosedEvent)); + }); + this.GetObservable(ContentProperty) .OfType() .Subscribe(x => @@ -53,6 +67,9 @@ namespace Avalonia.Controls.Notifications private set { SetAndRaise(IsClosingProperty, ref _isClosing, value); } } + /// + /// Defines the property. + /// public static readonly DirectProperty IsClosingProperty = AvaloniaProperty.RegisterDirect(nameof(IsClosing), o => o.IsClosing); @@ -92,6 +109,9 @@ namespace Avalonia.Controls.Notifications remove { RemoveHandler(NotificationCloseInvokedEvent, value); } } + /// + /// Raised when the has closed. + /// public event EventHandler NotificationClosed { add { AddHandler(NotificationClosedEvent, value); } @@ -108,6 +128,9 @@ namespace Avalonia.Controls.Notifications obj.SetValue(CloseOnClickProperty, value); } + /// + /// Defines the CloseOnClick property. + /// public static readonly AvaloniaProperty CloseOnClickProperty = AvaloniaProperty.RegisterAttached("CloseOnClick", typeof(NotificationCard), validate: CloseOnClickChanged); @@ -125,6 +148,9 @@ namespace Avalonia.Controls.Notifications return true; } + /// + /// Called when a button inside the Notification is clicked. + /// private static void Button_Click(object sender, RoutedEventArgs e) { var btn = sender as ILogical; @@ -132,25 +158,9 @@ namespace Avalonia.Controls.Notifications notification?.Close(); } - protected override void OnTemplateApplied(TemplateAppliedEventArgs e) - { - base.OnTemplateApplied(e); - var closeButton = this.FindControl