From 35731d4ebec690d343f68e347d6b244a597a39c3 Mon Sep 17 00:00:00 2001 From: Misaki Date: Sat, 28 Mar 2026 22:39:57 +0900 Subject: [PATCH] fix(docking): address code quality issues and improve structural integrity --- .../View/Controls/Docking/DockContainer.cs | 23 ++++++++++++++++--- .../View/Controls/Docking/DockPanel.cs | 6 +++-- .../View/Controls/Docking/DockingLayout.cs | 1 + 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs index 4a63c8e..792bff7 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs @@ -9,7 +9,7 @@ namespace Ghost.Editor.View.Controls.Docking; public abstract class DockContainer : DockModule { private readonly ObservableCollection _children = new(); - protected bool _isCleaningUp; + private bool _isCleaningUp; /// /// Gets the collection of child modules. /// @@ -50,7 +50,15 @@ public abstract class DockContainer : DockModule if (_children.Contains(module)) return; - module.Owner?.RemoveChildInternal(module, false); + if (module.Owner == this) + { + RemoveChildInternal(module, false); + } + else + { + module.Owner?.RemoveChild(module); + } + module.Owner = this; module.Root = Root; _children.Insert(index, module); @@ -90,11 +98,20 @@ public abstract class DockContainer : DockModule ArgumentNullException.ThrowIfNull(oldChild); ValidateChild(newChild); + if (oldChild == newChild) return; + int index = _children.IndexOf(oldChild); if (index < 0) throw new ArgumentException("oldChild not found"); // Detach newChild from its current owner if any - newChild.Owner?.RemoveChildInternal(newChild, false); + if (newChild.Owner == this) + { + newChild.Owner.RemoveChildInternal(newChild, false); + } + else + { + newChild.Owner?.RemoveChild(newChild); + } // Remove oldChild without triggering cleanup _isCleaningUp = true; diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockPanel.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockPanel.cs index a3a1503..6b21b62 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockPanel.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockPanel.cs @@ -61,8 +61,10 @@ public class DockPanel : DockContainer } else if (Root != null && Root.RootPanel == this) { - // If this is the root panel, we can't easily replace it if the child is a DockGroup, - // because RootPanel must be a DockPanel. So we just leave it. + if (child is DockPanel childPanel) + { + Root.RootPanel = childPanel; + } } } } diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs index db2d82a..0dcd5b4 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs @@ -235,6 +235,7 @@ public class DockingLayout : Control } else { + if (doc.Owner == targetGroup && targetGroup.Children.Count == 1) return; SplitGroup(targetGroup, doc, target); } }