From f3f0c27d807e369b167c4d37021d2a70496d6abb Mon Sep 17 00:00:00 2001 From: donlaci Date: Mon, 25 Nov 2024 09:02:05 +0100 Subject: [PATCH 1/2] [Workspaces] Implement store of app window's size and position --- .../Workspaces/WorkspacesEditor/App.config | 26 +++++++- .../WorkspacesEditor/MainWindow.xaml.cs | 35 ++++++++--- .../Properties/Settings.Designer.cs | 62 ++++++++++++++++++- .../Properties/Settings.settings | 24 +++++-- 4 files changed, 133 insertions(+), 14 deletions(-) diff --git a/src/modules/Workspaces/WorkspacesEditor/App.config b/src/modules/Workspaces/WorkspacesEditor/App.config index e31368d2271b..c1bd6abfee45 100644 --- a/src/modules/Workspaces/WorkspacesEditor/App.config +++ b/src/modules/Workspaces/WorkspacesEditor/App.config @@ -1,9 +1,33 @@ + + +
+ + - + + + + + 0 + + + 0 + + + 800 + + + 1200 + + + False + + + diff --git a/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs b/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs index a0a7f96a069f..c2b890cbc0fb 100644 --- a/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs +++ b/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs @@ -30,13 +30,15 @@ public MainWindow(MainViewModel mainViewModel) 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); + 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(); @@ -75,6 +77,25 @@ public MainWindow(MainViewModel mainViewModel) private void OnClosing(object sender, EventArgs e) { + 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(); 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 f598f04baeaa..19da8f05d8f6 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 @@ public static Settings Default { return defaultInstance; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public double Top { + get { + return ((double)(this["Top"])); + } + set { + this["Top"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public double Left { + get { + return ((double)(this["Left"])); + } + set { + this["Left"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("800")] + public double Height { + get { + return ((double)(this["Height"])); + } + set { + this["Height"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("1200")] + 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 033d7a5e9e22..62f513844f7d 100644 --- a/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.settings +++ b/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.settings @@ -1,7 +1,21 @@  - - - - - + + + + + 0 + + + 0 + + + 800 + + + 1200 + + + False + + \ No newline at end of file From 5cc7e3faf91ebac613b7cb62d9279eca074ec3ec Mon Sep 17 00:00:00 2001 From: donlaci Date: Wed, 27 Nov 2024 15:59:37 +0100 Subject: [PATCH 2/2] Modifying the default values to -1. The program will use the original default values for the first run. --- .../Workspaces/WorkspacesEditor/App.config | 8 ++++---- .../WorkspacesEditor/MainWindow.xaml.cs | 20 ++++++++++++++++++- .../Properties/Settings.Designer.cs | 8 ++++---- .../Properties/Settings.settings | 8 ++++---- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/modules/Workspaces/WorkspacesEditor/App.config b/src/modules/Workspaces/WorkspacesEditor/App.config index c1bd6abfee45..8ac4ff926602 100644 --- a/src/modules/Workspaces/WorkspacesEditor/App.config +++ b/src/modules/Workspaces/WorkspacesEditor/App.config @@ -14,16 +14,16 @@ - 0 + -1 - 0 + -1 - 800 + -1 - 1200 + -1 False diff --git a/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs b/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs index c2b890cbc0fb..8f9944cc9034 100644 --- a/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs +++ b/src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs @@ -30,6 +30,19 @@ public MainWindow(MainViewModel mainViewModel) MainViewModel = mainViewModel; mainViewModel.SetMainWindow(this); + 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; @@ -75,7 +88,7 @@ public MainWindow(MainViewModel mainViewModel) cancellationToken.Token); } - private void OnClosing(object sender, EventArgs e) + private void SavePosition() { if (WindowState == WindowState.Maximized) { @@ -96,6 +109,11 @@ private void OnClosing(object sender, EventArgs e) } 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 19da8f05d8f6..2f5448b8b645 100644 --- a/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.Designer.cs +++ b/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.Designer.cs @@ -25,7 +25,7 @@ public static Settings Default { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0")] + [global::System.Configuration.DefaultSettingValueAttribute("-1")] public double Top { get { return ((double)(this["Top"])); @@ -37,7 +37,7 @@ public double Top { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0")] + [global::System.Configuration.DefaultSettingValueAttribute("-1")] public double Left { get { return ((double)(this["Left"])); @@ -49,7 +49,7 @@ public double Left { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("800")] + [global::System.Configuration.DefaultSettingValueAttribute("-1")] public double Height { get { return ((double)(this["Height"])); @@ -61,7 +61,7 @@ public double Height { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("1200")] + [global::System.Configuration.DefaultSettingValueAttribute("-1")] public double Width { get { return ((double)(this["Width"])); diff --git a/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.settings b/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.settings index 62f513844f7d..e7d2ac5f07a7 100644 --- a/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.settings +++ b/src/modules/Workspaces/WorkspacesEditor/Properties/Settings.settings @@ -3,16 +3,16 @@ - 0 + -1 - 0 + -1 - 800 + -1 - 1200 + -1 False