fix(docking): address code quality issues and improve structural integrity
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Ghost.Editor.View.Controls.Docking;
|
|||||||
public abstract class DockContainer : DockModule
|
public abstract class DockContainer : DockModule
|
||||||
{
|
{
|
||||||
private readonly ObservableCollection<DockModule> _children = new();
|
private readonly ObservableCollection<DockModule> _children = new();
|
||||||
protected bool _isCleaningUp;
|
private bool _isCleaningUp;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the collection of child modules.
|
/// Gets the collection of child modules.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -50,7 +50,15 @@ public abstract class DockContainer : DockModule
|
|||||||
if (_children.Contains(module))
|
if (_children.Contains(module))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
module.Owner?.RemoveChildInternal(module, false);
|
if (module.Owner == this)
|
||||||
|
{
|
||||||
|
RemoveChildInternal(module, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
module.Owner?.RemoveChild(module);
|
||||||
|
}
|
||||||
|
|
||||||
module.Owner = this;
|
module.Owner = this;
|
||||||
module.Root = Root;
|
module.Root = Root;
|
||||||
_children.Insert(index, module);
|
_children.Insert(index, module);
|
||||||
@@ -90,11 +98,20 @@ public abstract class DockContainer : DockModule
|
|||||||
ArgumentNullException.ThrowIfNull(oldChild);
|
ArgumentNullException.ThrowIfNull(oldChild);
|
||||||
ValidateChild(newChild);
|
ValidateChild(newChild);
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
// Detach newChild from its current owner if any
|
// 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
|
// Remove oldChild without triggering cleanup
|
||||||
_isCleaningUp = true;
|
_isCleaningUp = true;
|
||||||
|
|||||||
@@ -61,8 +61,10 @@ public class DockPanel : DockContainer
|
|||||||
}
|
}
|
||||||
else if (Root != null && Root.RootPanel == this)
|
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,
|
if (child is DockPanel childPanel)
|
||||||
// because RootPanel must be a DockPanel. So we just leave it.
|
{
|
||||||
|
Root.RootPanel = childPanel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,6 +235,7 @@ public class DockingLayout : Control
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (doc.Owner == targetGroup && targetGroup.Children.Count == 1) return;
|
||||||
SplitGroup(targetGroup, doc, target);
|
SplitGroup(targetGroup, doc, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user