diff options
| author | Avi Levkovich <avi@twine-s.com> | 2018-02-20 16:45:00 +0200 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2018-02-20 16:45:00 +0200 |
| commit | 6c208c90bc45aff4a7fa214356a42fe7757c5e6f (patch) | |
| tree | 0d77bc6a0ecfbb53cf42c5462ee19212197ee1bd /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs | |
| parent | b0823127f152fe97a6e8fce29e427c7f3db9cf5a (diff) | |
| parent | 1a573aaa346ec4b8bd58a0e35ab9df571a09b855 (diff) | |
| download | Tango-6c208c90bc45aff4a7fa214356a42fe7757c5e6f.tar.gz Tango-6c208c90bc45aff4a7fa214356a42fe7757c5e6f.zip | |
MERGE
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.cs | 168 |
1 files changed, 159 insertions, 9 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 d4d053eaf..1ea22c587 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs @@ -13,31 +13,68 @@ using System.Collections.ObjectModel; namespace Tango.MachineStudio.UI.Notifications { + /// <summary> + /// Represents the default Machine Studio <see cref="INotificationProvider">Notification Provider</see>. + /// </summary> + /// <seealso cref="Tango.Core.ExtendedObject" /> + /// <seealso cref="Tango.MachineStudio.Common.Notifications.INotificationProvider" /> public class DefaultNotificationProvider : ExtendedObject, INotificationProvider { + /// <summary> + /// The view types + /// </summary> private static List<Type> viewTypes; + /// <summary> + /// Gets the collection of active task items. + /// </summary> public ObservableCollection<TaskItem> TaskItems { get; private set; } + /// <summary> + /// Gets the collection of active bar items. + /// </summary> + public ObservableCollection<BarItem> BarItems { get; private set; } + + /// <summary> + /// Gets a value indicating whether there are any queued task items. + /// </summary> public bool HasTaskItems { get { return TaskItems.Count > 0; } } + /// <summary> + /// The current task item + /// </summary> private TaskItem _currentTaskItem; + /// <summary> + /// Gets the current displayed task item. + /// </summary> public TaskItem CurrentTaskItem { get { return _currentTaskItem; } set { _currentTaskItem = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasTaskItems)); } } + /// <summary> + /// Initializes a new instance of the <see cref="DefaultNotificationProvider"/> class. + /// </summary> public DefaultNotificationProvider() { TaskItems = new ObservableCollection<TaskItem>(); + BarItems = new ObservableCollection<BarItem>(); } - public bool? ShowDialog(PackIconKind icon, Brush iconColor, string message, bool hasCancel) + /// <summary> + /// Display a message box. + /// </summary> + /// <param name="icon">The icon.</param> + /// <param name="iconColor">Color of the icon.</param> + /// <param name="message">The message.</param> + /// <param name="hasCancel">if set to <c>true</c> displays the cancel button.</param> + /// <returns></returns> + public bool? ShowMessageBox(PackIconKind icon, Brush iconColor, string message, bool hasCancel) { MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; @@ -55,6 +92,13 @@ namespace Tango.MachineStudio.UI.Notifications return result; } + /// <summary> + /// Creates a new instance of the specified View type and displays it as a modal dialog. + /// </summary> + /// <typeparam name="View">The type of the view.</typeparam> + /// <typeparam name="VM">The type of the view model.</typeparam> + /// <param name="onAccept">Accept button callback.</param> + /// <param name="onCancel">Cancel button callback.</param> public void ShowModalDialog<View, VM>(Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM { var view = Activator.CreateInstance<View>(); @@ -68,7 +112,7 @@ namespace Tango.MachineStudio.UI.Notifications dialog.DataContext = context; Action onAcceptAction = null; - onAcceptAction = new Action(() => + onAcceptAction = new Action(() => { dialog.Close(); onAccept(context); @@ -76,7 +120,7 @@ namespace Tango.MachineStudio.UI.Notifications }); Action onCancelAction = null; - onCancelAction = new Action(() => + onCancelAction = new Action(() => { dialog.Close(); @@ -97,6 +141,13 @@ namespace Tango.MachineStudio.UI.Notifications MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; } + /// <summary> + /// Creates a new view by a naming convention of the specified view model type. + /// </summary> + /// <typeparam name="VM">The type of the view model.</typeparam> + /// <param name="onAccept">Accept button callback.</param> + /// <param name="onCancel">Cancel button callback.</param> + /// <exception cref="NullReferenceException">Could not locate view " + viewName</exception> public void ShowModalDialog<VM>(Action<VM> onAccept, Action onCancel) where VM : DialogViewVM { String viewName = typeof(VM).Name.Replace("VM", ""); @@ -121,6 +172,10 @@ namespace Tango.MachineStudio.UI.Notifications view.Loaded += (x, y) => { VM context = view.DataContext as VM; + if (context == null) + { + context = Activator.CreateInstance<VM>(); + } dialog.DataContext = context; Action onAcceptAction = null; @@ -149,42 +204,73 @@ namespace Tango.MachineStudio.UI.Notifications context.OnShow(); }; - + dialog.ShowDialog(); MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; } + /// <summary> + /// Creates a new view by a naming convention of the specified view model type. + /// </summary> + /// <typeparam name="VM">The type of the view model.</typeparam> + /// <param name="onAccept">Accept button callback.</param> public void ShowModalDialog<VM>(Action<VM> onAccept) where VM : DialogViewVM { ShowModalDialog<VM>(onAccept, null); } + /// <summary> + /// Shows an error message box. + /// </summary> + /// <param name="message">The message.</param> public void ShowError(string message) { - ShowDialog(PackIconKind.Exclamation, Brushes.Red, message, false); + ShowMessageBox(PackIconKind.Exclamation, Brushes.Red, message, false); } + /// <summary> + /// Shows an information message box. + /// </summary> + /// <param name="message">The message.</param> public void ShowInfo(string message) { - ShowDialog(PackIconKind.Information, Brushes.Black, message, false); + ShowMessageBox(PackIconKind.Information, Brushes.Black, message, false); } + /// <summary> + /// Shows a question message box. + /// </summary> + /// <param name="message">The message.</param> + /// <returns></returns> public bool ShowQuestion(string message) { - return ShowDialog(PackIconKind.CommentQuestionOutline, Brushes.Black, message, true).Value; + return ShowMessageBox(PackIconKind.CommentQuestionOutline, Brushes.Black, message, true).Value; } - public void ShowWarnning(string message) + /// <summary> + /// Shows warning message box. + /// </summary> + /// <param name="message">The message.</param> + public void ShowWarning(string message) { - ShowDialog(PackIconKind.Exclamation, Brushes.DarkOrange, message, false); + ShowMessageBox(PackIconKind.Exclamation, Brushes.DarkOrange, message, false); } + /// <summary> + /// Pushes the specified task item to the queue. + /// </summary> + /// <param name="taskItem">The task item.</param> public void PushTaskItem(TaskItem taskItem) { TaskItems.Add(taskItem); CurrentTaskItem = taskItem; } + /// <summary> + /// Create and push a new task item from the specified message. + /// </summary> + /// <param name="message">The message.</param> + /// <returns></returns> public TaskItem PushTaskItem(string message) { TaskItem item = new TaskItem(this); @@ -193,6 +279,10 @@ namespace Tango.MachineStudio.UI.Notifications return item; } + /// <summary> + /// Removed the specified task item from the queue. + /// </summary> + /// <param name="taskItem">The task item.</param> public void PopTaskItem(TaskItem taskItem) { TaskItems.Remove(taskItem); @@ -204,5 +294,65 @@ namespace Tango.MachineStudio.UI.Notifications RaisePropertyChanged(nameof(HasTaskItems)); } + + /// <summary> + /// Pushes the specified bar item. + /// </summary> + /// <param name="barItem">The bar item.</param> + /// <returns></returns> + public BarItem PushBarItem(BarItem barItem) + { + BarItems.Add(barItem); + return barItem; + } + + /// <summary> + /// Creates and push a new bar item from the specified framework element. + /// </summary> + /// <param name="element">The element.</param> + /// <returns></returns> + public BarItem PushBarItem(FrameworkElement element) + { + BarItem item = new BarItem(this); + item.Element = element; + PushBarItem(item); + return item; + } + + /// <summary> + /// Removed the specified bar item. + /// </summary> + /// <param name="barItem">The bar item.</param> + public void PopBarItem(BarItem barItem) + { + BarItems.Remove(barItem); + } + + /// <summary> + /// Shows a dialog with a text input field and returns the response. + /// </summary> + /// <param name="message">The message.</param> + /// <param name="hint">Text field hint.</param> + /// <param name="defaultResponse">Optional default response.</param> + /// <returns></returns> + public string ShowTextInput(string message, string hint, string defaultResponse = null) + { + MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; + + TextInputBoxWindow dlg = new TextInputBoxWindow() + { + Owner = Application.Current.MainWindow, + Message = message, + IconKind = PackIconKind.Pencil, + IconColor = Brushes.DimGray, + Hint = hint, + Response = defaultResponse + }; + + var result = dlg.ShowDialog(); + + MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + return (result.Value ? dlg.Response : null); + } } } |
