fix(dock): fix build breaks, handle size reordering, and add size change subscriptions
This commit is contained in:
@@ -42,27 +42,45 @@ public partial class DockGroupNode : DockNode
|
||||
private void OnChildrenChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
// Maintain Sizes collection to match Children
|
||||
if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
|
||||
switch (e.Action)
|
||||
{
|
||||
for (int i = 0; i < e.NewItems.Count; i++)
|
||||
{
|
||||
Sizes.Insert(e.NewStartingIndex + i, new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star));
|
||||
}
|
||||
}
|
||||
else if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems != null)
|
||||
{
|
||||
for (int i = 0; i < e.OldItems.Count; i++)
|
||||
{
|
||||
Sizes.RemoveAt(e.OldStartingIndex);
|
||||
}
|
||||
}
|
||||
else if (e.Action == NotifyCollectionChangedAction.Reset)
|
||||
{
|
||||
Sizes.Clear();
|
||||
foreach (var _ in _children)
|
||||
{
|
||||
Sizes.Add(new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star));
|
||||
}
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
if (e.NewItems != null)
|
||||
{
|
||||
for (int i = 0; i < e.NewItems.Count; i++)
|
||||
{
|
||||
Sizes.Insert(e.NewStartingIndex + i, new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
if (e.OldItems != null)
|
||||
{
|
||||
for (int i = 0; i < e.OldItems.Count; i++)
|
||||
{
|
||||
Sizes.RemoveAt(e.OldStartingIndex);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Move:
|
||||
Sizes.Move(e.OldStartingIndex, e.NewStartingIndex);
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Replace:
|
||||
if (e.NewItems != null)
|
||||
{
|
||||
for (int i = 0; i < e.NewItems.Count; i++)
|
||||
{
|
||||
Sizes[e.NewStartingIndex + i] = new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Reset:
|
||||
Sizes.Clear();
|
||||
foreach (var _ in _children)
|
||||
{
|
||||
Sizes.Add(new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ using Ghost.Editor.Core.Controls.Internal.Docking;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Ghost.Editor.View.Controls;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ public sealed partial class DockLayout
|
||||
if (node is DockGroupNode groupNode)
|
||||
{
|
||||
((INotifyCollectionChanged)groupNode.Children).CollectionChanged += OnChildrenCollectionChanged;
|
||||
groupNode.Sizes.CollectionChanged += OnSizesCollectionChanged;
|
||||
foreach (var child in groupNode.Children)
|
||||
{
|
||||
SubscribeToNode(child);
|
||||
@@ -38,6 +39,7 @@ public sealed partial class DockLayout
|
||||
if (node is DockGroupNode groupNode)
|
||||
{
|
||||
((INotifyCollectionChanged)groupNode.Children).CollectionChanged -= OnChildrenCollectionChanged;
|
||||
groupNode.Sizes.CollectionChanged -= OnSizesCollectionChanged;
|
||||
foreach (var child in groupNode.Children)
|
||||
{
|
||||
UnsubscribeFromNode(child);
|
||||
@@ -55,11 +57,17 @@ public sealed partial class DockLayout
|
||||
if (node is DockGroupNode groupNode)
|
||||
{
|
||||
((INotifyCollectionChanged)groupNode.Children).CollectionChanged -= OnChildrenCollectionChanged;
|
||||
groupNode.Sizes.CollectionChanged -= OnSizesCollectionChanged;
|
||||
}
|
||||
}
|
||||
_subscribedNodes.Clear();
|
||||
}
|
||||
|
||||
private void OnSizesCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
RenderTree();
|
||||
}
|
||||
|
||||
private void OnNodePropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
// Filter to structural property names
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using Ghost.Core;
|
||||
using Ghost.Editor.Core.Controls.Internal.Docking;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Ghost.Editor.View.Controls;
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@ using Ghost.Editor.Core.Contracts;
|
||||
using Ghost.Editor.Core.Services;
|
||||
using Ghost.Editor.Core.Controls.Internal.Docking;
|
||||
using Ghost.Editor.View.Controls;
|
||||
using Ghost.Editor.View.Pages.EngineEditor;
|
||||
using Ghost.Editor.ViewModels.Windows;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Windows.ApplicationModel;
|
||||
using WinUIEx;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user