From 3e9b6caa1cacfccde746ada5f43a4555b668487d Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Fri, 25 Mar 2022 15:36:30 +0100 Subject: [PATCH] Fix sorting items in various contextual list popups in Editor --- .../Editor/CustomEditors/Dedicated/RagdollEditor.cs | 2 +- .../Editor/CustomEditors/Dedicated/ScriptsEditor.cs | 2 +- .../CustomEditors/Dedicated/UIControlEditor.cs | 2 +- Source/Editor/GUI/ItemsListContextMenu.cs | 13 +++++++++++++ Source/Editor/GUI/Popups/ActorSearchPopup.cs | 2 +- Source/Editor/GUI/Popups/AssetSearchPopup.cs | 2 +- Source/Editor/GUI/Popups/ScriptSearchPopup.cs | 2 +- Source/Editor/GUI/Popups/TypeSearchPopup.cs | 2 +- Source/Editor/Surface/Archetypes/Particles.cs | 2 +- Source/Editor/Surface/VisjectSurfaceWindow.cs | 2 +- Source/Editor/Windows/Assets/VisualScriptWindow.cs | 2 +- 11 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Source/Editor/CustomEditors/Dedicated/RagdollEditor.cs b/Source/Editor/CustomEditors/Dedicated/RagdollEditor.cs index fa72e06c0..2c3aebcc1 100644 --- a/Source/Editor/CustomEditors/Dedicated/RagdollEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/RagdollEditor.cs @@ -273,7 +273,7 @@ namespace FlaxEditor.CustomEditors.Dedicated cm.AddItem(item); } cm.ItemClicked += item => action((string)item.Tag); - cm.SortChildren(); + cm.SortItems(); cm.Show(button.Parent, button.BottomLeft); } diff --git a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs index d101d2ff2..8febb3958 100644 --- a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs @@ -71,7 +71,7 @@ namespace FlaxEditor.CustomEditors.Dedicated cm.AddItem(new TypeSearchPopup.TypeItemView(scripts[i])); } cm.ItemClicked += item => AddScript((ScriptType)item.Tag); - cm.SortChildren(); + cm.SortItems(); cm.Show(this, button.BottomLeft); } diff --git a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs index ac26de204..55473d42c 100644 --- a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs @@ -642,7 +642,7 @@ namespace FlaxEditor.CustomEditors.Dedicated cm.AddItem(new TypeSearchPopup.TypeItemView(controlTypes[i])); } cm.ItemClicked += controlType => SetType((ScriptType)controlType.Tag); - cm.SortChildren(); + cm.SortItems(); cm.Show(button.Parent, button.BottomLeft); } diff --git a/Source/Editor/GUI/ItemsListContextMenu.cs b/Source/Editor/GUI/ItemsListContextMenu.cs index 1c62a6556..3bfe912c4 100644 --- a/Source/Editor/GUI/ItemsListContextMenu.cs +++ b/Source/Editor/GUI/ItemsListContextMenu.cs @@ -263,6 +263,19 @@ namespace FlaxEditor.GUI PerformLayout(true); _searchBox.Focus(); } + + /// + /// Sorts the items list (by item name by default). + /// + public void SortItems() + { + ItemsPanel.SortChildren(); + if (_categoryPanels != null) + { + for (int i = 0; i < _categoryPanels.Count; i++) + _categoryPanels[i].SortChildren(); + } + } /// /// Adds the item to the view and registers for the click event. diff --git a/Source/Editor/GUI/Popups/ActorSearchPopup.cs b/Source/Editor/GUI/Popups/ActorSearchPopup.cs index b5859a52b..92482c18e 100644 --- a/Source/Editor/GUI/Popups/ActorSearchPopup.cs +++ b/Source/Editor/GUI/Popups/ActorSearchPopup.cs @@ -67,7 +67,7 @@ namespace FlaxEditor.GUI { Find(Level.GetScene(i)); } - SortChildren(); + SortItems(); } private void OnItemClicked(Item item) diff --git a/Source/Editor/GUI/Popups/AssetSearchPopup.cs b/Source/Editor/GUI/Popups/AssetSearchPopup.cs index 3f81c2e2a..8f5e007a0 100644 --- a/Source/Editor/GUI/Popups/AssetSearchPopup.cs +++ b/Source/Editor/GUI/Popups/AssetSearchPopup.cs @@ -122,7 +122,7 @@ namespace FlaxEditor.GUI if (project.Content != null) FindAssets(project.Content.Folder); } - SortChildren(); + SortItems(); } private void OnItemClicked(Item item) diff --git a/Source/Editor/GUI/Popups/ScriptSearchPopup.cs b/Source/Editor/GUI/Popups/ScriptSearchPopup.cs index d8c1e9ee1..ece346895 100644 --- a/Source/Editor/GUI/Popups/ScriptSearchPopup.cs +++ b/Source/Editor/GUI/Popups/ScriptSearchPopup.cs @@ -78,7 +78,7 @@ namespace FlaxEditor.GUI { Find(Level.GetScene(i)); } - SortChildren(); + SortItems(); } private void OnItemClicked(Item item) diff --git a/Source/Editor/GUI/Popups/TypeSearchPopup.cs b/Source/Editor/GUI/Popups/TypeSearchPopup.cs index 9ab0d5b54..40396652b 100644 --- a/Source/Editor/GUI/Popups/TypeSearchPopup.cs +++ b/Source/Editor/GUI/Popups/TypeSearchPopup.cs @@ -95,7 +95,7 @@ namespace FlaxEditor.GUI } } } - SortChildren(); + SortItems(); } private void OnItemClicked(Item item) diff --git a/Source/Editor/Surface/Archetypes/Particles.cs b/Source/Editor/Surface/Archetypes/Particles.cs index 17f96228f..9585dff88 100644 --- a/Source/Editor/Surface/Archetypes/Particles.cs +++ b/Source/Editor/Surface/Archetypes/Particles.cs @@ -126,7 +126,7 @@ namespace FlaxEditor.Surface.Archetypes }); } cm.ItemClicked += item => AddModule((ushort)item.Tag); - cm.SortChildren(); + cm.SortItems(); cm.Show(this, button.BottomLeft); } diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 6ae949000..08640be17 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -461,7 +461,7 @@ namespace FlaxEditor.Surface cm.AddItem(item); } cm.ItemClicked += OnAddParameterItemClicked; - cm.SortChildren(); + cm.SortItems(); cm.Show(button.Parent, button.BottomLeft); } diff --git a/Source/Editor/Windows/Assets/VisualScriptWindow.cs b/Source/Editor/Windows/Assets/VisualScriptWindow.cs index 2fab58b9f..bb3844eab 100644 --- a/Source/Editor/Windows/Assets/VisualScriptWindow.cs +++ b/Source/Editor/Windows/Assets/VisualScriptWindow.cs @@ -188,7 +188,7 @@ namespace FlaxEditor.Windows.Assets cm.AddItem(item); } cm.ItemClicked += (ItemsListContextMenu.Item item) => window.SetParamType(index, (ScriptType)item.Tag); - cm.SortChildren(); + cm.SortItems(); cm.Show(window, window.PointFromScreen(Input.MouseScreenPosition)); }); b.Enabled = window._canEdit;