fix(dock): ensure exception-safe reentrancy guard and symmetrical event cleanup
This commit is contained in:
@@ -110,50 +110,52 @@ public sealed partial class DockLayout
|
|||||||
{
|
{
|
||||||
if (_isSyncingSizes) return;
|
if (_isSyncingSizes) return;
|
||||||
|
|
||||||
bool isHorizontal = groupNode.Orientation == Orientation.Horizontal;
|
try
|
||||||
bool changed = false;
|
|
||||||
|
|
||||||
if (isHorizontal)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < groupNode.Children.Count; i++)
|
bool isHorizontal = groupNode.Orientation == Orientation.Horizontal;
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
if (isHorizontal)
|
||||||
{
|
{
|
||||||
if (i < groupNode.Sizes.Count && i * 2 < grid.ColumnDefinitions.Count)
|
for (int i = 0; i < groupNode.Children.Count; i++)
|
||||||
{
|
{
|
||||||
var newWidth = grid.ColumnDefinitions[i * 2].Width;
|
if (i < groupNode.Sizes.Count && i * 2 < grid.ColumnDefinitions.Count)
|
||||||
if (!groupNode.Sizes[i].Equals(newWidth))
|
|
||||||
{
|
{
|
||||||
// Only sync if it's a star or pixel value (not Auto)
|
var newWidth = grid.ColumnDefinitions[i * 2].Width;
|
||||||
if (newWidth.IsStar || newWidth.IsAbsolute)
|
if (!groupNode.Sizes[i].Equals(newWidth))
|
||||||
{
|
{
|
||||||
_isSyncingSizes = true;
|
// Only sync if it's a star or pixel value (not Auto)
|
||||||
groupNode.Sizes[i] = newWidth;
|
if (newWidth.IsStar || newWidth.IsAbsolute)
|
||||||
changed = true;
|
{
|
||||||
|
_isSyncingSizes = true;
|
||||||
|
groupNode.Sizes[i] = newWidth;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < groupNode.Children.Count; i++)
|
||||||
|
{
|
||||||
|
if (i < groupNode.Sizes.Count && i * 2 < grid.RowDefinitions.Count)
|
||||||
|
{
|
||||||
|
var newHeight = grid.RowDefinitions[i * 2].Height;
|
||||||
|
if (!groupNode.Sizes[i].Equals(newHeight))
|
||||||
|
{
|
||||||
|
if (newHeight.IsStar || newHeight.IsAbsolute)
|
||||||
|
{
|
||||||
|
_isSyncingSizes = true;
|
||||||
|
groupNode.Sizes[i] = newHeight;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
finally
|
||||||
{
|
|
||||||
for (int i = 0; i < groupNode.Children.Count; i++)
|
|
||||||
{
|
|
||||||
if (i < groupNode.Sizes.Count && i * 2 < grid.RowDefinitions.Count)
|
|
||||||
{
|
|
||||||
var newHeight = grid.RowDefinitions[i * 2].Height;
|
|
||||||
if (!groupNode.Sizes[i].Equals(newHeight))
|
|
||||||
{
|
|
||||||
if (newHeight.IsStar || newHeight.IsAbsolute)
|
|
||||||
{
|
|
||||||
_isSyncingSizes = true;
|
|
||||||
groupNode.Sizes[i] = newHeight;
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed)
|
|
||||||
{
|
{
|
||||||
_isSyncingSizes = false;
|
_isSyncingSizes = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,13 @@ internal sealed partial class EngineEditorWindow : WindowEx
|
|||||||
this.CenterOnScreen();
|
this.CenterOnScreen();
|
||||||
|
|
||||||
InitializeDockLayout();
|
InitializeDockLayout();
|
||||||
|
|
||||||
|
this.Unloaded += OnUnloaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUnloaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
PART_DockLayout.TabTornOff -= OnTabTornOff;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeDockLayout()
|
private void InitializeDockLayout()
|
||||||
@@ -68,7 +75,12 @@ internal sealed partial class EngineEditorWindow : WindowEx
|
|||||||
root.AddChild(rightGroup);
|
root.AddChild(rightGroup);
|
||||||
|
|
||||||
PART_DockLayout.Root = root;
|
PART_DockLayout.Root = root;
|
||||||
PART_DockLayout.TabTornOff += (s, e) => App.CreateAndShowDockWindow(e.TabContent);
|
PART_DockLayout.TabTornOff += OnTabTornOff;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTabTornOff(object? sender, TabTornOffEventArgs e)
|
||||||
|
{
|
||||||
|
App.CreateAndShowDockWindow(e.TabContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainGrid_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
private void MainGrid_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user