fix: address code quality issues in DockContainer and DockPanel
- Throw ArgumentException in DockContainer.ReplaceChild if newChild is already in the container to avoid index shifting bugs. - Add comment in DockPanel.CheckCleanup explaining the asymmetric root panel collapse behavior.
This commit is contained in:
@@ -102,12 +102,10 @@ public abstract class DockContainer : DockModule
|
|||||||
// Detach newChild from its current owner if any
|
// Detach newChild from its current owner if any
|
||||||
if (newChild.Owner == this)
|
if (newChild.Owner == this)
|
||||||
{
|
{
|
||||||
newChild.Owner.RemoveChildInternal(newChild, false);
|
throw new ArgumentException("newChild is already in this container", nameof(newChild));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
newChild.Owner?.RemoveChild(newChild);
|
newChild.Owner?.RemoveChild(newChild);
|
||||||
}
|
|
||||||
|
|
||||||
// Remove oldChild without triggering cleanup
|
// Remove oldChild without triggering cleanup
|
||||||
_isCleaningUp = true;
|
_isCleaningUp = true;
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ public class DockPanel : DockContainer
|
|||||||
}
|
}
|
||||||
else if (Root != null && Root.RootPanel == this)
|
else if (Root != null && Root.RootPanel == this)
|
||||||
{
|
{
|
||||||
|
// We only collapse the root panel if the child is also a DockPanel
|
||||||
|
// because DockingLayout.RootPanel is strongly typed as DockPanel,
|
||||||
|
// so we can't assign a DockGroup to it directly.
|
||||||
if (child is DockPanel childPanel)
|
if (child is DockPanel childPanel)
|
||||||
{
|
{
|
||||||
RemoveChildInternal(childPanel, false);
|
RemoveChildInternal(childPanel, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user