From d367cff79fd48847bc08f7e49d6445d4f328f56f Mon Sep 17 00:00:00 2001 From: Misaki Date: Sat, 28 Mar 2026 22:42:07 +0900 Subject: [PATCH] fix(docking): address code quality issues and improve structural integrity --- .../Ghost.Editor/View/Controls/Docking/DockContainer.cs | 5 ++++- src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs | 7 ++++--- .../Ghost.Editor/View/Controls/Docking/DockingLayout.cs | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs index 792bff7..a5d0b1f 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockContainer.cs @@ -38,6 +38,9 @@ public abstract class DockContainer : DockModule /// /// Inserts a child module at the specified index. /// + /// + /// This method does not support reordering existing children within the same container. + /// /// The zero-based index at which the module should be inserted. /// The module to insert. public virtual void InsertChild(int index, DockModule module) @@ -101,7 +104,7 @@ public abstract class DockContainer : DockModule if (oldChild == newChild) return; int index = _children.IndexOf(oldChild); - if (index < 0) throw new ArgumentException("oldChild not found"); + if (index < 0) throw new ArgumentException("oldChild not found in this container", nameof(oldChild)); // Detach newChild from its current owner if any if (newChild.Owner == this) diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs index bc0f2f6..5e693ea 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs @@ -11,6 +11,7 @@ namespace Ghost.Editor.View.Controls.Docking; public partial class DockGroup : DockContainer { private const string PART_TAB_VIEW = "PART_TabView"; + private const string DRAG_DOCUMENT_KEY = "DockDocument"; private TabView? _tabView; public DockGroup() @@ -59,7 +60,7 @@ public partial class DockGroup : DockContainer { if (args.Tab.Tag is DockDocument doc) { - args.Data.Properties.Add("DockDocument", doc); + args.Data.Properties.Add(DRAG_DOCUMENT_KEY, doc); } } @@ -73,7 +74,7 @@ public partial class DockGroup : DockContainer private void OnDragOver(object sender, DragEventArgs e) { - if (e.DataView.Properties.ContainsKey("DockDocument")) + if (e.DataView.Properties.ContainsKey(DRAG_DOCUMENT_KEY)) { e.AcceptedOperation = global::Windows.ApplicationModel.DataTransfer.DataPackageOperation.Move; Root?.ShowHighlight(this, e.GetPosition(this)); @@ -82,7 +83,7 @@ public partial class DockGroup : DockContainer private void OnDrop(object sender, DragEventArgs e) { - if (e.DataView.Properties.TryGetValue("DockDocument", out var obj) && obj is DockDocument doc) + if (e.DataView.Properties.TryGetValue(DRAG_DOCUMENT_KEY, out var obj) && obj is DockDocument doc) { Root?.HandleDrop(doc, this, e.GetPosition(this)); } diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs index 0dcd5b4..b76128a 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs @@ -76,7 +76,7 @@ public class DockingLayout : Control if (targetGroup != null && targetGroup.Root != this) { - throw new ArgumentException("targetGroup does not belong to this DockingLayout"); + throw new ArgumentException("targetGroup does not belong to this DockingLayout", nameof(targetGroup)); } if (RootPanel == null) @@ -150,7 +150,7 @@ public class DockingLayout : Control { // Different orientation, need a new sub-panel var newPanel = new DockPanel { Orientation = orientation }; - parentPanel.InsertChild(index, newPanel); + parentPanel.ReplaceChild(targetGroup, newPanel); if (target == DockTarget.Left || target == DockTarget.Top) {