From 2c8da378c82e5181f0566a564de529ab7ef96f4f Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 23 Aug 2018 09:45:01 +0300 Subject: Improvements to machine studio view models and navigation system. Improvements to tech board selection and edit modes handling. --- .../Tango.MachineStudio.Common/IStudioViewModel.cs | 19 +-- .../Navigation/INavigationBlocker.cs | 28 ++++ .../Navigation/INavigationManager.cs | 98 ++++++++++- .../Navigation/INavigationObjectReceiver.cs | 21 +++ .../Navigation/INavigationResultProvider.cs | 28 ++++ .../StudioApplication/IStudioApplicationManager.cs | 7 - .../Tango.MachineStudio.Common/StudioViewModel.cs | 180 ++++----------------- .../Tango.MachineStudio.Common.csproj | 10 +- .../Threading/IDispatcherProvider.cs | 26 +++ 9 files changed, 234 insertions(+), 183 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs index 76cc0433c..be0906fc4 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/IStudioViewModel.cs @@ -3,24 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static Tango.SharedUI.Controls.NavigationControl; namespace Tango.MachineStudio.Common { /// /// Represents a Machine Studio view model. /// - public interface IStudioViewModel + public interface IStudioViewModel : INavigationViewModel { - /// - /// Called when the user has navigated in to the module. - /// - void OnNavigatedTo(); - - /// - /// Called when the user has navigated out of the module. - /// - void OnNavigatedFrom(); - /// /// Called when application is shutting down. /// @@ -33,12 +24,6 @@ namespace Tango.MachineStudio.Common /// Task OnShutdownRequest(); - /// - /// Called when another module has wants to navigate to this module with some arguments. - /// - /// The arguments. - void OnModuleRequest(params object[] args); - /// /// Called when the application has been started /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs new file mode 100644 index 000000000..abd6db172 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationBlocker.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Navigation +{ + /// + /// Represents an object which can abort the navigation from it. + /// + public interface INavigationBlocker + { + /// + /// Called before the navigation system navigates from this object. + /// Return false to abort the navigation. + /// + /// + Task OnNavigateOutRequest(); + + /// + /// Called before the navigation system navigates back from this object. + /// Return false to abort the navigation. + /// + /// + Task OnNavigateBackRequest(); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs index 4d1cbea8c..e20940c8d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.Commands; namespace Tango.MachineStudio.Common.Navigation { @@ -12,9 +13,102 @@ namespace Tango.MachineStudio.Common.Navigation public interface INavigationManager { /// - /// Navigates to the specified view. + /// Gets the current module. + /// + IStudioModule CurrentModule { get; } + + /// + /// Gets the current view model. + /// + StudioViewModel CurrentVM { get; } + + /// + /// Gets a value indicating whether the navigation system is able to navigate to the previous view. + /// + bool CanNavigateBack { get; } + + /// + /// Navigates to the previous view if is true. + /// + Task NavigateBack(); + + /// + /// Navigates to the previous view.. + /// + RelayCommand NavigateBackCommand { get; } + + /// + /// Navigates to the specified full path in command parameter. + /// + RelayCommand NavigateToCommand { get; } + + /// + /// Navigates to the specified PPC view. /// /// The view. - void NavigateTo(NavigationView view); + Task NavigateTo(NavigationView view, bool pushToHistory = true); + + /// + /// Navigates to the specified PPC view with the specified receive object. + /// + /// The view. + Task NavigateWithObject(NavigationView view, TPass obj, bool pushToHistory = true); + + /// + /// Navigates to the specified module. + /// + /// + Task NavigateTo(bool pushToHistory = true) where T : IStudioModule; + + /// + /// Navigates to the specified module using the view path (e.g MainView.JobsView). + /// + /// + /// The view path. + Task NavigateTo(String viewPath, bool pushToHistory = true) where T : IStudioModule; + + /// + /// Navigates to the specified module using the view path (e.g MainView,JobsView). + /// This method makes it easy to do stuff like NavigateTo(nameof(MainView),nameof(JobsView)); + /// + /// + /// The view path. + Task NavigateTo(bool pushToHistory = true, params String[] viewPath) where T : IStudioModule; + + /// + /// Navigates to the specified module and view by full path (e.g Jobs.JobsView). + /// + /// The full path. + Task NavigateTo(String fullPath, bool pushToHistory = true); + + /// + /// Navigates to the specified module and view with the specified object and expecting a return parameter. + /// The view must be of type INavigationResultProvider. + /// + /// The full path. + Task NavigateForResult(TPass obj, bool pushToHistory = true) + where TModule : IStudioModule; + + /// + /// Navigates to the specified module and view with the specified object. + /// + /// The type of the module. + /// The type of the view. + /// The type of the pass. + /// The object. + /// if set to true [push to history]. + /// + Task NavigateWithObject(TPass obj, bool pushToHistory = true) + where TModule : IStudioModule; + + /// + /// Clears the navigation back history. + /// + void ClearHistory(); + + /// + /// Clears the navigation back history except the specified view type. + /// + void ClearHistoryExcept(); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs new file mode 100644 index 000000000..5072881d2 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationObjectReceiver.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Navigation +{ + /// + /// Represents an object which supports receiving an object as part of the navigation to it. + /// + /// + public interface INavigationObjectReceiver + { + /// + /// Called when navigation system is going to navigate to this instance with the specified object. + /// + /// The object. + void OnNavigatedToWithObject(T obj); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs new file mode 100644 index 000000000..dee037432 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationResultProvider.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Navigation +{ + /// + /// Represents a object which provides a result the navigation system navigates away from it. + /// + /// The type of the result. + /// The type of the pass. + public interface INavigationResultProvider + { + /// + /// Called when the navigation system requests a result when it is navigating away from this instance. + /// + /// + TResult GetNavigationResult(); + + /// + /// Called when navigation system is going to navigate to this instance with the specified object. + /// + /// The object. + void OnNavigationObjectReceived(TPass obj); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs index 441a4ca93..96de3eea0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs @@ -44,13 +44,6 @@ namespace Tango.MachineStudio.Common.StudioApplication /// bool IsMachineConnectedViaTCP { get; } - /// - /// Loads the specified module if permitted. - /// - /// Name of the module. - /// The arguments. - void RequestModule(String moduleName, params object[] args); - /// /// Gets the machine studio application version. /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs index 08ddbc073..63ff2119a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.DI; using Tango.SharedUI; namespace Tango.MachineStudio.Common @@ -10,128 +11,42 @@ namespace Tango.MachineStudio.Common /// /// Represents a Machine Studio view model /// - /// The type of the module. /// /// - public abstract class StudioViewModelInternal : ViewModel, IStudioViewModel + public abstract class StudioViewModel : ViewModel, IStudioViewModel { - public bool IsVisible { get; private set; } - - /// - /// Gets or sets a value indicating whether this view model studio module is currently loaded. - /// - public bool IsModuleLoaded { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - public StudioViewModelInternal() : base() - { - - } - - /// - /// Called when another module has wants to navigate to this module with some arguments. - /// - /// The arguments. - public virtual void OnModuleRequest(params object[] args) - { - - } - + private bool _isVisible; /// - /// Called when the user has navigated out of the module. + /// Gets or sets a value indicating whether this view model view's is visible. /// - public virtual void OnNavigatedFrom() + public bool IsVisible { - IsVisible = false; - IsModuleLoaded = false; + get { return _isVisible; } + set { _isVisible = value; RaisePropertyChangedAuto(); } } /// - /// Called when the user has navigated in to the module. - /// - public virtual void OnNavigatedTo() - { - IsVisible = true; - IsModuleLoaded = true; - } - - /// - /// Called before the application is shutting down. - /// Return false to cancel the shutdown in case an important process is in progress. - /// - /// - public virtual Task OnShutdownRequest() - { - return Task.FromResult(true); - } - - /// - /// Called when application is shutting down. - /// - public virtual void OnShuttingDown() - { - - } - - /// - /// Called when the application has been started - /// - public virtual void OnApplicationStarted() - { - - } - - /// - /// Called when the application is ready and all modules are loaded. - /// - public virtual void OnApplicationReady() - { - - } - } - - /// - /// Represents a Machine Studio view model - /// - /// The type of the module. - /// - /// - public abstract class StudioViewModel : ViewModel, IStudioViewModel where Module : IStudioModule - { - public bool IsVisible { get; private set; } - - /// - /// Gets or sets a value indicating whether this view model studio module is currently loaded. - /// - public bool IsModuleLoaded { get; private set; } - - /// - /// Called when another module has wants to navigate to this module with some arguments. + /// Initializes a new instance of the class. /// - /// The arguments. - public virtual void OnModuleRequest(params object[] args) + public StudioViewModel() : base() { } /// - /// Called when the user has navigated out of the module. + /// Called when the user has navigated out of this view model. /// public virtual void OnNavigatedFrom() { IsVisible = false; - IsModuleLoaded = false; } /// - /// Called when the user has navigated in to the module. + /// Called when the user has navigated in to this view model. /// public virtual void OnNavigatedTo() { IsVisible = true; - IsModuleLoaded = true; } /// @@ -163,79 +78,38 @@ namespace Tango.MachineStudio.Common /// /// Called when the application is ready and all modules are loaded. /// - public virtual void OnApplicationReady() - { - - } + public abstract void OnApplicationReady(); } /// - /// Represents a Machine Studio view model. + /// Represents a Machine Studio view model with a support for a view contract. /// - /// The type of the module. - /// + /// /// - /// - public abstract class StudioViewModel : ViewModel, IStudioViewModel where Module : IStudioModule where T : IView + public abstract class StudioViewModel : StudioViewModel where TView : IView { /// - /// Called when the application has been started - /// - public virtual void OnApplicationStarted() - { - - } - - /// - /// Called when the application is ready and all modules are loaded. - /// - public virtual void OnApplicationReady() - { - - } - - /// - /// Called when another module has wants to navigate to this module with some arguments. + /// Gets the view model's view. /// - /// The arguments. - public virtual void OnModuleRequest(params object[] args) - { - - } + public TView View { get; private set; } /// - /// Called when the user has navigated out of the module. + /// Initializes a new instance of the class. /// - public virtual void OnNavigatedFrom() + public StudioViewModel() : base() { - + TangoIOC.Default.GetInstanceWhenAvailable((view) => + { + View = view; + OnViewAttached(view); + }); } /// - /// Called when the user has navigated in to the module. + /// Called when the view has been attached /// - public virtual void OnNavigatedTo() - { - - } - - /// - /// Called before the application is shutting down. - /// Return false to cancel the shutdown in case an important process is in progress. - /// - /// - public virtual Task OnShutdownRequest() - { - return Task.FromResult(true); - } - - /// - /// Called when application is shutting down. - /// - public virtual void OnShuttingDown() - { - - } + /// The view. + protected abstract void OnViewAttached(TView view); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 8b251074d..09678b515 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -106,6 +106,9 @@ + + + @@ -115,6 +118,7 @@ + @@ -292,13 +296,11 @@ True - - - + - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs new file mode 100644 index 000000000..1c960ed3a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Threading/IDispatcherProvider.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Threading +{ + /// + /// Represents a mechanism for invoking actions on the main application thread. + /// + public interface IDispatcherProvider + { + /// + /// Invokes the specified action asynchronously. + /// + /// The action. + void Invoke(Action action); + + /// + /// Invokes the specified action synchronously. + /// + /// The action. + void InvokeSync(Action action); + } +} -- cgit v1.3.1