From 5a252208b6ffaccf56e5fee16feaa816cb9a5c5b Mon Sep 17 00:00:00 2001 From: peterforstmeier Date: Sun, 20 Mar 2011 19:48:40 +0100 Subject: [PATCH] Patch from http://community.sharpdevelop.net/forums/t/12899.aspx --- .../Project/Src/Gui/FormLocationHelper.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Main/Base/Project/Src/Gui/FormLocationHelper.cs b/src/Main/Base/Project/Src/Gui/FormLocationHelper.cs index 5a9c42e917..38ae1e962e 100644 --- a/src/Main/Base/Project/Src/Gui/FormLocationHelper.cs +++ b/src/Main/Base/Project/Src/Gui/FormLocationHelper.cs @@ -34,6 +34,42 @@ namespace ICSharpCode.SharpDevelop.Gui }; } + public static void ApplyWindow(Window window, string propertyName, bool isResizable) + { + window.WindowStartupLocation = WindowStartupLocation.Manual; + Window owner = window.Owner ?? WorkbenchSingleton.MainWindow; + Point ownerPos = (owner == null ? new Point(0, 0) : new Point(owner.Left, owner.Top)); + if (isResizable) { + Rect bounds = PropertyService.Get(propertyName, GetDefaultBounds(window)); + bounds.Offset(ownerPos.X, ownerPos.Y); + bounds = Validate(bounds); + window.Left = bounds.X; + window.Top = bounds.Y; + window.Width = bounds.Width; + window.Height = bounds.Height; + } else { + Size size = new Size(window.ActualWidth, window.ActualHeight); + Point location = PropertyService.Get(propertyName, GetDefaultLocation(window)); + location.Offset(ownerPos.X, ownerPos.Y); + location = Validate(location, size); + window.Left = location.X; + window.Top = location.Y; + } + window.Closing += delegate { + owner = window.Owner ?? WorkbenchSingleton.MainWindow; + ownerPos = (owner == null ? new Point(0, 0) : new Point(owner.Left, owner.Top)); + if (isResizable) { + if (window.WindowState == System.Windows.WindowState.Normal) { + PropertyService.Set(propertyName, new Rect(window.Left, window.Top, window.ActualWidth, window.ActualHeight)); + } + } else { + PropertyService.Set(propertyName, new Point(window.Left - ownerPos.X, window.Top - ownerPos.Y)); + + } + }; + } + + /* public static void ApplyWindow(Window window, string propertyName, bool isResizable) { window.WindowStartupLocation = WindowStartupLocation.Manual; @@ -59,6 +95,7 @@ namespace ICSharpCode.SharpDevelop.Gui } }; } + */ public static Rect Validate(Rect bounds) {