aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
diff options
context:
space:
mode:
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.cs128
1 files changed, 81 insertions, 47 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 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
{
@@ -47,6 +49,16 @@ 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; }
@@ -58,6 +70,10 @@ 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>>();
@@ -66,6 +82,9 @@ 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;
@@ -322,29 +341,33 @@ namespace Tango.PPC.UI.Notifications
/// <returns></returns>
public async Task<T> ShowDialog<T>(T datacontext, FrameworkElement view) where T : DialogViewVM
{
- view.DataContext = datacontext;
-
- TangoIOC.Default.Inject(datacontext);
+ TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>();
- view.Loaded += (_, __) =>
+ InvokeUI(() =>
{
view.DataContext = datacontext;
- datacontext.OnShow();
- };
- TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>();
+ 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<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;
@@ -376,23 +399,31 @@ namespace Tango.PPC.UI.Notifications
/// <returns></returns>
public Task<T> ShowDialog<T>(T datacontext) where T : DialogViewVM
{
- var callingAssembly = datacontext.GetType().Assembly;
- String viewName = datacontext.GetType().FullName.Replace("VM", "");
- var viewType = callingAssembly.GetType(viewName);
+ TaskCompletionSource<T> source = new TaskCompletionSource<T>();
- 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<T>(datacontext, view);
+ if (view == null)
+ {
+ throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element.");
+ }
+
+ T result = await ShowDialog<T>(datacontext, view);
+ source.SetResult(result);
+ });
+
+ return source.Task;
}
/// <summary>
@@ -404,7 +435,15 @@ namespace Tango.PPC.UI.Notifications
/// <returns></returns>
public Task<T> ShowDialog<T>() where T : DialogViewVM
{
- return ShowDialog<T>(Activator.CreateInstance<T>());
+ TaskCompletionSource<T> source = new TaskCompletionSource<T>();
+
+ InvokeUI(async () =>
+ {
+ var result = await ShowDialog<T>(Activator.CreateInstance<T>());
+ source.SetResult(result);
+ });
+
+ return source.Task;
}
/// <summary>
@@ -442,22 +481,12 @@ 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 HasAppBarItem
+ public bool HasAppBarItems
{
- get { return CurrentAppBarItem != null; }
+ get { return AppBarItems.Count > 0; }
}
/// <summary>
@@ -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
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
- public AppBarItem PushAppBarItem<T>() where T : AppBarItem
+ public T PushAppBarItem<T>() where T : AppBarItem
{
- return PushAppBarItem(Activator.CreateInstance<T>());
+ return PushAppBarItem(Activator.CreateInstance<T>()) as T;
}
/// <summary>
@@ -489,8 +519,12 @@ namespace Tango.PPC.UI.Notifications
/// <param name="appBarItem">The application bar item.</param>
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));
+ });
}
/// <summary>