aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
diff options
context:
space:
mode:
authorRoy <roy.mail.net@gmail.com>2017-12-24 02:27:16 +0200
committerRoy <roy.mail.net@gmail.com>2017-12-24 02:27:16 +0200
commit53db041e636bb3802dbe3cb911de6ef6ef41446c (patch)
tree9be0b0961a31fea4a60f5a9c1741363fa313a13b /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
parentceac40d058a8554638aa3fa39d4697f3fbfe62f8 (diff)
downloadTango-53db041e636bb3802dbe3cb911de6ef6ef41446c.tar.gz
Tango-53db041e636bb3802dbe3cb911de6ef6ef41446c.zip
Continue for last commit.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs114
1 files changed, 90 insertions, 24 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
index b1ba03109..3c245510b 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
@@ -35,48 +35,114 @@ namespace Tango.MachineStudio.UI.Notifications
TaskItems = new ObservableCollection<TaskItem>();
}
- public bool ShowModalWindow<T>(PackIconKind icon, string title, object context) where T : FrameworkElement
- {
- return ShowModalWindow(icon, title, Activator.CreateInstance<T>(), context);
- }
-
- public bool? ShowModalWindow(Window window)
+ public bool? ShowDialog(PackIconKind icon, Brush iconColor, string message, bool hasCancel)
{
- window.Owner = Application.Current.MainWindow;
MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;
- bool result = window.ShowDialog().Value;
+
+ var result = new MessageBoxWindow()
+ {
+ Owner = Application.Current.MainWindow,
+ Message = message,
+ IconKind = icon,
+ IconColor = iconColor,
+ HasCancel = hasCancel
+
+ }.ShowDialog();
+
MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden;
return result;
}
- public bool ShowModalWindow(PackIconKind icon, string title, FrameworkElement content, object context)
+ public void ShowModalDialog<View, VM>(Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM
{
- DialogWindow dialog = new DialogWindow(content);
- dialog.DataContext = context;
- dialog.InnerTitle = title;
+ var view = Activator.CreateInstance<View>();
+ DialogWindow dialog = new DialogWindow();
dialog.Owner = Application.Current.MainWindow;
+ dialog.InnerContent = view;
MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;
- bool result = dialog.ShowDialog().Value;
+ view.Loaded += (x, y) =>
+ {
+ VM context = view.DataContext as VM;
+ dialog.DataContext = context;
+
+ Action onAcceptAction = null;
+ onAcceptAction = new Action(() =>
+ {
+ dialog.Close();
+ onAccept(context);
+ context.Accepted -= onAcceptAction;
+ });
+
+ Action onCancelAction = null;
+ onCancelAction = new Action(() =>
+ {
+ dialog.Close();
+
+ if (onCancel != null)
+ {
+ onCancel();
+ }
+
+ context.Canceled -= onCancelAction;
+ });
+
+ context.Accepted += onAcceptAction;
+ context.Canceled += onCancelAction;
+
+ context.OnShow();
+ };
+ dialog.ShowDialog();
MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden;
- return result;
}
- public bool? ShowDialog(PackIconKind icon, Brush iconColor, string message, bool hasCancel)
+ public void ShowModalDialog<VM>(Action<VM> onAccept, Action onCancel) where VM : DialogViewVM
{
- MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;
+ String viewName = typeof(VM).Name.Replace("VM", "");
- var result = new MessageBoxWindow()
+ var view = Activator.CreateInstance(AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).Single(x => x.Name == viewName)) as FrameworkElement;
+ DialogWindow dialog = new DialogWindow();
+ dialog.Owner = Application.Current.MainWindow;
+ dialog.InnerContent = view;
+ MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;
+ view.Loaded += (x, y) =>
{
- Owner = Application.Current.MainWindow,
- Message = message,
- IconKind = icon,
- IconColor = iconColor,
- HasCancel = hasCancel
+ VM context = view.DataContext as VM;
+ dialog.DataContext = context;
- }.ShowDialog();
+ Action onAcceptAction = null;
+ onAcceptAction = new Action(() =>
+ {
+ dialog.Close();
+ onAccept(context);
+ context.Accepted -= onAcceptAction;
+ });
+
+ Action onCancelAction = null;
+ onCancelAction = new Action(() =>
+ {
+ dialog.Close();
+
+ if (onCancel != null)
+ {
+ onCancel();
+ }
+
+ context.Canceled -= onCancelAction;
+ });
+ context.Accepted += onAcceptAction;
+ context.Canceled += onCancelAction;
+
+ context.OnShow();
+ };
+
+ dialog.ShowDialog();
MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden;
- return result;
+ }
+
+ public void ShowModalDialog<VM>(Action<VM> onAccept) where VM : DialogViewVM
+ {
+ ShowModalDialog<VM>(onAccept, null);
}
public void ShowError(string message)