void Expand(SearcherItem item)
        {
            m_ExpandedResults.Add(item);

            RegenerateVisibleResults();
            HideUnexpandedItems();

            RefreshListView();
        }
        /// <inheritdoc/>
        public override IEnumerable <SearcherItem> PerformSearch(string query,
                                                                 IReadOnlyList <SearcherItem> filteredItems)
        {
            var searchQuery = m_QueryEngine.Parse("\"" + query + "\""); // TODO add support for "doc:" filter?

            m_CurrentItem = null;
            var searchResults = searchQuery.Apply(filteredItems);

            return(searchResults);
        }
 void OnListViewSelect(SearcherItem item)
 {
     if (!m_Searcher.Adapter.MultiSelectEnabled)
     {
         m_SelectionCallback(item);
     }
     else
     {
         ToggleItemForMultiSelect(item, !m_MultiSelectSelection.Contains(item));
     }
 }
Example #4
0
        public virtual VisualElement Bind(VisualElement element, SearcherItem item, ItemExpanderState expanderState, string query)
        {
            var indent = element.Q <VisualElement>("itemIndent");

            indent.style.width = item.Depth * k_IndentDepthFactor;

            var expander = element.Q <VisualElement>("itemChildExpander");

            var icon = expander.Query("expanderIcon").First();

            icon.ClearClassList();

            switch (expanderState)
            {
            case ItemExpanderState.Expanded:
                icon.AddToClassList("Expanded");
                break;

            case ItemExpanderState.Collapsed:
                icon.AddToClassList("Collapsed");
                break;
            }

            var nameLabelsContainer = element.Q <VisualElement>("labelsContainer");

            nameLabelsContainer.Clear();

            var iconElement = element.Q <VisualElement>("itemIconVisualElement");

            iconElement.style.backgroundImage = item.Icon;
            if (item.Icon == null && item.CollapseEmptyIcon)
            {
                iconElement.style.display = DisplayStyle.None;
            }
            else
            {
                iconElement.style.display = DisplayStyle.Flex;
            }

            nameLabelsContainer.Add(new Label(item.Name));
            // TODO VladN: support highlight for parts of the string?
            // Highlight was disabled because it was inconsistent with fuzzy search
            // and with searching allowing to match item path (e.g. 'Debug/Log message' will be matched by DbgLM)
            // We need to figure out if there's a good way to highlight results.
            //    SearcherHighlighter.HighlightTextIndices(nameLabelsContainer, item.Name, item.lastMatchedIndices);

            element.userData = item;
            element.name     = k_EntryName;

            return(expander);
        }
        static void GetItemsToHide(SearcherItem parent, ref HashSet <SearcherItem> itemsToHide)
        {
            if (!parent.HasChildren)
            {
                itemsToHide.Add(parent);
                return;
            }

            foreach (var child in parent.Children)
            {
                itemsToHide.Add(child);
                GetItemsToHide(child, ref itemsToHide);
            }
        }
 IEnumerable <string> GetSearchData(SearcherItem arg)
 {
     if (arg == null)
     {
         yield break;
     }
     m_CurrentItem = arg;
     foreach (var keysRatio in arg.SearchKeys)
     {
         var items = keysRatio.searchData;
         m_ScoreMultiplier = keysRatio.ratio;
         foreach (var item in items)
         {
             yield return(item);
         }
     }
 }
        bool HasChildResult(SearcherItem item)
        {
            if (m_Results.Contains(item))
            {
                return(true);
            }

            foreach (var child in item.Children)
            {
                if (HasChildResult(child))
                {
                    return(true);
                }
            }

            return(false);
        }
        public static List <SearcherItem> CreateFromFlatList(List <SearcherItem> items)
        {
            List <SearcherItem> searchList = new List <SearcherItem>();

            for (int i = 0; i < items.Count; ++i)
            {
                SearcherItem item       = items[i];
                string[]     pathParts  = item.Name.Split('/');
                SearcherItem searchNode = FindNodeByName(searchList, pathParts[0]);
                if (searchNode == null)
                {
                    searchNode = new SearcherItem(pathParts[0]);
                    searchList.Add(searchNode);
                }
                AddItem(searchNode, item, pathParts);
            }
            return(searchList);
        }
        VisualElement MakeItem()
        {
            VisualElement item = m_Searcher.Adapter.MakeItem();

            if (m_Searcher.Adapter.MultiSelectEnabled)
            {
                var selectionToggle = item.Q <Toggle>("itemToggle");
                if (selectionToggle != null)
                {
                    selectionToggle.RegisterValueChangedCallback(changeEvent =>
                    {
                        SearcherItem searcherItem = item.userData as SearcherItem;
                        ToggleItemForMultiSelect(searcherItem, changeEvent.newValue);
                    });
                }
            }
            return(item);
        }
        void AddResultChildren(SearcherItem item, ISet <SearcherItem> idSet)
        {
            if (!item.HasChildren)
            {
                return;
            }
            if (m_Searcher.Adapter.AddAllChildResults)
            {
                //add all children results for current search term
                // eg "Book" will show both "Cook Book" and "Cooking" as children
                foreach (var child in item.Children)
                {
                    if (!idSet.Contains(child))
                    {
                        idSet.Add(child);
                        m_VisibleResults.Add(child);
                    }

                    AddResultChildren(child, idSet);
                }
            }
            else
            {
                foreach (var child in item.Children)
                {
                    //only add child results if the child matches the search term
                    // eg "Book" will show "Cook Book" but not "Cooking" as a child
                    if (!m_Results.Contains(child))
                    {
                        continue;
                    }

                    if (!idSet.Contains(child))
                    {
                        idSet.Add(child);
                        m_VisibleResults.Add(child);
                    }

                    AddResultChildren(child, idSet);
                }
            }
        }
        private static void AddItem(SearcherItem root, SearcherItem item, string[] pathParts)
        {
            string       itemFullPath      = item.Name;
            string       itemName          = pathParts[pathParts.Length - 1];
            string       currentPath       = string.Empty;
            SearcherItem currentSearchNode = root;

            for (int i = 1; i < pathParts.Length; ++i)
            {
                SearcherItem node = FindNodeByName(currentSearchNode.Children, pathParts[i]);
                if (node == null)
                {
                    node = new SearcherItem(pathParts[i]);
                    currentSearchNode.AddChild(node);
                }
                currentSearchNode = node;
            }
            // Set the user data to the final node, which is guaranteed to correspond to the item.
            currentSearchNode.UserData = item.UserData;
            currentSearchNode.Icon     = item.Icon;
        }
        void Collapse(SearcherItem item)
        {
            // if it's already collapsed or not collapsed
            if (!m_ExpandedResults.Remove(item))
            {
                // this case applies for a left arrow key press
                if (item.Parent != null)
                {
                    SetSelectedElementInResultsList(m_VisibleResults.IndexOf(item.Parent));
                }

                // even if it's a root item and has no parents, do nothing more
                return;
            }

            RegenerateVisibleResults();
            HideUnexpandedItems();

            // TODO: understand what happened
            RefreshListView();

            // RefreshListViewOn();
        }
        void ToggleItemForMultiSelect(SearcherItem item, bool selected)
        {
            if (selected)
            {
                m_MultiSelectSelection.Add(item);
            }
            else
            {
                m_MultiSelectSelection.Remove(item);
            }

            Toggle toggle;

            if (m_SearchItemToVisualToggle.TryGetValue(item, out toggle))
            {
                toggle.SetValueWithoutNotify(selected);
            }

            foreach (var child in item.Children)
            {
                ToggleItemForMultiSelect(child, selected);
            }
        }
Example #14
0
        protected virtual bool Match(string query, IReadOnlyList <string> tokenizedQuery, SearcherItem item, out float score)
        {
            var filter = MatchFilter?.Invoke(item) ?? true;

            return(Match(tokenizedQuery, item.Path, out score) && filter);
        }
Example #15
0
 /// <inheritdoc />
 public override bool Match(SearcherItem item)
 {
     return(m_FilterFunctions.All(f => f(item)));
 }
Example #16
0
        public override void OnInspectorGUI()
        {
            var root     = new SearcherItem("Root");
            var children = new List <SearcherItem>();

            for (var i = 0; i < 10; ++i)
            {
                children.Add(new SearcherItem("B-" + i));
            }

            var child = new SearcherItem("Child", "", children);

            root.AddChild(child);

            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Mouse Position");
                if (EditorGUILayout.DropdownButton(new GUIContent("Button"), FocusType.Passive, GUI.skin.button))
                {
                    var editorWindow       = EditorWindow.focusedWindow;
                    var localMousePosition = Event.current.mousePosition;
                    var worldMousePosition = editorWindow.rootVisualElement.LocalToWorld(localMousePosition);

                    SearcherWindow.Show(
                        editorWindow,
                        new List <SearcherItem> {
                        root
                    },
                        "Mouse Position",
                        item =>
                    {
                        Debug.Log("Searcher item selected: " + (item?.Name ?? "<none>"));
                        return(true);
                    },
                        worldMousePosition);
                }
                EditorGUILayout.EndHorizontal();
            }

            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Button Center");

                var selected = EditorGUILayout.DropdownButton(new GUIContent("Button"), FocusType.Passive, GUI.skin.button);
                if (Event.current.type == EventType.Repaint)
                {
                    m_ButtonRect = GUILayoutUtility.GetLastRect();
                }

                if (selected)
                {
                    var editorWindow      = EditorWindow.focusedWindow;
                    var localButtonCenter = m_ButtonRect.center;
                    var worldButtonCenter = editorWindow.rootVisualElement.LocalToWorld(localButtonCenter);

                    SearcherWindow.Show(
                        editorWindow,
                        new List <SearcherItem> {
                        root
                    },
                        "Button Center",
                        item =>
                    {
                        Debug.Log("Searcher item selected: " + (item?.Name ?? "<none>"));
                        return(true);
                    },
                        worldButtonCenter);
                }

                EditorGUILayout.EndHorizontal();
            }
        }