diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-23 09:45:01 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-23 09:45:01 +0300 |
| commit | 2c8da378c82e5181f0566a564de529ab7ef96f4f (patch) | |
| tree | d450472402b15fc30d8bd482da348826caf487c5 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common | |
| parent | 774da535e732ecd5a3737550ef1d35819a1e7fc6 (diff) | |
| download | Tango-2c8da378c82e5181f0566a564de529ab7ef96f4f.tar.gz Tango-2c8da378c82e5181f0566a564de529ab7ef96f4f.zip | |
Improvements to machine studio view models and navigation system.
Improvements to tech board selection and edit modes handling.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common')
9 files changed, 234 insertions, 183 deletions
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,25 +3,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static Tango.SharedUI.Controls.NavigationControl; namespace Tango.MachineStudio.Common { /// <summary> /// Represents a Machine Studio view model. /// </summary> - public interface IStudioViewModel + public interface IStudioViewModel : INavigationViewModel { /// <summary> - /// Called when the user has navigated in to the module. - /// </summary> - void OnNavigatedTo(); - - /// <summary> - /// Called when the user has navigated out of the module. - /// </summary> - void OnNavigatedFrom(); - - /// <summary> /// Called when application is shutting down. /// </summary> void OnShuttingDown(); @@ -34,12 +25,6 @@ namespace Tango.MachineStudio.Common Task<bool> OnShutdownRequest(); /// <summary> - /// Called when another module has wants to navigate to this module with some arguments. - /// </summary> - /// <param name="args">The arguments.</param> - void OnModuleRequest(params object[] args); - - /// <summary> /// Called when the application has been started /// </summary> void OnApplicationStarted(); 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 +{ + /// <summary> + /// Represents an object which can abort the navigation from it. + /// </summary> + public interface INavigationBlocker + { + /// <summary> + /// Called before the navigation system navigates from this object. + /// Return false to abort the navigation. + /// </summary> + /// <returns></returns> + Task<bool> OnNavigateOutRequest(); + + /// <summary> + /// Called before the navigation system navigates back from this object. + /// Return false to abort the navigation. + /// </summary> + /// <returns></returns> + Task<bool> 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 { /// <summary> - /// Navigates to the specified view. + /// Gets the current module. + /// </summary> + IStudioModule CurrentModule { get; } + + /// <summary> + /// Gets the current view model. + /// </summary> + StudioViewModel CurrentVM { get; } + + /// <summary> + /// Gets a value indicating whether the navigation system is able to navigate to the previous view. + /// </summary> + bool CanNavigateBack { get; } + + /// <summary> + /// Navigates to the previous view if <see cref="CanNavigateBack"/> is true. + /// </summary> + Task<bool> NavigateBack(); + + /// <summary> + /// Navigates to the previous view.. + /// </summary> + RelayCommand NavigateBackCommand { get; } + + /// <summary> + /// Navigates to the specified full path in command parameter. + /// </summary> + RelayCommand<String> NavigateToCommand { get; } + + /// <summary> + /// Navigates to the specified PPC view. /// </summary> /// <param name="view">The view.</param> - void NavigateTo(NavigationView view); + Task<bool> NavigateTo(NavigationView view, bool pushToHistory = true); + + /// <summary> + /// Navigates to the specified PPC view with the specified receive object. + /// </summary> + /// <param name="view">The view.</param> + Task<bool> NavigateWithObject<TPass>(NavigationView view, TPass obj, bool pushToHistory = true); + + /// <summary> + /// Navigates to the specified module. + /// </summary> + /// <typeparam name="T"></typeparam> + Task<bool> NavigateTo<T>(bool pushToHistory = true) where T : IStudioModule; + + /// <summary> + /// Navigates to the specified module using the view path (e.g MainView.JobsView). + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="viewPath">The view path.</param> + Task<bool> NavigateTo<T>(String viewPath, bool pushToHistory = true) where T : IStudioModule; + + /// <summary> + /// 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)); + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="viewPath">The view path.</param> + Task<bool> NavigateTo<T>(bool pushToHistory = true, params String[] viewPath) where T : IStudioModule; + + /// <summary> + /// Navigates to the specified module and view by full path (e.g Jobs.JobsView). + /// </summary> + /// <param name="fullPath">The full path.</param> + Task<bool> NavigateTo(String fullPath, bool pushToHistory = true); + + /// <summary> + /// Navigates to the specified module and view with the specified object and expecting a return parameter. + /// The view must be of type INavigationResultProvider<TResult>. + /// </summary> + /// <param name="fullPath">The full path.</param> + Task<TResult> NavigateForResult<TModule, TView, TResult, TPass>(TPass obj, bool pushToHistory = true) + where TModule : IStudioModule; + + /// <summary> + /// Navigates to the specified module and view with the specified object. + /// </summary> + /// <typeparam name="TModule">The type of the module.</typeparam> + /// <typeparam name="TView">The type of the view.</typeparam> + /// <typeparam name="TPass">The type of the pass.</typeparam> + /// <param name="obj">The object.</param> + /// <param name="pushToHistory">if set to <c>true</c> [push to history].</param> + /// <returns></returns> + Task<bool> NavigateWithObject<TModule, TView, TPass>(TPass obj, bool pushToHistory = true) + where TModule : IStudioModule; + + /// <summary> + /// Clears the navigation back history. + /// </summary> + void ClearHistory(); + + /// <summary> + /// Clears the navigation back history except the specified view type. + /// </summary> + void ClearHistoryExcept<T>(); } } 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 +{ + /// <summary> + /// Represents an object which supports receiving an object as part of the navigation to it. + /// </summary> + /// <typeparam name="T"></typeparam> + public interface INavigationObjectReceiver<T> + { + /// <summary> + /// Called when navigation system is going to navigate to this instance with the specified object. + /// </summary> + /// <param name="obj">The object.</param> + 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 +{ + /// <summary> + /// Represents a object which provides a result the navigation system navigates away from it. + /// </summary> + /// <typeparam name="TResult">The type of the result.</typeparam> + /// <typeparam name="TPass">The type of the pass.</typeparam> + public interface INavigationResultProvider<TResult, TPass> + { + /// <summary> + /// Called when the navigation system requests a result when it is navigating away from this instance. + /// </summary> + /// <returns></returns> + TResult GetNavigationResult(); + + /// <summary> + /// Called when navigation system is going to navigate to this instance with the specified object. + /// </summary> + /// <param name="obj">The object.</param> + 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 @@ -45,13 +45,6 @@ namespace Tango.MachineStudio.Common.StudioApplication bool IsMachineConnectedViaTCP { get; } /// <summary> - /// Loads the specified module if permitted. - /// </summary> - /// <param name="moduleName">Name of the module.</param> - /// <param name="args">The arguments.</param> - void RequestModule(String moduleName, params object[] args); - - /// <summary> /// Gets the machine studio application version. /// </summary> Version Version { get; } 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 /// <summary> /// Represents a Machine Studio view model /// </summary> - /// <typeparam name="Module">The type of the module.</typeparam> /// <seealso cref="Tango.SharedUI.ViewModel" /> /// <seealso cref="Tango.MachineStudio.Common.IStudioViewModel" /> - public abstract class StudioViewModelInternal : ViewModel, IStudioViewModel + public abstract class StudioViewModel : ViewModel, IStudioViewModel { - public bool IsVisible { get; private set; } - - /// <summary> - /// Gets or sets a value indicating whether this view model studio module is currently loaded. - /// </summary> - public bool IsModuleLoaded { get; private set; } - - /// <summary> - /// Initializes a new instance of the <see cref="StudioViewModel{Module}"/> class. - /// </summary> - public StudioViewModelInternal() : base() - { - - } - - /// <summary> - /// Called when another module has wants to navigate to this module with some arguments. - /// </summary> - /// <param name="args">The arguments.</param> - public virtual void OnModuleRequest(params object[] args) - { - - } - + private bool _isVisible; /// <summary> - /// Called when the user has navigated out of the module. + /// Gets or sets a value indicating whether this view model view's is visible. /// </summary> - public virtual void OnNavigatedFrom() + public bool IsVisible { - IsVisible = false; - IsModuleLoaded = false; + get { return _isVisible; } + set { _isVisible = value; RaisePropertyChangedAuto(); } } /// <summary> - /// Called when the user has navigated in to the module. - /// </summary> - public virtual void OnNavigatedTo() - { - IsVisible = true; - IsModuleLoaded = true; - } - - /// <summary> - /// Called before the application is shutting down. - /// Return false to cancel the shutdown in case an important process is in progress. - /// </summary> - /// <returns></returns> - public virtual Task<bool> OnShutdownRequest() - { - return Task.FromResult(true); - } - - /// <summary> - /// Called when application is shutting down. - /// </summary> - public virtual void OnShuttingDown() - { - - } - - /// <summary> - /// Called when the application has been started - /// </summary> - public virtual void OnApplicationStarted() - { - - } - - /// <summary> - /// Called when the application is ready and all modules are loaded. - /// </summary> - public virtual void OnApplicationReady() - { - - } - } - - /// <summary> - /// Represents a Machine Studio view model - /// </summary> - /// <typeparam name="Module">The type of the module.</typeparam> - /// <seealso cref="Tango.SharedUI.ViewModel" /> - /// <seealso cref="Tango.MachineStudio.Common.IStudioViewModel" /> - public abstract class StudioViewModel<Module> : ViewModel, IStudioViewModel where Module : IStudioModule - { - public bool IsVisible { get; private set; } - - /// <summary> - /// Gets or sets a value indicating whether this view model studio module is currently loaded. - /// </summary> - public bool IsModuleLoaded { get; private set; } - - /// <summary> - /// Called when another module has wants to navigate to this module with some arguments. + /// Initializes a new instance of the <see cref="StudioViewModel{Module}"/> class. /// </summary> - /// <param name="args">The arguments.</param> - public virtual void OnModuleRequest(params object[] args) + public StudioViewModel() : base() { } /// <summary> - /// Called when the user has navigated out of the module. + /// Called when the user has navigated out of this view model. /// </summary> public virtual void OnNavigatedFrom() { IsVisible = false; - IsModuleLoaded = false; } /// <summary> - /// Called when the user has navigated in to the module. + /// Called when the user has navigated in to this view model. /// </summary> public virtual void OnNavigatedTo() { IsVisible = true; - IsModuleLoaded = true; } /// <summary> @@ -163,79 +78,38 @@ namespace Tango.MachineStudio.Common /// <summary> /// Called when the application is ready and all modules are loaded. /// </summary> - public virtual void OnApplicationReady() - { - - } + public abstract void OnApplicationReady(); } /// <summary> - /// Represents a Machine Studio view model. + /// Represents a Machine Studio view model with a support for a view contract. /// </summary> - /// <typeparam name="Module">The type of the module.</typeparam> - /// <typeparam name="T"></typeparam> + /// <typeparam name="TView"></typeparam> /// <seealso cref="Tango.SharedUI.ViewModel" /> - /// <seealso cref="Tango.MachineStudio.Common.IStudioViewModel" /> - public abstract class StudioViewModel<Module, T> : ViewModel<T>, IStudioViewModel where Module : IStudioModule where T : IView + public abstract class StudioViewModel<TView> : StudioViewModel where TView : IView { /// <summary> - /// Called when the application has been started - /// </summary> - public virtual void OnApplicationStarted() - { - - } - - /// <summary> - /// Called when the application is ready and all modules are loaded. - /// </summary> - public virtual void OnApplicationReady() - { - - } - - /// <summary> - /// Called when another module has wants to navigate to this module with some arguments. + /// Gets the view model's view. /// </summary> - /// <param name="args">The arguments.</param> - public virtual void OnModuleRequest(params object[] args) - { - - } + public TView View { get; private set; } /// <summary> - /// Called when the user has navigated out of the module. + /// Initializes a new instance of the <see cref="StudioViewModel{TView}"/> class. /// </summary> - public virtual void OnNavigatedFrom() + public StudioViewModel() : base() { - + TangoIOC.Default.GetInstanceWhenAvailable<TView>((view) => + { + View = view; + OnViewAttached(view); + }); } /// <summary> - /// Called when the user has navigated in to the module. + /// Called when the view has been attached /// </summary> - public virtual void OnNavigatedTo() - { - - } - - /// <summary> - /// Called before the application is shutting down. - /// Return false to cancel the shutdown in case an important process is in progress. - /// </summary> - /// <returns></returns> - public virtual Task<bool> OnShutdownRequest() - { - return Task.FromResult(true); - } - - /// <summary> - /// Called when application is shutting down. - /// </summary> - public virtual void OnShuttingDown() - { - - } + /// <param name="view">The view.</param> + 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 @@ <Compile Include="IStudioViewModel.cs" /> <Compile Include="MachineStudioSettings.cs" /> <Compile Include="Messages\MachineConnectionChangedMessage.cs" /> + <Compile Include="Navigation\INavigationBlocker.cs" /> + <Compile Include="Navigation\INavigationObjectReceiver.cs" /> + <Compile Include="Navigation\INavigationResultProvider.cs" /> <Compile Include="Notifications\BarItem.cs" /> <Compile Include="Speech\DefaultSpeechProvider.cs" /> <Compile Include="Speech\ISpeechProvider.cs" /> @@ -115,6 +118,7 @@ <Compile Include="StudioModuleAttribute.cs" /> <Compile Include="StudioModuleBase.cs" /> <Compile Include="StudioViewModel.cs" /> + <Compile Include="Threading\IDispatcherProvider.cs" /> <Compile Include="Update\CheckForUpdatesResponse.cs" /> <Compile Include="Update\CheckForUpdatesRequest.cs" /> <Compile Include="Update\IMachineStudioUpdateService.cs" /> @@ -292,13 +296,11 @@ <EmbedInteropTypes>True</EmbedInteropTypes> </COMReference> </ItemGroup> - <ItemGroup> - <Folder Include="MarkupExtensions\" /> - </ItemGroup> + <ItemGroup /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ 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 +{ + /// <summary> + /// Represents a mechanism for invoking actions on the main application thread. + /// </summary> + public interface IDispatcherProvider + { + /// <summary> + /// Invokes the specified action asynchronously. + /// </summary> + /// <param name="action">The action.</param> + void Invoke(Action action); + + /// <summary> + /// Invokes the specified action synchronously. + /// </summary> + /// <param name="action">The action.</param> + void InvokeSync(Action action); + } +} |
