From 28de564b35207886d181e4a3870f70c3bde04c3d Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 17 Sep 2018 16:06:27 +0300 Subject: Implemented keep modules windows states and bounds after restart. --- .../ViewModels/LoadingViewVM.cs | 2 +- .../ViewModels/MainViewVM.cs | 33 ++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs index 215f7afb5..4032c946c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -149,7 +149,7 @@ namespace Tango.MachineStudio.UI.ViewModels InvokeUI(() => { - _studioModuleLoader.LoadModules(); + //_studioModuleLoader.LoadModules(); _navigationManager.NavigateTo(NavigationView.LoginView); IsLoading = false; }); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 31b2181ea..cbd58134d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -47,7 +47,7 @@ namespace Tango.MachineStudio.UI.ViewModels /// Represents the Machine Studio main view, view model. /// /// - public class MainViewVM : ViewModel + public class MainViewVM : StudioViewModel { private IStudioModule _currentModule; private INavigationManager _navigation; @@ -296,7 +296,7 @@ namespace Tango.MachineStudio.UI.ViewModels ConnectCommand = new RelayCommand(ConnectToMachine); SignoutCommand = new RelayCommand(SignOut); DisconnectCommand = new RelayCommand(DisconnectFromMachine, (x) => ApplicationManager.IsMachineConnected && !_isDisconnecting); - OpenModuleInWindowCommand = new RelayCommand(OpenModuleInWindow); + OpenModuleInWindowCommand = new RelayCommand((x) => { OpenModuleInWindow(x); }); ExitCommand = new RelayCommand(ExitApplication); UpdateCenterCommand = new RelayCommand(NavigateToUpdateCenter); @@ -671,7 +671,7 @@ namespace Tango.MachineStudio.UI.ViewModels /// Opens the module in a new window. /// /// The module. - private void OpenModuleInWindow(IStudioModule module) + private void OpenModuleInWindow(IStudioModule module, Rect? bounds = null, WindowState? state = null) { if (module == null) return; @@ -697,6 +697,20 @@ namespace Tango.MachineStudio.UI.ViewModels ModuleWindowVM vm = new ModuleWindowVM(module); ModuleWindow window = new ModuleWindow(this, vm, view); + if (bounds.HasValue) + { + window.WindowStartupLocation = WindowStartupLocation.Manual; + window.WindowState = WindowState.Normal; + window.Left = bounds.Value.Left; + window.Top = bounds.Value.Top; + window.Width = bounds.Value.Width; + window.Height = bounds.Value.Height; + window.Loaded += (_, __) => + { + window.WindowState = state.Value; + }; + } + window.Closing += (x, y) => { LogManager.Log(String.Format("Closing module '{0}' on new window...", module.Name)); @@ -847,5 +861,18 @@ namespace Tango.MachineStudio.UI.ViewModels console.Owner = MainWindow.Instance; console.Show(); } + + public override void OnApplicationReady() + { + foreach (var item in SettingsManager.Default.GetOrCreate().StudioModulesBounds) + { + var module = StudioModuleLoader.AllModules.SingleOrDefault(x => x.Name == item.Name); + + if (module != null && !module.InNewWindow) + { + OpenModuleInWindow(module, item.Bounds, item.State); + } + } + } } } -- cgit v1.3.1