diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs | 128 |
1 files changed, 47 insertions, 81 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> |
