fix(docking): improve container consistency and re-parenting
This commit is contained in:
@@ -13,18 +13,35 @@ public abstract class DockContainer : DockModule
|
|||||||
|
|
||||||
private void OnChildrenChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
private void OnChildrenChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
|
||||||
|
{
|
||||||
|
// Reset is tricky because e.OldItems is null.
|
||||||
|
// We should have handled this by clearing owners before Clear() was called,
|
||||||
|
// or by using a custom collection that notifies before clearing.
|
||||||
|
// For now, we'll just log or handle it if we can.
|
||||||
|
}
|
||||||
|
|
||||||
if (e.OldItems != null)
|
if (e.OldItems != null)
|
||||||
{
|
{
|
||||||
foreach (DockModule module in e.OldItems)
|
foreach (DockModule module in e.OldItems)
|
||||||
|
{
|
||||||
|
if (module.Owner == this)
|
||||||
{
|
{
|
||||||
module.Owner = null;
|
module.Owner = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (e.NewItems != null)
|
if (e.NewItems != null)
|
||||||
{
|
{
|
||||||
foreach (DockModule module in e.NewItems)
|
foreach (DockModule module in e.NewItems)
|
||||||
{
|
{
|
||||||
|
// Re-parenting: if it has an owner, detach it
|
||||||
|
if (module.Owner != null && module.Owner != this)
|
||||||
|
{
|
||||||
|
module.Owner.Children.Remove(module);
|
||||||
|
}
|
||||||
|
|
||||||
module.Owner = this;
|
module.Owner = this;
|
||||||
// module.Root = Root;
|
// module.Root = Root;
|
||||||
}
|
}
|
||||||
@@ -33,5 +50,22 @@ public abstract class DockContainer : DockModule
|
|||||||
OnChildrenUpdated();
|
OnChildrenUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddChild(DockModule module)
|
||||||
|
{
|
||||||
|
if (Children.Contains(module))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Children.Add(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
foreach (var child in Children)
|
||||||
|
{
|
||||||
|
child.Owner = null;
|
||||||
|
}
|
||||||
|
Children.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void OnChildrenUpdated() { }
|
protected virtual void OnChildrenUpdated() { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public abstract class DockModule : Control
|
|||||||
|
|
||||||
public void Detach()
|
public void Detach()
|
||||||
{
|
{
|
||||||
// Owner?.Children.Remove(this);
|
Owner?.Children.Remove(this);
|
||||||
Owner = null;
|
Owner = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user