From 076461e460a2b71109d2d3500b0124a2a21e5af3 Mon Sep 17 00:00:00 2001 From: Laszlo Nemeth <57342539+donlaci@users.noreply.github.com> Date: Thu, 5 Dec 2024 20:28:22 +0100 Subject: [PATCH] [Workspaces] Implement store of app window's size and position (#36086) * [Workspaces] Implement store of app window's size and position * Modifying the default values to -1. The program will use the original default values for the first run. --- .../Workspaces/WorkspacesEditor/App.config | 26 +++++++- .../WorkspacesEditor/MainWindow.xaml.cs | 53 +++++++++++++--- .../Properties/Settings.Designer.cs | 62 ++++++++++++++++++- .../Properties/Settings.settings | 24 +++++-- 4 files changed, 151 insertions(+), 14 deletions(-) diff --git a/src/modules/Workspaces/WorkspacesEditor/App.config b/src/modules/Workspaces/WorkspacesEditor/App.config index e31368d227..8ac4ff9266 100644 --- a/src/modules/Workspaces/WorkspacesEditor/App.config +++ b/src/modules/Workspaces/WorkspacesEditor/App.config @@ -1,9 +1,33 @@ + + +
+ + - + + + + + -1 + + + -1 + + + -1 + + + -1 + + + False + + + diff --git a/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs b/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs index a0a7f96a06..8f9944cc90 100644 --- a/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs +++ b/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs @@ -30,13 +30,28 @@ namespace WorkspacesEditor MainViewModel = mainViewModel; mainViewModel.SetMainWindow(this); - WindowInteropHelper windowInteropHelper = new WindowInteropHelper(this); - System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle); - double dpi = MonitorHelper.GetScreenDpiFromScreen(screen); - this.Height = screen.WorkingArea.Height / dpi * 0.90; - this.Width = screen.WorkingArea.Width / dpi * 0.75; - this.Top = screen.WorkingArea.Top + (int)(screen.WorkingArea.Height / dpi * 0.05); - this.Left = screen.WorkingArea.Left + (int)(screen.WorkingArea.Width / dpi * 0.125); + if (Properties.Settings.Default.Height == -1) + { + // This is the very first time the window is created. Place it on the screen center + WindowInteropHelper windowInteropHelper = new WindowInteropHelper(this); + System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle); + double dpi = MonitorHelper.GetScreenDpiFromScreen(screen); + this.Height = screen.WorkingArea.Height / dpi * 0.90; + this.Width = screen.WorkingArea.Width / dpi * 0.75; + this.Top = screen.WorkingArea.Top + (int)(screen.WorkingArea.Height / dpi * 0.05); + this.Left = screen.WorkingArea.Left + (int)(screen.WorkingArea.Width / dpi * 0.125); + SavePosition(); + } + + this.Top = Properties.Settings.Default.Top; + this.Left = Properties.Settings.Default.Left; + this.Height = Properties.Settings.Default.Height; + this.Width = Properties.Settings.Default.Width; + + if (Properties.Settings.Default.Maximized) + { + WindowState = WindowState.Maximized; + } InitializeComponent(); @@ -73,8 +88,32 @@ namespace WorkspacesEditor cancellationToken.Token); } + private void SavePosition() + { + if (WindowState == WindowState.Maximized) + { + // Use the RestoreBounds as the current values will be 0, 0 and the size of the screen + Properties.Settings.Default.Top = RestoreBounds.Top; + Properties.Settings.Default.Left = RestoreBounds.Left; + Properties.Settings.Default.Height = RestoreBounds.Height; + Properties.Settings.Default.Width = RestoreBounds.Width; + Properties.Settings.Default.Maximized = true; + } + else + { + Properties.Settings.Default.Top = this.Top; + Properties.Settings.Default.Left = this.Left; + Properties.Settings.Default.Height = this.Height; + Properties.Settings.Default.Width = this.Width; + Properties.Settings.Default.Maximized = false; + } + + Properties.Settings.Default.Save(); + } + private void OnClosing(object sender, EventArgs e) { + SavePosition(); cancellationToken.Dispose(); App.Current.Shutdown(); } diff --git a/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.Designer.cs b/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.Designer.cs index f598f04bae..2f5448b8b6 100644 --- a/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.Designer.cs +++ b/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace WorkspacesEditor.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -22,5 +22,65 @@ namespace WorkspacesEditor.Properties { return defaultInstance; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("-1")] + public double Top { + get { + return ((double)(this["Top"])); + } + set { + this["Top"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("-1")] + public double Left { + get { + return ((double)(this["Left"])); + } + set { + this["Left"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("-1")] + public double Height { + get { + return ((double)(this["Height"])); + } + set { + this["Height"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("-1")] + public double Width { + get { + return ((double)(this["Width"])); + } + set { + this["Width"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool Maximized { + get { + return ((bool)(this["Maximized"])); + } + set { + this["Maximized"] = value; + } + } } } diff --git a/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.settings b/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.settings index 033d7a5e9e..e7d2ac5f07 100644 --- a/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.settings +++ b/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.settings @@ -1,7 +1,21 @@  - - - - - + + + + + -1 + + + -1 + + + -1 + + + -1 + + + False + + \ No newline at end of file