From 00a491d93733d4625ad329b2ba8237f445364b3f Mon Sep 17 00:00:00 2001 From: Mirta Date: Wed, 30 Dec 2020 16:39:52 +0200 Subject: merge --- .../Notifications/DefaultNotificationProvider.cs | 128 ++++++++------------- 1 file changed, 47 insertions(+), 81 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 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 { @@ -48,16 +46,6 @@ 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. /// @@ -70,10 +58,6 @@ 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>(); @@ -82,9 +66,6 @@ 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; @@ -341,33 +322,29 @@ namespace Tango.PPC.UI.Notifications /// public async Task ShowDialog(T datacontext, FrameworkElement view) where T : DialogViewVM { - TaskCompletionSource source = new TaskCompletionSource(); + 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 source = new TaskCompletionSource(); - 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; @@ -399,31 +376,23 @@ namespace Tango.PPC.UI.Notifications /// public Task ShowDialog(T datacontext) where T : DialogViewVM { - TaskCompletionSource source = new TaskCompletionSource(); + 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(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(datacontext, view); } /// @@ -435,15 +404,7 @@ namespace Tango.PPC.UI.Notifications /// public Task ShowDialog() where T : DialogViewVM { - TaskCompletionSource source = new TaskCompletionSource(); - - InvokeUI(async () => - { - var result = await ShowDialog(Activator.CreateInstance()); - source.SetResult(result); - }); - - return source.Task; + return ShowDialog(Activator.CreateInstance()); } /// @@ -481,12 +442,22 @@ 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 HasAppBarItems + public bool HasAppBarItem { - get { return AppBarItems.Count > 0; } + get { return CurrentAppBarItem != null; } } /// @@ -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 /// /// /// - public T PushAppBarItem() where T : AppBarItem + public AppBarItem PushAppBarItem() where T : AppBarItem { - return PushAppBarItem(Activator.CreateInstance()) as T; + return PushAppBarItem(Activator.CreateInstance()); } /// @@ -519,12 +489,8 @@ namespace Tango.PPC.UI.Notifications /// The application bar item. 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; } /// -- cgit v1.3.1