From d33c19b3ac6803de4b5c8d475832efef131c1a45 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 30 Dec 2020 15:11:34 +0000 Subject: Revert "Hope it is fine" --- .../Notifications/DefaultNotificationProvider.cs | 128 +++++++++++++-------- 1 file changed, 81 insertions(+), 47 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs') 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 65337a892..e9de2538e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -17,6 +17,8 @@ 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 { @@ -46,6 +48,16 @@ namespace Tango.PPC.UI.Notifications /// public ObservableCollection NotificationItems { get; private set; } + /// + /// Gets the application bar items. + /// + public ObservableCollection AppBarItems { get; private set; } + + /// + /// Gets the notification items view. + /// + public ICollectionView NotificationItemsView { get; private set; } + /// /// Gets the collection of taskbar items. /// @@ -58,6 +70,10 @@ namespace Tango.PPC.UI.Notifications { NotificationsVisible = true; NotificationItems = new ObservableCollection(); + + AppBarItems = new ObservableCollection(); + CollectionViewSource.GetDefaultView(AppBarItems).SortDescriptions.Add(new SortDescription(nameof(AppBarItem.Priority), ListSortDirection.Ascending)); + TaskBarItems = new ObservableCollection(); _pendingMessageBoxes = new ConcurrentQueue>(); _pendingDialogs = new ConcurrentQueue>(); @@ -66,6 +82,9 @@ namespace Tango.PPC.UI.Notifications PopNotificationCommand = new RelayCommand((x) => PopNotification(x)); NotificationItems.EnableCrossThreadOperations(); + + NotificationItemsView = CollectionViewSource.GetDefaultView(NotificationItems); + NotificationItemsView.SortDescriptions.Add(new SortDescription(nameof(NotificationItem.Priority), ListSortDirection.Descending)); } private MessageBoxVM _currentMessageBox; @@ -322,29 +341,33 @@ namespace Tango.PPC.UI.Notifications /// public async Task ShowDialog(T datacontext, FrameworkElement view) where T : DialogViewVM { - view.DataContext = datacontext; - - TangoIOC.Default.Inject(datacontext); + TaskCompletionSource source = new TaskCompletionSource(); - view.Loaded += (_, __) => + InvokeUI(() => { view.DataContext = datacontext; - datacontext.OnShow(); - }; - TaskCompletionSource source = new TaskCompletionSource(); + TangoIOC.Default.Inject(datacontext); - datacontext.Accepted += () => { OnDialogClosed(); source.SetResult(datacontext); }; - datacontext.Canceled += () => { OnDialogClosed(); source.SetResult(datacontext); }; + view.Loaded += (_, __) => + { + view.DataContext = datacontext; + datacontext.OnShow(); + }; - if (CurrentDialog == null) - { - CurrentDialog = view; - } - else - { - _pendingDialogs.Enqueue(new PendingNotification(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(new DialogAndView(datacontext, view), source)); + } + + }); var result = await source.Task; return result as T; @@ -376,23 +399,31 @@ namespace Tango.PPC.UI.Notifications /// public Task ShowDialog(T datacontext) where T : DialogViewVM { - var callingAssembly = datacontext.GetType().Assembly; - String viewName = datacontext.GetType().FullName.Replace("VM", ""); - var viewType = callingAssembly.GetType(viewName); + TaskCompletionSource source = new TaskCompletionSource(); - if (viewType == null) + InvokeUI(async () => { - throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!"); - } + var callingAssembly = datacontext.GetType().Assembly; + String viewName = datacontext.GetType().FullName.Replace("VM", ""); + var viewType = callingAssembly.GetType(viewName); - var view = Activator.CreateInstance(viewType) as FrameworkElement; + if (viewType == null) + { + 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; - return ShowDialog(datacontext, view); + if (view == null) + { + throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element."); + } + + T result = await ShowDialog(datacontext, view); + source.SetResult(result); + }); + + return source.Task; } /// @@ -404,7 +435,15 @@ namespace Tango.PPC.UI.Notifications /// public Task ShowDialog() where T : DialogViewVM { - return ShowDialog(Activator.CreateInstance()); + TaskCompletionSource source = new TaskCompletionSource(); + + InvokeUI(async () => + { + var result = await ShowDialog(Activator.CreateInstance()); + source.SetResult(result); + }); + + return source.Task; } /// @@ -442,22 +481,12 @@ namespace Tango.PPC.UI.Notifications /// public bool IsInGlobalBusyState { get; private set; } - private AppBarItem _currentAppBarItem; - /// - /// Gets the current application bar item. - /// - public AppBarItem CurrentAppBarItem - { - get { return _currentAppBarItem; } - set { _currentAppBarItem = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasAppBarItem)); } - } - /// /// Gets a value indicating whether this instance has application bar item. /// - public bool HasAppBarItem + public bool HasAppBarItems { - get { return CurrentAppBarItem != null; } + get { return AppBarItems.Count > 0; } } /// @@ -468,8 +497,9 @@ namespace Tango.PPC.UI.Notifications public AppBarItem PushAppBarItem(AppBarItem appBarItem) { LogManager.Log($"Pushing AppBarItem '{appBarItem.GetType().Name}'."); - CurrentAppBarItem = appBarItem; + AppBarItems.Add(appBarItem); appBarItem.RemoveAction = () => PopAppBarItem(appBarItem); + RaisePropertyChanged(nameof(HasAppBarItems)); return appBarItem; } @@ -478,9 +508,9 @@ namespace Tango.PPC.UI.Notifications /// /// /// - public AppBarItem PushAppBarItem() where T : AppBarItem + public T PushAppBarItem() where T : AppBarItem { - return PushAppBarItem(Activator.CreateInstance()); + return PushAppBarItem(Activator.CreateInstance()) as T; } /// @@ -489,8 +519,12 @@ namespace Tango.PPC.UI.Notifications /// The application bar item. public void PopAppBarItem(AppBarItem appBarItem) { - LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'."); - CurrentAppBarItem = null; + InvokeUI(() => + { + LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'."); + AppBarItems.Remove(appBarItem); + RaisePropertyChanged(nameof(HasAppBarItems)); + }); } /// -- cgit v1.3.1