diff --git a/Source/Editor/CustomEditorWindow.cs b/Source/Editor/CustomEditorWindow.cs index 242b4d28d..5c3fedd6c 100644 --- a/Source/Editor/CustomEditorWindow.cs +++ b/Source/Editor/CustomEditorWindow.cs @@ -1,9 +1,9 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using FlaxEditor.CustomEditors; +using FlaxEditor.GUI.Docking; using FlaxEditor.Windows; using FlaxEngine.GUI; -using DockState = FlaxEditor.GUI.Docking.DockState; namespace FlaxEditor { @@ -97,9 +97,12 @@ namespace FlaxEditor /// Shows the window. /// /// Initial window state. - public void Show(DockState state = DockState.Float) + /// The panel to dock to, if any. + /// Only used if is set. If true the window will be selected after docking it. + /// The splitter value to use if toDock is not null. If not specified, a default value will be used. + public void Show(DockState state = DockState.Float, DockPanel toDock = null, bool autoSelect = true, float? splitterValue = null) { - _win.Show(state); + _win.Show(state, toDock, autoSelect, splitterValue); } } } diff --git a/Source/Editor/GUI/Docking/DockPanel.cs b/Source/Editor/GUI/Docking/DockPanel.cs index b04aad08c..df6a75bef 100644 --- a/Source/Editor/GUI/Docking/DockPanel.cs +++ b/Source/Editor/GUI/Docking/DockPanel.cs @@ -518,9 +518,9 @@ namespace FlaxEditor.GUI.Docking } } - internal virtual void DockWindowInternal(DockState state, DockWindow window) + internal virtual void DockWindowInternal(DockState state, DockWindow window, bool autoSelect = true, float? splitterValue = null) { - DockWindow(state, window); + DockWindow(state, window, autoSelect, splitterValue); } /// @@ -528,7 +528,9 @@ namespace FlaxEditor.GUI.Docking /// /// The state. /// The window. - protected virtual void DockWindow(DockState state, DockWindow window) + /// Whether or not to automatically select the window after docking it. + /// The splitter value to use when docking to window. + protected virtual void DockWindow(DockState state, DockWindow window, bool autoSelect = true, float? splitterValue = null) { CreateTabsProxy(); @@ -536,12 +538,12 @@ namespace FlaxEditor.GUI.Docking if (state == DockState.DockFill) { // Add tab - AddTab(window); + AddTab(window, autoSelect); } else { // Create child panel - var dockPanel = CreateChildPanel(state, DefaultSplitterValue); + var dockPanel = CreateChildPanel(state, splitterValue ?? DefaultSplitterValue); // Dock window as a tab in a child panel dockPanel.DockWindow(DockState.DockFill, window); diff --git a/Source/Editor/GUI/Docking/DockWindow.cs b/Source/Editor/GUI/Docking/DockWindow.cs index 72c74ad9e..15608d3e1 100644 --- a/Source/Editor/GUI/Docking/DockWindow.cs +++ b/Source/Editor/GUI/Docking/DockWindow.cs @@ -214,7 +214,9 @@ namespace FlaxEditor.GUI.Docking /// /// Initial window state. /// Panel to dock to it. - public void Show(DockState state = DockState.Float, DockPanel toDock = null) + /// Only used if is set. If true the window will be selected after docking it. + /// Only used if is set. The splitter value to use. If not specified, a default value will be used. + public void Show(DockState state = DockState.Float, DockPanel toDock = null, bool autoSelect = true, float? splitterValue = null) { if (state == DockState.Hidden) { @@ -232,7 +234,7 @@ namespace FlaxEditor.GUI.Docking Undock(); // Then dock - (toDock ?? _masterPanel).DockWindowInternal(state, this); + (toDock ?? _masterPanel).DockWindowInternal(state, this, autoSelect, splitterValue); OnShow(); PerformLayout(); } diff --git a/Source/Editor/Modules/WindowsModule.cs b/Source/Editor/Modules/WindowsModule.cs index 245fd4d5d..3e88a379c 100644 --- a/Source/Editor/Modules/WindowsModule.cs +++ b/Source/Editor/Modules/WindowsModule.cs @@ -36,6 +36,17 @@ namespace FlaxEditor.Modules { public string AssemblyName; public string TypeName; + + public DockState DockState; + public DockPanel DockedTo; + public float? SplitterValue = null; + + public bool SelectOnShow = false; + + // Constructor, to allow for default values + public WindowRestoreData() + { + } } private readonly List _restoreWindows = new List(); @@ -802,10 +813,33 @@ namespace FlaxEditor.Modules if (constructor == null || type.IsGenericType) return; - WindowRestoreData winData; + var winData = new WindowRestoreData(); + var panel = win.Window.ParentDockPanel; + + // Ensure that this window is only selected following recompilation + // if it was the active tab in its dock panel. Otherwise, there is a + // risk of interrupting the user's workflow by potentially selecting + // background tabs. + winData.SelectOnShow = panel.SelectedTab == win.Window; + if (panel is FloatWindowDockPanel) + { + winData.DockState = DockState.Float; + } + else + { + if (panel.TabsCount > 1) + { + winData.DockState = DockState.DockFill; + winData.DockedTo = panel; + }else + { + winData.DockState = panel.TryGetDockState(out var splitterValue); + winData.DockedTo = panel.ParentDockPanel; + winData.SplitterValue = splitterValue; + } + } winData.AssemblyName = type.Assembly.GetName().Name; winData.TypeName = type.FullName; - // TODO: cache and restore docking info _restoreWindows.Add(winData); } @@ -824,7 +858,7 @@ namespace FlaxEditor.Modules if (type != null) { var win = (CustomEditorWindow)Activator.CreateInstance(type); - win.Show(); + win.Show(winData.DockState, winData.DockedTo, winData.SelectOnShow, winData.SplitterValue); } } }