diff --git a/src/Editor/Ghost.Editor/App.xaml.cs b/src/Editor/Ghost.Editor/App.xaml.cs index 5a62383..5e0282b 100644 --- a/src/Editor/Ghost.Editor/App.xaml.cs +++ b/src/Editor/Ghost.Editor/App.xaml.cs @@ -23,6 +23,7 @@ namespace Ghost.Editor; public partial class App : Application { private Window? _window; + private readonly List _secondaryWindows = new(); internal static Window? Window { @@ -39,6 +40,15 @@ public partial class App : Application } } + internal static void AddSecondaryWindow(Window window) + { + if (Current is App app) + { + app._secondaryWindows.Add(window); + window.Closed += (s, e) => app._secondaryWindows.Remove(window); + } + } + internal IHost Host { get; diff --git a/src/Editor/Ghost.Editor/View/Controls/DockLayout.cs b/src/Editor/Ghost.Editor/View/Controls/DockLayout.cs index 8cdf3dc..6d74a72 100644 --- a/src/Editor/Ghost.Editor/View/Controls/DockLayout.cs +++ b/src/Editor/Ghost.Editor/View/Controls/DockLayout.cs @@ -300,12 +300,15 @@ public sealed partial class DockLayout : Control if (_sourceNode != null && _draggedItem != null) { // Remove from current tree - _sourceNode.Items.Remove(_draggedItem); - DockMutationEngine.CleanupEmptyNodes(_sourceNode, Root); + if (_sourceNode.Items.Remove(_draggedItem)) + { + DockMutationEngine.CleanupEmptyNodes(_sourceNode); - // Create new window - var newWindow = new Ghost.Editor.View.Windows.DockWindow(_draggedItem); - newWindow.Activate(); + // Create new window and register it with App to prevent GC + var newWindow = new Ghost.Editor.View.Windows.DockWindow(_draggedItem); + App.AddSecondaryWindow(newWindow); + newWindow.Activate(); + } ClearDragOperationState(); } diff --git a/src/Editor/Ghost.Editor/View/Windows/DockWindow.xaml.cs b/src/Editor/Ghost.Editor/View/Windows/DockWindow.xaml.cs index 00d9fc1..2a89b92 100644 --- a/src/Editor/Ghost.Editor/View/Windows/DockWindow.xaml.cs +++ b/src/Editor/Ghost.Editor/View/Windows/DockWindow.xaml.cs @@ -3,7 +3,7 @@ using WinUIEx; namespace Ghost.Editor.View.Windows; -public sealed partial class DockWindow : WindowEx +internal sealed partial class DockWindow : WindowEx { public DockWindow(object initialTabContent) { @@ -16,7 +16,5 @@ public sealed partial class DockWindow : WindowEx rootGroup.AddChild(panel); PART_DockLayout.Root = rootGroup; - - // Optional: Titlebar setup etc. } }