fix(docking): add ownership guards and rename FindFirstLeafDockGroup

This commit is contained in:
2026-03-28 22:15:55 +09:00
parent 45375ac2ff
commit 1ec8496b8b

View File

@@ -56,6 +56,11 @@ public class DockingLayout : Control
if (e.NewValue is DockPanel newPanel) if (e.NewValue is DockPanel newPanel)
{ {
if (newPanel.Root != null && newPanel.Root != layout)
{
throw new InvalidOperationException("Panel is already owned by another DockingLayout");
}
newPanel.Root = layout; newPanel.Root = layout;
} }
} }
@@ -74,6 +79,11 @@ public class DockingLayout : Control
throw new NotImplementedException("Target docking will be implemented in Task 5"); throw new NotImplementedException("Target docking will be implemented in Task 5");
} }
if (targetGroup != null && targetGroup.Root != this)
{
throw new ArgumentException("targetGroup does not belong to this DockingLayout");
}
if (RootPanel == null) if (RootPanel == null)
{ {
RootPanel = new DockPanel(); RootPanel = new DockPanel();
@@ -81,7 +91,7 @@ public class DockingLayout : Control
if (targetGroup == null) if (targetGroup == null)
{ {
targetGroup = FindFirstLeafDockGroup(RootPanel); targetGroup = FindFirstDockGroup(RootPanel);
if (targetGroup == null) if (targetGroup == null)
{ {
@@ -93,7 +103,7 @@ public class DockingLayout : Control
targetGroup.AddChild(document); targetGroup.AddChild(document);
} }
private static DockGroup? FindFirstLeafDockGroup(DockContainer container) private static DockGroup? FindFirstDockGroup(DockContainer container)
{ {
if (container is DockGroup group) if (container is DockGroup group)
{ {
@@ -104,7 +114,7 @@ public class DockingLayout : Control
{ {
if (child is DockContainer childContainer) if (child is DockContainer childContainer)
{ {
var result = FindFirstLeafDockGroup(childContainer); var result = FindFirstDockGroup(childContainer);
if (result != null) if (result != null)
{ {
return result; return result;