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.Dockable.cs b/src/Dock.Model/FactoryBase.Dockable.cs index 375db2165..c987ef63b 100644 --- a/src/Dock.Model/FactoryBase.Dockable.cs +++ b/src/Dock.Model/FactoryBase.Dockable.cs @@ -254,7 +254,7 @@ public virtual void SwapDockable(IDock sourceDock, IDock targetDock, IDockable s var originalTargetDockable = targetDock.VisibleDockables[targetIndex]; sourceDock.VisibleDockables[sourceIndex] = originalTargetDockable; targetDock.VisibleDockables[targetIndex] = originalSourceDockable; - + InitDockable(originalSourceDockable, targetDock); InitDockable(originalTargetDockable, sourceDock); @@ -371,7 +371,7 @@ public virtual void PinDockable(IDockable dockable) { return; } - + var isVisible = false; if (toolDock.VisibleDockables is not null) @@ -413,7 +413,7 @@ public virtual void PinDockable(IDockable dockable) break; } } - + if (toolDock.VisibleDockables is not null) { RemoveVisibleDockable(toolDock, dockable); @@ -531,8 +531,9 @@ public virtual void PinDockable(IDockable dockable) HidePreviewingDockables(rootDock); AddVisibleDockable(originalOwner, dockable); } + OnDockableAdded(dockable); - + // TODO: Handle ActiveDockable state. // TODO: Handle IsExpanded property of IToolDock. // TODO: Handle AutoHide property of IToolDock. @@ -604,7 +605,7 @@ public virtual void FloatDockable(IDockable dockable) /// public virtual void CloseDockable(IDockable dockable) { - if (dockable.OnClose()) + if (dockable.CanClose && dockable.OnClose()) { RemoveDockable(dockable, true); OnDockableClosed(dockable); @@ -662,7 +663,7 @@ public virtual void CloseLeftDockables(IDockable dockable) { return; } - + CloseDockablesRange(dock, 0, indexOf - 1); } @@ -679,7 +680,7 @@ public virtual void CloseRightDockables(IDockable dockable) { return; } - + CloseDockablesRange(dock, indexOf + 1, dock.VisibleDockables.Count - 1); } diff --git a/src/Dock.Model/FactoryBase.cs b/src/Dock.Model/FactoryBase.cs index 442495695..9b21cfd16 100644 --- a/src/Dock.Model/FactoryBase.cs +++ b/src/Dock.Model/FactoryBase.cs @@ -255,7 +255,6 @@ public virtual void SplitToDock(IDock dock, IDockable dockable, DockOperation op public virtual IDockWindow? CreateWindowFrom(IDockable dockable) { IDockable? target; - bool topmost; switch (dockable) { @@ -273,7 +272,6 @@ public virtual void SplitToDock(IDock dock, IDockable dockable, DockOperation op dock.ActiveDockable = dockable; } } - topmost = true; break; } case IDocument: @@ -305,37 +303,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: @@ -361,7 +353,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;