diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-05-27 19:33:15 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-05-27 19:33:15 +0300 |
| commit | e571f20e27c4fca6bb6efe03d6427a1f332f9830 (patch) | |
| tree | b16041b76ea3b4e8368039c9396f9bbf9624dcc2 /Software/Visual_Studio/PPC/Tango.PPC.Common/Notification | |
| parent | 157e0685abb2e7b22b6584cdc7d6f5838ed0a808 (diff) | |
| download | Tango-e571f20e27c4fca6bb6efe03d6427a1f332f9830.tar.gz Tango-e571f20e27c4fca6bb6efe03d6427a1f332f9830.zip | |
Working on panel pc.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Notification')
3 files changed, 265 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/DialogViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/DialogViewVM.cs new file mode 100644 index 000000000..b7a48f259 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/DialogViewVM.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.SharedUI; + +namespace Tango.PPC.Common.Notifications +{ + /// <summary> + /// Represents a dialog view model base class. + /// </summary> + /// <seealso cref="Tango.SharedUI.ViewModel" /> + public abstract class DialogViewVM : ViewModel + { + public event Action Accepted; + public event Action Canceled; + + /// <summary> + /// Initializes a new instance of the <see cref="DialogViewVM"/> class. + /// </summary> + public DialogViewVM() + { + CanClose = true; + CloseCommand = new RelayCommand(Cancel, (x) => CanClose); + OKCommand = new RelayCommand(Accept, (x) => CanClose); + } + + private bool _canClose; + /// <summary> + /// Gets or sets a value indicating whether this dialog can be closed. + /// </summary> + public bool CanClose + { + get { return _canClose; } + set { _canClose = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + /// <summary> + /// Gets or sets the close command. + /// </summary> + public RelayCommand CloseCommand { get; set; } + + /// <summary> + /// Gets or sets the ok command. + /// </summary> + public RelayCommand OKCommand { get; set; } + + /// <summary> + /// Called when the dialog has been shown. + /// </summary> + public virtual void OnShow() + { + + } + + /// <summary> + /// Invokes the <see cref="Accepted"/> event. + /// </summary> + protected virtual void Accept() + { + Accepted?.Invoke(); + } + + /// <summary> + /// Invokes the <see cref="Canceled"/> event. + /// </summary> + protected virtual void Cancel() + { + Canceled?.Invoke(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/INotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/INotificationProvider.cs new file mode 100644 index 000000000..edad5c1e9 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/INotificationProvider.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; + +namespace Tango.PPC.Common.Notifications +{ + /// <summary> + /// Represents the Machine Studio user notification provider responsible for displaying information, alerts and dialogs to the user. + /// </summary> + public interface INotificationProvider + { + /// <summary> + /// Gets the collection of active task items. + /// </summary> + ObservableCollection<TaskItem> TaskItems { get; } + + /// <summary> + /// Gets the current displayed task item. + /// </summary> + TaskItem CurrentTaskItem { get; } + + /// <summary> + /// Gets a value indicating whether there are any queued task items. + /// </summary> + bool HasTaskItems { get; } + + /// <summary> + /// Pushes the specified task item to the queue. + /// </summary> + /// <param name="taskItem">The task item.</param> + void PushTaskItem(TaskItem taskItem); + + /// <summary> + /// Create and push a new task item from the specified message. + /// </summary> + /// <param name="message">The message.</param> + /// <returns></returns> + TaskItem PushTaskItem(String message); + + /// <summary> + /// Removed the specified task item from the queue. + /// </summary> + /// <param name="taskItem">The task item.</param> + void PopTaskItem(TaskItem taskItem); + + /// <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> + void ShowModalDialog<View, VM>(Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM; + + /// <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> + void ShowModalDialog<VM>(Action<VM> onAccept, Action onCancel) where VM : DialogViewVM; + + /// <summary> + /// Shows the specified view with the specified view model as it's data context. + /// </summary> + /// <typeparam name="VM">The type of the mm.</typeparam> + /// <typeparam name="View">The type of the view.</typeparam> + /// <param name="vm">The view model.</param> + /// <param name="onAccept">The accept action.</param> + /// <param name="onCancel">The cancel action.</param> + void ShowModalDialog<VM, View>(VM vm, Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM; + + /// <summary> + /// Shows the specified view with the specified view model as it's data context. + /// </summary> + /// <typeparam name="VM">The type of the mm.</typeparam> + /// <typeparam name="View">The type of the view.</typeparam> + /// <param name="vm">The view model.</param> + /// <param name="view">The view.</param> + /// <param name="onAccept">The accept action.</param> + /// <param name="onCancel">The cancel action.</param> + void ShowModalDialog<VM, View>(VM vm, View view, Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM; + + /// <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> + void ShowModalDialog<VM>(Action<VM> onAccept) where VM : DialogViewVM; + + /// <summary> + /// Shows an information message box. + /// </summary> + /// <param name="message">The message.</param> + void ShowInfo(String message); + + /// <summary> + /// Shows warning message box. + /// </summary> + /// <param name="message">The message.</param> + void ShowWarning(String message); + + /// <summary> + /// Shows an error message box. + /// </summary> + /// <param name="message">The message.</param> + void ShowError(String message); + + /// <summary> + /// Shows a question message box. + /// </summary> + /// <param name="message">The message.</param> + bool ShowQuestion(String message); + + /// <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> + String ShowTextInput(String message, String hint, String defaultResponse = null); + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/TaskItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/TaskItem.cs new file mode 100644 index 000000000..b9ffa4a72 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/TaskItem.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.PPC.Common.Notifications +{ + /// <summary> + /// Represents a Machine Studio "work-bar" item. + /// </summary> + /// <seealso cref="Tango.Core.ExtendedObject" /> + /// <seealso cref="System.IDisposable" /> + public class TaskItem : ExtendedObject, IDisposable + { + private INotificationProvider _notificationProvider; + + /// <summary> + /// Initializes a new instance of the <see cref="TaskItem"/> class. + /// </summary> + /// <param name="notificationProvider">The notification provider.</param> + public TaskItem(INotificationProvider notificationProvider) + { + _notificationProvider = notificationProvider; + } + + private String _message; + /// <summary> + /// Gets or sets the message. + /// </summary> + public String Message + { + get { return _message; } + set { _message = value; RaisePropertyChangedAuto(); } + } + + /// <summary> + /// Removed this item from the queue. + /// </summary> + public void Pop() + { + _notificationProvider.PopTaskItem(this); + } + + /// <summary> + /// Pushes this item to the queue. + /// </summary> + public void Push() + { + _notificationProvider.PushTaskItem(this); + } + + /// <summary> + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// </summary> + public void Dispose() + { + Pop(); + } + } +} |
