fix(dock): complete tear-off flow and add rollback on failure

This commit is contained in:
2026-03-28 16:01:42 +09:00
parent 8c136709ff
commit 304df0a381
4 changed files with 49 additions and 8 deletions

View File

@@ -306,20 +306,23 @@ public sealed partial class DockLayout : Control
{
DockMutationEngine.CleanupEmptyNodes(_sourceNode);
// Raise event to let the host handle window creation
TabTornOff?.Invoke(this, new TabTornOffEventArgs(_draggedItem));
try
{
// Raise event to let the host handle window creation
TabTornOff?.Invoke(this, new TabTornOffEventArgs(_draggedItem));
}
catch (Exception ex)
{
// Rollback: Re-insert the item if the tear-off handler fails
_sourceNode.Items.Add(_draggedItem);
Logger.LogError($"Failed to tear off tab: {ex.Message}");
}
}
ClearDragOperationState();
}
}
public class TabTornOffEventArgs : EventArgs
{
public object TabContent { get; }
public TabTornOffEventArgs(object tabContent) => TabContent = tabContent;
}
private object? _draggedItem;
private DockPanelNode? _sourceNode;
private DockPosition _currentDropPosition = DockPosition.None;