From bed559d9dde75e282dcb0245233dbc3f65b6f2b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Korczy=C5=84ski?= Date: Sun, 10 Mar 2024 21:29:52 +0000 Subject: [PATCH] Correctly set host window's parent --- src/Dock.Avalonia/Controls/HostWindow.axaml | 4 +++- src/Dock.Avalonia/Controls/HostWindow.axaml.cs | 18 +++++++++++------- src/Dock.Model/Adapters/HostAdapter.cs | 1 - src/Dock.Model/Core/IHostWindow.cs | 6 ------ src/Dock.Model/FactoryBase.cs | 9 --------- 5 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/Dock.Avalonia/Controls/HostWindow.axaml b/src/Dock.Avalonia/Controls/HostWindow.axaml index c9ca9cc00..d64af0d17 100644 --- a/src/Dock.Avalonia/Controls/HostWindow.axaml +++ b/src/Dock.Avalonia/Controls/HostWindow.axaml @@ -1,6 +1,7 @@  + xmlns:core="using:Dock.Model.Core" + xmlns:controls="clr-namespace:Dock.Model.Controls;assembly=Dock.Model"> @@ -14,6 +15,7 @@ + diff --git a/src/Dock.Avalonia/Controls/HostWindow.axaml.cs b/src/Dock.Avalonia/Controls/HostWindow.axaml.cs index 5957bcd68..633ca2b7c 100644 --- a/src/Dock.Avalonia/Controls/HostWindow.axaml.cs +++ b/src/Dock.Avalonia/Controls/HostWindow.axaml.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Runtime.InteropServices; using Avalonia; using Avalonia.Controls; @@ -6,6 +7,7 @@ using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Styling; +using Avalonia.VisualTree; using Dock.Avalonia.Internal; using Dock.Model; using Dock.Model.Core; @@ -276,7 +278,15 @@ public void Present(bool isDialog) Window.Factory?.OnWindowOpened(Window); } - Show(); + var ownerDockControl = Window?.Layout?.Factory?.DockControls.FirstOrDefault(); + if (ownerDockControl is Control control && control.GetVisualRoot() is Window parentWindow) + { + Show(parentWindow); + } + else + { + Show(); + } } } } @@ -334,12 +344,6 @@ public void GetSize(out double width, out double height) height = Height; } - /// - public void SetTopmost(bool topmost) - { - Topmost = topmost; - } - /// public void SetTitle(string title) { diff --git a/src/Dock.Model/Adapters/HostAdapter.cs b/src/Dock.Model/Adapters/HostAdapter.cs index 7cdee8287..3baf45227 100644 --- a/src/Dock.Model/Adapters/HostAdapter.cs +++ b/src/Dock.Model/Adapters/HostAdapter.cs @@ -56,7 +56,6 @@ public void Present(bool isDialog) _window.Host.Present(isDialog); _window.Host.SetPosition(_window.X, _window.Y); _window.Host.SetSize(_window.Width, _window.Height); - _window.Host.SetTopmost(_window.Topmost); _window.Host.SetTitle(_window.Title); _window.Host.SetLayout(_window.Layout); _window.Host.IsTracked = true; diff --git a/src/Dock.Model/Core/IHostWindow.cs b/src/Dock.Model/Core/IHostWindow.cs index ffaff405f..eef221c7d 100644 --- a/src/Dock.Model/Core/IHostWindow.cs +++ b/src/Dock.Model/Core/IHostWindow.cs @@ -64,12 +64,6 @@ public interface IHostWindow /// The host height. void GetSize(out double width, out double height); - /// - /// Sets host topmost. - /// - /// The host topmost. - void SetTopmost(bool topmost); - /// /// Sets host title. /// diff --git a/src/Dock.Model/FactoryBase.cs b/src/Dock.Model/FactoryBase.cs index 15fc26aa0..6e71f309f 100644 --- a/src/Dock.Model/FactoryBase.cs +++ b/src/Dock.Model/FactoryBase.cs @@ -263,7 +263,6 @@ public virtual void SplitToDock(IDock dock, IDockable dockable, DockOperation op public virtual IDockWindow? CreateWindowFrom(IDockable dockable) { IDockable? target; - bool topmost; switch (dockable) { @@ -282,7 +281,6 @@ public virtual void SplitToDock(IDock dock, IDockable dockable, DockOperation op dock.ActiveDockable = dockable; } } - topmost = true; break; } case IDocument: @@ -315,37 +313,31 @@ public virtual void SplitToDock(IDock dock, IDockable dockable, DockOperation op dock.ActiveDockable = dockable; } } - topmost = false; break; } case IToolDock: { target = dockable; - topmost = true; break; } case IDocumentDock: { target = dockable; - topmost = false; break; } case IProportionalDock proportionalDock: { target = proportionalDock; - topmost = false; break; } case IDockDock dockDock: { target = dockDock; - topmost = false; break; } case IRootDock rootDock: { target = rootDock.ActiveDockable; - topmost = false; break; } default: @@ -372,7 +364,6 @@ public virtual void SplitToDock(IDock dock, IDockable dockable, DockOperation op window.Title = ""; window.Width = double.NaN; window.Height = double.NaN; - window.Topmost = topmost; window.Layout = root; root.Window = window;