using System; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UIElements; using UnityEditor.UIElements; namespace UnityEditor.Searcher { class SearcherControl : VisualElement { // Window constants. const string k_WindowTitleLabel = "windowTitleLabel"; const string k_WindowDetailsPanel = "windowDetailsVisualContainer"; const string k_WindowResultsScrollViewName = "windowResultsScrollView"; const string k_WindowSearchTextFieldName = "searchBox"; const string k_WindowAutoCompleteLabelName = "autoCompleteLabel"; const string k_WindowSearchIconName = "searchIcon"; const string k_WindowResizerName = "windowResizer"; const string kWindowSearcherPanel = "searcherVisualContainer"; const int k_TabCharacter = 9; Label m_AutoCompleteLabel; IEnumerable m_Results; List m_VisibleResults; HashSet m_ExpandedResults; HashSet m_MultiSelectSelection; Dictionary m_SearchItemToVisualToggle; Searcher m_Searcher; string m_SuggestedTerm; string m_Text = string.Empty; Action m_SelectionCallback; Action m_AnalyticsDataCallback; Func, string, SearcherItem> m_SearchResultsFilterCallback; ListView m_ListView; TextField m_SearchTextField; VisualElement m_SearchTextInput; VisualElement m_DetailsPanel; VisualElement m_SearcherPanel; VisualElement m_ContentContainer; Button m_ConfirmButton; internal Label TitleLabel { get; } internal VisualElement Resizer { get; } public SearcherControl() { // Load window template. var windowUxmlTemplate = Resources.Load("SearcherWindow"); // Clone Window Template. var windowRootVisualElement = windowUxmlTemplate.CloneTree(); windowRootVisualElement.AddToClassList("content"); windowRootVisualElement.StretchToParentSize(); // Add Window VisualElement to window's RootVisualContainer Add(windowRootVisualElement); m_VisibleResults = new List(); m_ExpandedResults = new HashSet(); m_MultiSelectSelection = new HashSet(); m_SearchItemToVisualToggle = new Dictionary(); m_ListView = this.Q(k_WindowResultsScrollViewName); if (m_ListView != null) { m_ListView.bindItem = Bind; m_ListView.RegisterCallback(SetSelectedElementInResultsList); #if UNITY_2020_1_OR_NEWER m_ListView.onItemsChosen += obj => OnListViewSelect((SearcherItem)obj.FirstOrDefault()); m_ListView.onSelectionChange += selectedItems => m_Searcher.Adapter.OnSelectionChanged(selectedItems.OfType().ToList()); #else m_ListView.onItemChosen += obj => OnListViewSelect((SearcherItem)obj); m_ListView.onSelectionChanged += selectedItems => m_Searcher.Adapter.OnSelectionChanged(selectedItems.OfType()); #endif m_ListView.focusable = true; m_ListView.tabIndex = 1; } m_DetailsPanel = this.Q(k_WindowDetailsPanel); TitleLabel = this.Q