diff --git a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs index f783822a5..e1a358b6e 100644 --- a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs @@ -591,14 +591,14 @@ namespace FlaxEditor.CustomEditors.Dedicated var group = layout.Group(title, editor); if ((Presenter.Features & FeatureFlags.CacheExpandedGroups) != 0) { - if (Editor.Instance.ProjectCache.IsCollapsedGroup(title)) - group.Panel.Close(false); + if (Editor.Instance.ProjectCache.IsGroupToggled(title)) + group.Panel.Close(); else - group.Panel.Open(false); - group.Panel.IsClosedChanged += panel => Editor.Instance.ProjectCache.SetCollapsedGroup(panel.HeaderText, panel.IsClosed); + group.Panel.Open(); + group.Panel.IsClosedChanged += panel => Editor.Instance.ProjectCache.SetGroupToggle(panel.HeaderText, panel.IsClosed); } else - group.Panel.Open(false); + group.Panel.Open(); // Customize group.Panel.TooltipText = Editor.Instance.CodeDocs.GetTooltip(scriptType); diff --git a/Source/Editor/CustomEditors/LayoutElementsContainer.cs b/Source/Editor/CustomEditors/LayoutElementsContainer.cs index 936851b15..e9a501bec 100644 --- a/Source/Editor/CustomEditors/LayoutElementsContainer.cs +++ b/Source/Editor/CustomEditors/LayoutElementsContainer.cs @@ -25,6 +25,11 @@ namespace FlaxEditor.CustomEditors /// internal bool isRootGroup = true; + /// + /// Parent container who created this one. + /// + internal LayoutElementsContainer _parent; + /// /// The children. /// @@ -40,6 +45,24 @@ namespace FlaxEditor.CustomEditors /// public abstract ContainerControl ContainerControl { get; } + /// + /// Gets the Custom Editors layout presenter. + /// + internal CustomEditorPresenter Presenter + { + get + { + CustomEditorPresenter result; + var container = this; + do + { + result = container as CustomEditorPresenter; + container = container._parent; + } while (container != null); + return result; + } + } + /// /// Adds new group element. /// @@ -81,17 +104,31 @@ namespace FlaxEditor.CustomEditors public GroupElement Group(string title, bool useTransparentHeader = false) { var element = new GroupElement(); - if (!isRootGroup) + var presenter = Presenter; + var isSubGroup = !isRootGroup; + if (isSubGroup) + element.Panel.Close(); + if (presenter != null && (presenter.Features & FeatureFlags.CacheExpandedGroups) != 0) { - element.Panel.Close(false); - } - else if (this is CustomEditorPresenter presenter && (presenter.Features & FeatureFlags.CacheExpandedGroups) != 0) - { - if (Editor.Instance.ProjectCache.IsCollapsedGroup(title)) - element.Panel.Close(false); - element.Panel.IsClosedChanged += OnPanelIsClosedChanged; + // Build group identifier (made of path from group titles) + var expandPath = title; + var container = this; + while (container != null && !(container is CustomEditorPresenter)) + { + if (container.ContainerControl is DropPanel dropPanel) + expandPath = dropPanel.HeaderText + "/" + expandPath; + container = container._parent; + } + + // Caching/restoring expanded groups (non-root groups cache expanded state so invert boolean expression) + if (Editor.Instance.ProjectCache.IsGroupToggled(expandPath) ^ isSubGroup) + element.Panel.Close(); + else + element.Panel.Open(); + element.Panel.IsClosedChanged += panel => Editor.Instance.ProjectCache.SetGroupToggle(expandPath, panel.IsClosed ^ isSubGroup); } element.isRootGroup = false; + element._parent = this; element.Panel.HeaderText = title; if (useTransparentHeader) { @@ -103,11 +140,6 @@ namespace FlaxEditor.CustomEditors return element; } - private void OnPanelIsClosedChanged(DropPanel panel) - { - Editor.Instance.ProjectCache.SetCollapsedGroup(panel.HeaderText, panel.IsClosed); - } - /// /// Adds new horizontal panel element. /// @@ -627,7 +659,6 @@ namespace FlaxEditor.CustomEditors if (style == DisplayStyle.Group) { var group = Group(name, editor, true); - group.Panel.Close(false); group.Panel.TooltipText = tooltip; return group.Object(values, editor); } @@ -657,7 +688,6 @@ namespace FlaxEditor.CustomEditors if (style == DisplayStyle.Group) { var group = Group(label.Text, editor, true); - group.Panel.Close(false); group.Panel.TooltipText = tooltip; return group.Object(values, editor); } diff --git a/Source/Editor/Modules/ProjectCacheModule.cs b/Source/Editor/Modules/ProjectCacheModule.cs index acb6e997e..eebea3ba0 100644 --- a/Source/Editor/Modules/ProjectCacheModule.cs +++ b/Source/Editor/Modules/ProjectCacheModule.cs @@ -18,7 +18,7 @@ namespace FlaxEditor.Modules private DateTime _lastSaveTime; private readonly HashSet _expandedActors = new HashSet(); - private readonly HashSet _collapsedGroups = new HashSet(); + private readonly HashSet _toggledGroups = new HashSet(); private readonly Dictionary _customData = new Dictionary(); /// @@ -62,26 +62,26 @@ namespace FlaxEditor.Modules } /// - /// Determines whether group identified by the given title is collapsed in the UI. + /// Determines whether group identified by the given title is collapsed/opened in the UI. /// /// The group title. - /// true if group is collapsed; otherwise, false. - public bool IsCollapsedGroup(string title) + /// true if group is toggled; otherwise, false. + public bool IsGroupToggled(string title) { - return _collapsedGroups.Contains(title); + return _toggledGroups.Contains(title); } /// - /// Sets the group collapsed cached value. + /// Sets the group collapsed/opened cached value. /// /// The group title. - /// If set to true group will be cached as an collapsed, otherwise false. - public void SetCollapsedGroup(string title, bool isCollapsed) + /// If set to true group will be cached as a toggled, otherwise false. + public void SetGroupToggle(string title, bool isToggled) { - if (isCollapsed) - _collapsedGroups.Add(title); + if (isToggled) + _toggledGroups.Add(title); else - _collapsedGroups.Remove(title); + _toggledGroups.Remove(title); _isDirty = true; } @@ -160,7 +160,7 @@ namespace FlaxEditor.Modules _expandedActors.Add(new Guid(bytes16)); } - _collapsedGroups.Clear(); + _toggledGroups.Clear(); _customData.Clear(); break; @@ -176,7 +176,7 @@ namespace FlaxEditor.Modules _expandedActors.Add(new Guid(bytes16)); } - _collapsedGroups.Clear(); + _toggledGroups.Clear(); _customData.Clear(); int customDataCount = reader.ReadInt32(); @@ -201,11 +201,9 @@ namespace FlaxEditor.Modules } int collapsedGroupsCount = reader.ReadInt32(); - _collapsedGroups.Clear(); + _toggledGroups.Clear(); for (int i = 0; i < collapsedGroupsCount; i++) - { - _collapsedGroups.Add(reader.ReadString()); - } + _toggledGroups.Add(reader.ReadString()); _customData.Clear(); int customDataCount = reader.ReadInt32(); @@ -259,11 +257,9 @@ namespace FlaxEditor.Modules writer.Write(e.ToByteArray()); } - writer.Write(_collapsedGroups.Count); - foreach (var e in _collapsedGroups) - { + writer.Write(_toggledGroups.Count); + foreach (var e in _toggledGroups) writer.Write(e); - } writer.Write(_customData.Count); foreach (var e in _customData) @@ -284,7 +280,6 @@ namespace FlaxEditor.Modules try { SaveGuarded(); - _isDirty = false; } catch (Exception ex)