From 12005ad3141c695cdef59bac66920013ec36b925 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sun, 23 Jul 2023 15:20:57 -0500 Subject: [PATCH] Simplify functionality into function. --- Source/Editor/GUI/AssetPicker.cs | 27 ++--------------------- Source/Editor/GUI/ItemsListContextMenu.cs | 20 +++++++++++++++++ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/Source/Editor/GUI/AssetPicker.cs b/Source/Editor/GUI/AssetPicker.cs index 7447e8472..39a06cf0b 100644 --- a/Source/Editor/GUI/AssetPicker.cs +++ b/Source/Editor/GUI/AssetPicker.cs @@ -484,18 +484,7 @@ namespace FlaxEditor.GUI if (_selected != null) { var selectedAssetName = Path.GetFileNameWithoutExtension(_selected.Path); - foreach (var child in popup.ItemsPanel.Children) - { - if (child is not ItemsListContextMenu.Item item) - continue; - if (string.Equals(item.Name, selectedAssetName, StringComparison.Ordinal)) - { - // Highlight and scroll to item - item.Focus(); - popup.ScrollViewTo(item); - break; - } - } + popup.ScrollToAndHighlightItemByName(selectedAssetName); } } else @@ -509,19 +498,7 @@ namespace FlaxEditor.GUI }); if (_selectedItem != null) { - var selectedItemName = _selectedItem.ShortName; - foreach (var child in popup.ItemsPanel.Children) - { - if (child is not ItemsListContextMenu.Item item) - continue; - if (string.Equals(item.Name, selectedItemName, StringComparison.Ordinal)) - { - // Highlight and scroll to item - item.Focus(); - popup.ScrollViewTo(item); - break; - } - } + popup.ScrollToAndHighlightItemByName(_selectedItem.ShortName); } } } diff --git a/Source/Editor/GUI/ItemsListContextMenu.cs b/Source/Editor/GUI/ItemsListContextMenu.cs index 12de479bf..42d236991 100644 --- a/Source/Editor/GUI/ItemsListContextMenu.cs +++ b/Source/Editor/GUI/ItemsListContextMenu.cs @@ -274,6 +274,26 @@ namespace FlaxEditor.GUI _scrollPanel.ScrollViewTo(item, true); } + /// + /// Scrolls to the item and focuses it by name. + /// + /// The item name. + public void ScrollToAndHighlightItemByName(string itemName) + { + foreach (var child in ItemsPanel.Children) + { + if (child is not ItemsListContextMenu.Item item) + continue; + if (string.Equals(item.Name, itemName, StringComparison.Ordinal)) + { + // Highlight and scroll to item + item.Focus(); + ScrollViewTo(item); + break; + } + } + } + /// /// Sorts the items list (by item name by default). ///