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
|
||||
if (newChild.Owner == this)
|
||||
{
|
||||
newChild.Owner.RemoveChildInternal(newChild, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
newChild.Owner?.RemoveChild(newChild);
|
||||
throw new ArgumentException("newChild is already in this container", nameof(newChild));
|
||||
}
|
||||
|
||||
newChild.Owner?.RemoveChild(newChild);
|
||||
|
||||
// Remove oldChild without triggering cleanup
|
||||
_isCleaningUp = true;
|
||||
|
||||
@@ -61,6 +61,9 @@ public class DockPanel : DockContainer
|
||||
}
|
||||
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)
|
||||
{
|
||||
RemoveChildInternal(childPanel, false);
|
||||
|
||||
Reference in New Issue
Block a user