From 02d135053f05bdbf5eaafd94179b8ffe872cf8c8 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sun, 23 Jul 2023 15:10:31 -0500 Subject: [PATCH 1/3] Add scroll to selected asset/content item on asset picker select menu open. --- Source/Editor/GUI/AssetPicker.cs | 36 +++++++++++++++++++++-- Source/Editor/GUI/ItemsListContextMenu.cs | 9 ++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Source/Editor/GUI/AssetPicker.cs b/Source/Editor/GUI/AssetPicker.cs index bfded5380..7447e8472 100644 --- a/Source/Editor/GUI/AssetPicker.cs +++ b/Source/Editor/GUI/AssetPicker.cs @@ -475,22 +475,54 @@ namespace FlaxEditor.GUI if (_type != ScriptType.Null) { // Show asset picker popup - AssetSearchPopup.Show(this, Button1Rect.BottomLeft, IsValid, item => + var popup = AssetSearchPopup.Show(this, Button1Rect.BottomLeft, IsValid, item => { SelectedItem = item; RootWindow.Focus(); Focus(); }); + 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; + } + } + } } else { // Show content item picker popup - ContentSearchPopup.Show(this, Button1Rect.BottomLeft, IsValid, item => + var popup = ContentSearchPopup.Show(this, Button1Rect.BottomLeft, IsValid, item => { SelectedItem = item; RootWindow.Focus(); Focus(); }); + 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; + } + } + } } } else if (_selected != null || _selectedItem != null) diff --git a/Source/Editor/GUI/ItemsListContextMenu.cs b/Source/Editor/GUI/ItemsListContextMenu.cs index ae470235d..12de479bf 100644 --- a/Source/Editor/GUI/ItemsListContextMenu.cs +++ b/Source/Editor/GUI/ItemsListContextMenu.cs @@ -265,6 +265,15 @@ namespace FlaxEditor.GUI _searchBox.Focus(); } + /// + /// Scrolls the scroll panel to a specific Item + /// + /// The item to scroll to. + public void ScrollViewTo(Item item) + { + _scrollPanel.ScrollViewTo(item, true); + } + /// /// Sorts the items list (by item name by default). /// From 12005ad3141c695cdef59bac66920013ec36b925 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sun, 23 Jul 2023 15:20:57 -0500 Subject: [PATCH 2/3] 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). /// From f80b7ee2a52c26a6a8b60d517f25760f7e994513 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sun, 23 Jul 2023 18:58:47 -0500 Subject: [PATCH 3/3] Fix spacing --- Source/Editor/GUI/AssetPicker.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Editor/GUI/AssetPicker.cs b/Source/Editor/GUI/AssetPicker.cs index 39a06cf0b..3e5d22eb0 100644 --- a/Source/Editor/GUI/AssetPicker.cs +++ b/Source/Editor/GUI/AssetPicker.cs @@ -482,9 +482,9 @@ namespace FlaxEditor.GUI Focus(); }); if (_selected != null) - { - var selectedAssetName = Path.GetFileNameWithoutExtension(_selected.Path); - popup.ScrollToAndHighlightItemByName(selectedAssetName); + { + var selectedAssetName = Path.GetFileNameWithoutExtension(_selected.Path); + popup.ScrollToAndHighlightItemByName(selectedAssetName); } } else