From e571f20e27c4fca6bb6efe03d6427a1f332f9830 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 27 May 2018 19:33:15 +0300 Subject: Working on panel pc. --- .../Tango.PPC.Common/Notification/DialogViewVM.cs | 74 ++++++++++++ .../Notification/INotificationProvider.cs | 129 +++++++++++++++++++++ .../PPC/Tango.PPC.Common/Notification/TaskItem.cs | 62 ++++++++++ 3 files changed, 265 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/DialogViewVM.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/INotificationProvider.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Notification/TaskItem.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Notification') 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 +{ + /// + /// Represents a dialog view model base class. + /// + /// + public abstract class DialogViewVM : ViewModel + { + public event Action Accepted; + public event Action Canceled; + + /// + /// Initializes a new instance of the class. + /// + public DialogViewVM() + { + CanClose = true; + CloseCommand = new RelayCommand(Cancel, (x) => CanClose); + OKCommand = new RelayCommand(Accept, (x) => CanClose); + } + + private bool _canClose; + /// + /// Gets or sets a value indicating whether this dialog can be closed. + /// + public bool CanClose + { + get { return _canClose; } + set { _canClose = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + /// + /// Gets or sets the close command. + /// + public RelayCommand CloseCommand { get; set; } + + /// + /// Gets or sets the ok command. + /// + public RelayCommand OKCommand { get; set; } + + /// + /// Called when the dialog has been shown. + /// + public virtual void OnShow() + { + + } + + /// + /// Invokes the event. + /// + protected virtual void Accept() + { + Accepted?.Invoke(); + } + + /// + /// Invokes the event. + /// + 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 +{ + /// + /// Represents the Machine Studio user notification provider responsible for displaying information, alerts and dialogs to the user. + /// + public interface INotificationProvider + { + /// + /// Gets the collection of active task items. + /// + ObservableCollection TaskItems { get; } + + /// + /// Gets the current displayed task item. + /// + TaskItem CurrentTaskItem { get; } + + /// + /// Gets a value indicating whether there are any queued task items. + /// + bool HasTaskItems { get; } + + /// + /// Pushes the specified task item to the queue. + /// + /// The task item. + void PushTaskItem(TaskItem taskItem); + + /// + /// Create and push a new task item from the specified message. + /// + /// The message. + /// + TaskItem PushTaskItem(String message); + + /// + /// Removed the specified task item from the queue. + /// + /// The task item. + void PopTaskItem(TaskItem taskItem); + + /// + /// Creates a new instance of the specified View type and displays it as a modal dialog. + /// + /// The type of the view. + /// The type of the view model. + /// Accept button callback. + /// Cancel button callback. + void ShowModalDialog(Action onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM; + + /// + /// Creates a new view by a naming convention of the specified view model type. + /// + /// The type of the view model. + /// Accept button callback. + /// Cancel button callback. + void ShowModalDialog(Action onAccept, Action onCancel) where VM : DialogViewVM; + + /// + /// Shows the specified view with the specified view model as it's data context. + /// + /// The type of the mm. + /// The type of the view. + /// The view model. + /// The accept action. + /// The cancel action. + void ShowModalDialog(VM vm, Action onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM; + + /// + /// Shows the specified view with the specified view model as it's data context. + /// + /// The type of the mm. + /// The type of the view. + /// The view model. + /// The view. + /// The accept action. + /// The cancel action. + void ShowModalDialog(VM vm, View view, Action onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM; + + /// + /// Creates a new view by a naming convention of the specified view model type. + /// + /// The type of the view model. + /// Accept button callback. + void ShowModalDialog(Action onAccept) where VM : DialogViewVM; + + /// + /// Shows an information message box. + /// + /// The message. + void ShowInfo(String message); + + /// + /// Shows warning message box. + /// + /// The message. + void ShowWarning(String message); + + /// + /// Shows an error message box. + /// + /// The message. + void ShowError(String message); + + /// + /// Shows a question message box. + /// + /// The message. + bool ShowQuestion(String message); + + /// + /// Shows a dialog with a text input field and returns the response. + /// + /// The message. + /// Text field hint. + /// Optional default response. + /// + 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 +{ + /// + /// Represents a Machine Studio "work-bar" item. + /// + /// + /// + public class TaskItem : ExtendedObject, IDisposable + { + private INotificationProvider _notificationProvider; + + /// + /// Initializes a new instance of the class. + /// + /// The notification provider. + public TaskItem(INotificationProvider notificationProvider) + { + _notificationProvider = notificationProvider; + } + + private String _message; + /// + /// Gets or sets the message. + /// + public String Message + { + get { return _message; } + set { _message = value; RaisePropertyChangedAuto(); } + } + + /// + /// Removed this item from the queue. + /// + public void Pop() + { + _notificationProvider.PopTaskItem(this); + } + + /// + /// Pushes this item to the queue. + /// + public void Push() + { + _notificationProvider.PushTaskItem(this); + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + Pop(); + } + } +} -- cgit v1.3.1