diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications')
4 files changed, 47 insertions, 193 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs index e9de2538e..65337a892 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -17,8 +17,6 @@ using Tango.Touch.Controls; using Tango.SharedUI; using System.Reflection; using Tango.Core.DI; -using System.ComponentModel; -using System.Windows.Data; namespace Tango.PPC.UI.Notifications { @@ -49,16 +47,6 @@ namespace Tango.PPC.UI.Notifications public ObservableCollection<NotificationItem> NotificationItems { get; private set; } /// <summary> - /// Gets the application bar items. - /// </summary> - public ObservableCollection<AppBarItem> AppBarItems { get; private set; } - - /// <summary> - /// Gets the notification items view. - /// </summary> - public ICollectionView NotificationItemsView { get; private set; } - - /// <summary> /// Gets the collection of taskbar items. /// </summary> public ObservableCollection<TaskBarItem> TaskBarItems { get; private set; } @@ -70,10 +58,6 @@ namespace Tango.PPC.UI.Notifications { NotificationsVisible = true; NotificationItems = new ObservableCollection<NotificationItem>(); - - AppBarItems = new ObservableCollection<AppBarItem>(); - CollectionViewSource.GetDefaultView(AppBarItems).SortDescriptions.Add(new SortDescription(nameof(AppBarItem.Priority), ListSortDirection.Ascending)); - TaskBarItems = new ObservableCollection<TaskBarItem>(); _pendingMessageBoxes = new ConcurrentQueue<PendingNotification<MessageBoxVM, bool>>(); _pendingDialogs = new ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>>(); @@ -82,9 +66,6 @@ namespace Tango.PPC.UI.Notifications PopNotificationCommand = new RelayCommand<NotificationItem>((x) => PopNotification(x)); NotificationItems.EnableCrossThreadOperations(); - - NotificationItemsView = CollectionViewSource.GetDefaultView(NotificationItems); - NotificationItemsView.SortDescriptions.Add(new SortDescription(nameof(NotificationItem.Priority), ListSortDirection.Descending)); } private MessageBoxVM _currentMessageBox; @@ -341,33 +322,29 @@ namespace Tango.PPC.UI.Notifications /// <returns></returns> public async Task<T> ShowDialog<T>(T datacontext, FrameworkElement view) where T : DialogViewVM { - TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>(); + view.DataContext = datacontext; + + TangoIOC.Default.Inject(datacontext); - InvokeUI(() => + view.Loaded += (_, __) => { view.DataContext = datacontext; + datacontext.OnShow(); + }; - TangoIOC.Default.Inject(datacontext); - - view.Loaded += (_, __) => - { - view.DataContext = datacontext; - datacontext.OnShow(); - }; - - datacontext.Accepted += () => { OnDialogClosed(); source.SetResult(datacontext); }; - datacontext.Canceled += () => { OnDialogClosed(); source.SetResult(datacontext); }; + TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>(); - if (CurrentDialog == null) - { - CurrentDialog = view; - } - else - { - _pendingDialogs.Enqueue(new PendingNotification<DialogAndView, DialogViewVM>(new DialogAndView(datacontext, view), source)); - } + datacontext.Accepted += () => { OnDialogClosed(); source.SetResult(datacontext); }; + datacontext.Canceled += () => { OnDialogClosed(); source.SetResult(datacontext); }; - }); + if (CurrentDialog == null) + { + CurrentDialog = view; + } + else + { + _pendingDialogs.Enqueue(new PendingNotification<DialogAndView, DialogViewVM>(new DialogAndView(datacontext, view), source)); + } var result = await source.Task; return result as T; @@ -399,31 +376,23 @@ namespace Tango.PPC.UI.Notifications /// <returns></returns> public Task<T> ShowDialog<T>(T datacontext) where T : DialogViewVM { - TaskCompletionSource<T> source = new TaskCompletionSource<T>(); + var callingAssembly = datacontext.GetType().Assembly; + String viewName = datacontext.GetType().FullName.Replace("VM", ""); + var viewType = callingAssembly.GetType(viewName); - InvokeUI(async () => + if (viewType == null) { - var callingAssembly = datacontext.GetType().Assembly; - String viewName = datacontext.GetType().FullName.Replace("VM", ""); - var viewType = callingAssembly.GetType(viewName); - - if (viewType == null) - { - throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!"); - } - - var view = Activator.CreateInstance(viewType) as FrameworkElement; + throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!"); + } - if (view == null) - { - throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element."); - } + var view = Activator.CreateInstance(viewType) as FrameworkElement; - T result = await ShowDialog<T>(datacontext, view); - source.SetResult(result); - }); + if (view == null) + { + throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element."); + } - return source.Task; + return ShowDialog<T>(datacontext, view); } /// <summary> @@ -435,15 +404,7 @@ namespace Tango.PPC.UI.Notifications /// <returns></returns> public Task<T> ShowDialog<T>() where T : DialogViewVM { - TaskCompletionSource<T> source = new TaskCompletionSource<T>(); - - InvokeUI(async () => - { - var result = await ShowDialog<T>(Activator.CreateInstance<T>()); - source.SetResult(result); - }); - - return source.Task; + return ShowDialog<T>(Activator.CreateInstance<T>()); } /// <summary> @@ -481,12 +442,22 @@ namespace Tango.PPC.UI.Notifications /// </summary> public bool IsInGlobalBusyState { get; private set; } + private AppBarItem _currentAppBarItem; + /// <summary> + /// Gets the current application bar item. + /// </summary> + public AppBarItem CurrentAppBarItem + { + get { return _currentAppBarItem; } + set { _currentAppBarItem = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasAppBarItem)); } + } + /// <summary> /// Gets a value indicating whether this instance has application bar item. /// </summary> - public bool HasAppBarItems + public bool HasAppBarItem { - get { return AppBarItems.Count > 0; } + get { return CurrentAppBarItem != null; } } /// <summary> @@ -497,9 +468,8 @@ namespace Tango.PPC.UI.Notifications public AppBarItem PushAppBarItem(AppBarItem appBarItem) { LogManager.Log($"Pushing AppBarItem '{appBarItem.GetType().Name}'."); - AppBarItems.Add(appBarItem); + CurrentAppBarItem = appBarItem; appBarItem.RemoveAction = () => PopAppBarItem(appBarItem); - RaisePropertyChanged(nameof(HasAppBarItems)); return appBarItem; } @@ -508,9 +478,9 @@ namespace Tango.PPC.UI.Notifications /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> - public T PushAppBarItem<T>() where T : AppBarItem + public AppBarItem PushAppBarItem<T>() where T : AppBarItem { - return PushAppBarItem(Activator.CreateInstance<T>()) as T; + return PushAppBarItem(Activator.CreateInstance<T>()); } /// <summary> @@ -519,12 +489,8 @@ namespace Tango.PPC.UI.Notifications /// <param name="appBarItem">The application bar item.</param> public void PopAppBarItem(AppBarItem appBarItem) { - InvokeUI(() => - { - LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'."); - AppBarItems.Remove(appBarItem); - RaisePropertyChanged(nameof(HasAppBarItems)); - }); + LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'."); + CurrentAppBarItem = null; } /// <summary> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs deleted file mode 100644 index 9e336f276..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItem.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.PPC.Common.Notifications; - -namespace Tango.PPC.UI.Notifications.NotificationItems -{ - /// <summary> - /// Represents a simple text message notification item which can be inserted into the application notifications panel. - /// </summary> - /// <seealso cref="Tango.PPC.Common.Notifications.NotificationItem" /> - public class UpdateAvailableNotificationItem : NotificationItem - { - /// <summary> - /// Initializes a new instance of the <see cref="UpdateAvailableNotificationItem"/> class. - /// </summary> - public UpdateAvailableNotificationItem() - { - CanClose = true; - } - - private String _version; - /// <summary> - /// Gets or sets the message. - /// </summary> - public String Version - { - get { return _version; } - set { _version = value; RaisePropertyChangedAuto(); } - } - - private bool _isDatabaseUpdate; - /// <summary> - /// Gets or sets a value indicating whether this instance is database update. - /// </summary> - public bool IsDatabaseUpdate - { - get { return _isDatabaseUpdate; } - set { _isDatabaseUpdate = value; RaisePropertyChangedAuto(); } - } - - /// <summary> - /// Gets or sets the view type. - /// </summary> - public override Type ViewType - { - get { return typeof(UpdateAvailableNotificationItemView); } - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml deleted file mode 100644 index 1d4dd6fc7..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml +++ /dev/null @@ -1,30 +0,0 @@ -<UserControl x:Class="Tango.PPC.UI.Notifications.NotificationItems.UpdateAvailableNotificationItemView" - xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" - xmlns:local="clr-namespace:Tango.PPC.UI.Notifications.NotificationItems" - xmlns:common="clr-namespace:Tango.PPC.Common.Converters" - mc:Ignorable="d" - x:Name="MessageNotificationItemControl" - d:DesignHeight="60" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=local:UpdateAvailableNotificationItem, IsDesignTimeCreatable=False}" MinHeight="90" Height="90" MaxHeight="150" Background="{StaticResource TangoPrimaryBackgroundBrush}"> - - <Grid> - <Border BorderThickness="0 0 0 2" BorderBrush="{StaticResource TangoPrimaryAccentBrush}" Padding="15"> - <DockPanel> - <Image Source="/Images/update_available.png" MaxHeight="50" /> - - <Grid> - <TextBlock Margin="20 0 0 0" VerticalAlignment="Center" Visibility="{Binding IsDatabaseUpdate,Converter={StaticResource BooleanToVisibilityInverseConverter}}"> - <Run>Version</Run> - <Run Foreground="{StaticResource TangoPrimaryAccentBrush}" FontWeight="SemiBold" Text="{Binding Version,FallbackValue='1.0.0.0',TargetNullValue='1.0.0.0'}"></Run> - <Run>is available!</Run> - <Run>Tap to start updating your system.</Run> - </TextBlock> - <TextBlock Margin="20 0 0 0" VerticalAlignment="Center" Text="Database updates are available. Tap to start updating your system." Visibility="{Binding IsDatabaseUpdate,Converter={StaticResource BooleanToVisibilityConverter}}"></TextBlock> - </Grid> - </DockPanel> - </Border> - </Grid> -</UserControl> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml.cs deleted file mode 100644 index 791d40540..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/UpdateAvailableNotificationItemView.xaml.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace Tango.PPC.UI.Notifications.NotificationItems -{ - /// <summary> - /// Represents the <see cref="UpdateAvailableNotificationItemView"/> view. - /// </summary> - /// <seealso cref="System.Windows.Controls.UserControl" /> - /// <seealso cref="System.Windows.Markup.IComponentConnector" /> - public partial class UpdateAvailableNotificationItemView : UserControl - { - public UpdateAvailableNotificationItemView() - { - InitializeComponent(); - } - } -} |
