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

This commit is contained in:
2026-03-28 22:39:57 +09:00
parent 8d3c5ecb1f
commit 35731d4ebe
3 changed files with 25 additions and 5 deletions

View File

@@ -9,7 +9,7 @@ namespace Ghost.Editor.View.Controls.Docking;
public abstract class DockContainer : DockModule
{
private readonly ObservableCollection<DockModule> _children = new();
protected bool _isCleaningUp;
private bool _isCleaningUp;
/// <summary>
/// Gets the collection of child modules.
/// </summary>
@@ -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;

View File

@@ -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;
}
}
}
}

View File

@@ -235,6 +235,7 @@ public class DockingLayout : Control
}
else
{
if (doc.Owner == targetGroup && targetGroup.Children.Count == 1) return;
SplitGroup(targetGroup, doc, target);
}
}