From 1230d8a3920da8f2050c39e8ffc3b3f9c5a2f2b2 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 28 Jan 2011 00:18:52 +0100 Subject: [PATCH] WpfWorkbench: Fixed window bound restore code - When closing a minimized SharpDevelop instance, save the previous state (before minimizing) - Use RestoreBounds so that window size is saved even when maximized - Validate the bounds being restored (avoid placing SharpDevelop on deactivated monitor) --- .../Project/Src/Gui/FormLocationHelper.cs | 2 +- .../Project/Src/Gui/Workbench/WpfWorkbench.cs | 33 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/FormLocationHelper.cs b/src/Main/Base/Project/Src/Gui/FormLocationHelper.cs index 5c6a674059..5a9c42e917 100644 --- a/src/Main/Base/Project/Src/Gui/FormLocationHelper.cs +++ b/src/Main/Base/Project/Src/Gui/FormLocationHelper.cs @@ -60,7 +60,7 @@ namespace ICSharpCode.SharpDevelop.Gui }; } - static Rect Validate(Rect bounds) + public static Rect Validate(Rect bounds) { // Check if form is outside the screen and get it back if necessary. // This is important when the user uses multiple screens, a window stores its location diff --git a/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs b/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs index 4546d46340..18197d439c 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/WpfWorkbench.cs @@ -529,25 +529,36 @@ namespace ICSharpCode.SharpDevelop.Gui } #endregion + System.Windows.WindowState lastNonMinimizedWindowState = System.Windows.WindowState.Normal; + Rect restoreBoundsBeforeClosing; + + protected override void OnStateChanged(EventArgs e) + { + base.OnStateChanged(e); + if (this.WindowState != System.Windows.WindowState.Minimized) + lastNonMinimizedWindowState = this.WindowState; + } + public Properties CreateMemento() { Properties prop = new Properties(); - prop.Set("WindowState", this.WindowState); - if (this.WindowState == System.Windows.WindowState.Normal) { - prop.Set("Left", this.Left); - prop.Set("Top", this.Top); - prop.Set("Width", this.Width); - prop.Set("Height", this.Height); + prop.Set("WindowState", lastNonMinimizedWindowState); + var bounds = this.RestoreBounds; + if (bounds.IsEmpty) bounds = restoreBoundsBeforeClosing; + if (!bounds.IsEmpty) { + prop.Set("Bounds", bounds); } return prop; } public void SetMemento(Properties memento) { - this.Left = memento.Get("Left", 10.0); - this.Top = memento.Get("Top", 10.0); - this.Width = memento.Get("Width", 600.0); - this.Height = memento.Get("Height", 400.0); + Rect bounds = memento.Get("Bounds", new Rect(10, 10, 750, 550)); + bounds = FormLocationHelper.Validate(bounds); + this.Left = bounds.Left; + this.Top = bounds.Top; + this.Width = bounds.Width; + this.Height = bounds.Height; this.WindowState = memento.Get("WindowState", System.Windows.WindowState.Maximized); } @@ -574,6 +585,8 @@ namespace ICSharpCode.SharpDevelop.Gui Project.ProjectService.CloseSolution(); ParserService.StopParserThread(); + restoreBoundsBeforeClosing = this.RestoreBounds; + this.WorkbenchLayout = null; foreach (PadDescriptor padDescriptor in this.PadContentCollection) {