aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2018-06-30 03:59:41 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2018-06-30 03:59:41 +0300
commit010535f3064bbf69f063c5f329b7689c070a4ea8 (patch)
tree6e3f1b0ea6cc27373c3aea7159069f63ba8c9d0b /Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
parent48904928ae83d9c836fe8408374a21af01e5b132 (diff)
downloadTango-010535f3064bbf69f063c5f329b7689c070a4ea8.tar.gz
Tango-010535f3064bbf69f063c5f329b7689c070a4ea8.zip
Implemented "Dialogs" on TouchPanel and PPC INotificationProvider !
Added Inject method to TangoIOC. Started working on color correction.
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.cs152
1 files changed, 127 insertions, 25 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 fc1ba894f..ae777839b 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
@@ -14,6 +14,9 @@ using Tango.SharedUI.Helpers;
using System.Timers;
using Tango.Core.Commands;
using Tango.Touch.Controls;
+using Tango.SharedUI;
+using System.Reflection;
+using Tango.Core.DI;
namespace Tango.PPC.UI.Notifications
{
@@ -29,23 +32,8 @@ namespace Tango.PPC.UI.Notifications
/// </summary>
public ObservableCollection<NotificationItem> NotificationItems { get; private set; }
- /// <summary>
- /// Represents a pending message box.
- /// </summary>
- private class PendingMessageBox
- {
- /// <summary>
- /// Gets or sets the message view model.
- /// </summary>
- public MessageBoxVM VM { get; set; }
-
- /// <summary>
- /// Gets or sets the message task completion source.
- /// </summary>
- public TaskCompletionSource<bool> CompletionSource { get; set; }
- }
-
- private ConcurrentQueue<PendingMessageBox> _pendingMessageBoxes;
+ private ConcurrentQueue<PendingNotification<MessageBoxVM, bool>> _pendingMessageBoxes;
+ private ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>> _pendingDialogs;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultNotificationProvider"/> class.
@@ -53,7 +41,8 @@ namespace Tango.PPC.UI.Notifications
public DefaultNotificationProvider()
{
NotificationItems = new ObservableCollection<NotificationItem>();
- _pendingMessageBoxes = new ConcurrentQueue<PendingMessageBox>();
+ _pendingMessageBoxes = new ConcurrentQueue<PendingNotification<MessageBoxVM, bool>>();
+ _pendingDialogs = new ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>>();
PopNotificationCommand = new RelayCommand<NotificationItem>((x) => PopNotification(x));
}
@@ -84,6 +73,32 @@ namespace Tango.PPC.UI.Notifications
}
}
+ private FrameworkElement _currentDialog;
+ /// <summary>
+ /// Gets the current dialog if any.
+ /// </summary>
+ public FrameworkElement CurrentDialog
+ {
+ get { return _currentDialog; }
+ private set
+ {
+ _currentDialog = value;
+ RaisePropertyChangedAuto();
+ RaisePropertyChanged(nameof(HasDialog));
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether a dialog is available.
+ /// </summary>
+ public bool HasDialog
+ {
+ get
+ {
+ return CurrentDialog != null;
+ }
+ }
+
/// <summary>
/// Shows an error message box.
/// </summary>
@@ -167,11 +182,7 @@ namespace Tango.PPC.UI.Notifications
}
else
{
- _pendingMessageBoxes.Enqueue(new PendingMessageBox()
- {
- VM = vm,
- CompletionSource = source,
- });
+ _pendingMessageBoxes.Enqueue(new PendingNotification<MessageBoxVM, bool>(vm, source));
}
return source.Task;
@@ -186,10 +197,10 @@ namespace Tango.PPC.UI.Notifications
if (_pendingMessageBoxes.Count > 0)
{
- PendingMessageBox p = null;
+ PendingNotification<MessageBoxVM, bool> p = null;
if (_pendingMessageBoxes.TryDequeue(out p))
{
- CurrentMessageBox = p.VM;
+ CurrentMessageBox = p.Item;
}
}
}
@@ -284,5 +295,96 @@ namespace Tango.PPC.UI.Notifications
}
public RelayCommand<NotificationItem> PopNotificationCommand { get; private set; }
+
+ /// <summary>
+ /// Displays the specified dialog in a modal design.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="datacontext">The data context.</param>
+ /// <param name="view">The view.</param>
+ /// <returns></returns>
+ public async Task<T> ShowDialog<T>(T datacontext, FrameworkElement view) where T : DialogViewVM
+ {
+ view.DataContext = datacontext;
+
+ TangoIOC.Default.Inject(datacontext);
+
+ view.Loaded += (_, __) =>
+ {
+ view.DataContext = datacontext;
+ datacontext.OnShow();
+ };
+
+ TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>();
+
+ 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;
+ }
+
+ private void OnDialogClosed()
+ {
+ CurrentDialog = null;
+
+ if (_pendingDialogs.Count > 0)
+ {
+ PendingNotification<DialogAndView, DialogViewVM> p = null;
+ if (_pendingDialogs.TryDequeue(out p))
+ {
+ CurrentDialog = p.Item.View;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Displays the specified dialog in a modal design.
+ /// The notification provider will try to locate the view automatically using conventions.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="datacontext">The data context.</param>
+ /// <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);
+
+ if (viewType == null)
+ {
+ throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!");
+ }
+
+ var view = Activator.CreateInstance(viewType) as FrameworkElement;
+
+ if (view == null)
+ {
+ throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element.");
+ }
+
+ return ShowDialog<T>(datacontext, Activator.CreateInstance(viewType) as FrameworkElement);
+ }
+
+ /// <summary>
+ /// Displays the specified dialog in a modal design.
+ /// The data context instance will be automatically created.
+ /// The notification provider will try to locate the view automatically using conventions.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <returns></returns>
+ public Task<T> ShowDialog<T>() where T : DialogViewVM
+ {
+ return ShowDialog<T>(Activator.CreateInstance<T>());
+ }
}
}