diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs index 68ee5c9..3563475 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs @@ -3,6 +3,9 @@ using Microsoft.UI.Xaml.Controls; namespace Ghost.Editor.View.Controls.Docking; +/// +/// Represents a document module in the docking system. +/// public partial class DockDocument : DockModule { public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( @@ -29,6 +32,9 @@ public partial class DockDocument : DockModule set => SetValue(ContentProperty, value); } + /// + /// Initializes a new instance of the class. + /// public DockDocument() { DefaultStyleKey = typeof(DockDocument); diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs index 1ba83d6..f049edf 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs @@ -95,22 +95,28 @@ public class DockingLayout : Control throw new ArgumentException("targetGroup does not belong to this DockingLayout", nameof(targetGroup)); } - if (RootModule == null) - { - RootModule = new DockPanel(); - } - if (targetGroup == null) { - targetGroup = FindFirstDockGroup(RootModule as DockContainer); - - if (targetGroup == null) + if (RootModule != null) + { + targetGroup = FindFirstDockGroup(RootModule as DockContainer); + if (targetGroup == null) + { + // Root is not a container, or contains no groups. Wrap it. + var newGroup = new DockGroup(); + if (RootModule is DockDocument existingDoc) + { + RootModule = null; // Detach first + newGroup.AddChild(existingDoc); + } + RootModule = newGroup; + targetGroup = newGroup; + } + } + else { targetGroup = new DockGroup(); - if (RootModule is DockContainer container) - { - container.AddChild(targetGroup); - } + RootModule = targetGroup; } } @@ -191,8 +197,10 @@ public class DockingLayout : Control } } - private static DockGroup? FindFirstDockGroup(DockContainer container) + private static DockGroup? FindFirstDockGroup(DockContainer? container) { + if (container == null) return null; + if (container is DockGroup group) { return group;