fix(docking): address code quality issues and improve structural integrity

This commit is contained in:
2026-03-28 22:42:07 +09:00
parent 35731d4ebe
commit d367cff79f
3 changed files with 10 additions and 6 deletions

View File

@@ -38,6 +38,9 @@ public abstract class DockContainer : DockModule
/// <summary> /// <summary>
/// Inserts a child module at the specified index. /// Inserts a child module at the specified index.
/// </summary> /// </summary>
/// <remarks>
/// This method does not support reordering existing children within the same container.
/// </remarks>
/// <param name="index">The zero-based index at which the module should be inserted.</param> /// <param name="index">The zero-based index at which the module should be inserted.</param>
/// <param name="module">The module to insert.</param> /// <param name="module">The module to insert.</param>
public virtual void InsertChild(int index, DockModule module) public virtual void InsertChild(int index, DockModule module)
@@ -101,7 +104,7 @@ public abstract class DockContainer : DockModule
if (oldChild == newChild) return; if (oldChild == newChild) return;
int index = _children.IndexOf(oldChild); 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 // Detach newChild from its current owner if any
if (newChild.Owner == this) if (newChild.Owner == this)

View File

@@ -11,6 +11,7 @@ namespace Ghost.Editor.View.Controls.Docking;
public partial class DockGroup : DockContainer public partial class DockGroup : DockContainer
{ {
private const string PART_TAB_VIEW = "PART_TabView"; private const string PART_TAB_VIEW = "PART_TabView";
private const string DRAG_DOCUMENT_KEY = "DockDocument";
private TabView? _tabView; private TabView? _tabView;
public DockGroup() public DockGroup()
@@ -59,7 +60,7 @@ public partial class DockGroup : DockContainer
{ {
if (args.Tab.Tag is DockDocument doc) 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) 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; e.AcceptedOperation = global::Windows.ApplicationModel.DataTransfer.DataPackageOperation.Move;
Root?.ShowHighlight(this, e.GetPosition(this)); Root?.ShowHighlight(this, e.GetPosition(this));
@@ -82,7 +83,7 @@ public partial class DockGroup : DockContainer
private void OnDrop(object sender, DragEventArgs e) 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)); Root?.HandleDrop(doc, this, e.GetPosition(this));
} }

View File

@@ -76,7 +76,7 @@ public class DockingLayout : Control
if (targetGroup != null && targetGroup.Root != this) 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) if (RootPanel == null)
@@ -150,7 +150,7 @@ public class DockingLayout : Control
{ {
// Different orientation, need a new sub-panel // Different orientation, need a new sub-panel
var newPanel = new DockPanel { Orientation = orientation }; var newPanel = new DockPanel { Orientation = orientation };
parentPanel.InsertChild(index, newPanel); parentPanel.ReplaceChild(targetGroup, newPanel);
if (target == DockTarget.Left || target == DockTarget.Top) if (target == DockTarget.Left || target == DockTarget.Top)
{ {