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/StudioViewModel.cs | 180 ++++----------------- 1 file changed, 27 insertions(+), 153 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioViewModel.cs') 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); } } -- cgit v1.3.1