From 4a9fb8a89a7fc48d9d3ecc9f24770c472834453d Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 7 Apr 2019 16:14:48 +0300 Subject: added code to launch dynamically dialogs during run time, correct styles treeview item --- .../Notifications/DefaultNotificationManager.cs | 94 +++++++++++++++++++++ .../Notifications/INotificationManager.cs | 95 ++++++++++++++++++++++ .../Notifications/ProgressNotificationHandler.cs | 23 ++++++ 3 files changed, 212 insertions(+) create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/DefaultNotificationManager.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/INotificationManager.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/ProgressNotificationHandler.cs (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications') diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/DefaultNotificationManager.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/DefaultNotificationManager.cs new file mode 100644 index 000000000..7121e6ce0 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/DefaultNotificationManager.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; +using Tango.Scripting.IDE.Windows; +using Tango.SharedUI; + +namespace Tango.Scripting.IDE.Notifications +{ + public class DefaultNotificationManager : INotificationManager + { + public Task ShowDialog(TViewModel viewModel, TView view) + where TViewModel : IDEDialogViewModel + where TView : FrameworkElement + { + TaskCompletionSource source = new TaskCompletionSource(); + + Application.Current.Dispatcher.BeginInvoke(new Action(() => + { + DialogWindow window = new DialogWindow(); + window.Title = viewModel.Title; + window.Content = view; + view.DataContext = viewModel; + window.WindowStartupLocation = WindowStartupLocation.CenterOwner; + window.Owner = Application.Current.MainWindow; + viewModel.Accepted += () => + { + window.Close(); + source.SetResult(viewModel); + }; + viewModel.Canceled += () => + { + window.Close(); + source.SetResult(viewModel); + }; + window.ShowDialog(); + })); + + return source.Task; + } + + public Task ShowDialog(TViewModel viewModel) where TViewModel : IDEDialogViewModel + { + var modelName = typeof(TViewModel).Name; + var viewName = modelName.Replace("VM", ""); + var viewType = typeof(TViewModel).Assembly.GetType(typeof(TViewModel).Namespace + "." + viewName); + var view = Activator.CreateInstance(viewType) as FrameworkElement; + return ShowDialog(viewModel, view); + } + + public Task ShowDialog() where TViewModel : IDEDialogViewModel + { + return ShowDialog(Activator.CreateInstance()); + } + + public Task ShowError(string title, string message) + { + throw new NotImplementedException(); + } + + public Task ShowInfo(string title, string message) + { + throw new NotImplementedException(); + } + + public ProgressNotificationHandler ShowProgress(string title, string message, bool canCancel = false) + { + throw new NotImplementedException(); + } + + public Task ShowQuestion(string title, string message) + { + throw new NotImplementedException(); + } + + public Task ShowSuccess(string title, string message) + { + throw new NotImplementedException(); + } + + public Task ShowWarning(string title, string message) + { + throw new NotImplementedException(); + } + + private Task ShowMessageBox(String title, String message, bool hasCancel, BitmapSource icon) + { + return null; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/INotificationManager.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/INotificationManager.cs new file mode 100644 index 000000000..1ed516b28 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/INotificationManager.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using Tango.SharedUI; + +namespace Tango.Scripting.IDE.Notifications +{ + /// + /// Represents the IDE notification manager. + /// + public interface INotificationManager + { + /// + /// Displays the specified TView as a dialog and TViewModel as it's data context. + /// + /// The type of the view model. + /// The type of the view. + /// The view model. + /// The view. + /// + Task ShowDialog(TViewModel viewModel, TView view) where TViewModel : IDEDialogViewModel where TView : FrameworkElement; + + /// + /// Finds (by convention )the appropriate view by the specified TViewModel name. + /// The search pattern is ViewVM - VM + View. + /// + /// The type of the view model. + /// The view model. + /// + Task ShowDialog(TViewModel viewModel) where TViewModel : IDEDialogViewModel; + + /// + /// Finds (by convention )the appropriate view by the specified TViewModel name. + /// The search pattern is ViewVM - VM + View. + /// The view model instance will be created automatically and must contain a parameterless constructor. + /// + /// The type of the view model. + /// The view model. + /// + Task ShowDialog() where TViewModel : IDEDialogViewModel; + + /// + /// Displays an error message. + /// + /// The title. + /// The message. + /// + Task ShowError(String title, String message); + + /// + /// Displays an error message. + /// + /// The title. + /// The message. + /// + Task ShowInfo(String title, String message); + + /// + /// Displays a warning message. + /// + /// The title. + /// The message. + /// + Task ShowWarning(String title, String message); + + /// + /// Displays a positive message. + /// + /// The title. + /// The message. + /// + Task ShowSuccess(String title, String message); + + /// + /// Displays a question and returns the result. + /// + /// The title. + /// The message. + /// + Task ShowQuestion(String title, String message); + + /// + /// Displays an intermediate progress dialog and returns an instance of . + /// Once the progress notification handler will be disposed the dialog will close. + /// + /// The title. + /// The message. + /// if set to true the dialog will contain a cancel button. + /// + ProgressNotificationHandler ShowProgress(String title, String message, bool canCancel = false); + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/ProgressNotificationHandler.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/ProgressNotificationHandler.cs new file mode 100644 index 000000000..b36419400 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.IDE/Notifications/ProgressNotificationHandler.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.IDE.Notifications +{ + public class ProgressNotificationHandler : IDisposable + { + private Action _disposeAction; + + public ProgressNotificationHandler(Action disposeAction) + { + _disposeAction = disposeAction; + } + + public void Dispose() + { + _disposeAction?.Invoke(); + } + } +} -- cgit v1.3.1