/// <summary>Creates a folder that contains dropdown items.</summary>
        /// <param name="name">Name of the folder.</param>
        /// <returns>A <see cref="SelectionNode"/> instance that represents the folder.</returns>
        public SelectionNode CreateChildFolder(string name)
        {
            var child = new SelectionNode(name, this, _parentTree, null, null);

            ChildNodes.Add(child);
            return(child);
        }
        /// <summary>Creates a dropdown item that represents a <see cref="System.Type"/>.</summary>
        /// <param name="name">Name that will show up in the popup.</param>
        /// <param name="type"><see cref="System.Type"/>> this node represents.</param>
        /// <param name="fullTypeName">
        /// Full name of the type. It will show up instead of the short name when performing search.
        /// </param>
        /// <returns>A <see cref="SelectionNode"/> instance that represents the dropdown item.</returns>
        public SelectionNode CreateChildItem(string name, Type type, string fullTypeName)
        {
            var child = new SelectionNode(name, this, _parentTree, type, fullTypeName);

            ChildNodes.Add(child);
            return(child);
        }
Beispiel #3
0
        private void SetSelection(TypeItem[] items, Type selectedType)
        {
            if (selectedType == null)
            {
                SelectedNode = _noneElement;
                return;
            }

            ReadOnlySpan <char> nameOfItemToSelect = default;

            foreach (TypeItem item in items)
            {
                if (item.Type == selectedType)
                {
                    nameOfItemToSelect = item.Path.AsSpan();
                }
            }

            if (nameOfItemToSelect == default)
            {
                return;
            }

            SelectionNode itemToSelect = _root;

            foreach (var part in nameOfItemToSelect.Split('/'))
            {
                itemToSelect = itemToSelect.FindChild(part);
            }

            SelectedNode = itemToSelect;
            _scrollbar.RequestScrollToNode(itemToSelect, Scrollbar.NodePosition.Center);
        }
Beispiel #4
0
 /// <summary>Constructor of a root node that does not have a parent and does not show up in the popup.</summary>
 /// <param name="parentTree">The tree this node belongs to.</param>
 private SelectionNode(SelectionTree parentTree)
 {
     ParentNode   = null;
     _parentTree  = parentTree;
     _name        = string.Empty;
     Type         = null;
     FullTypeName = null;
 }
Beispiel #5
0
        public static NoneElement Create(SelectionTree parentTree)
        {
            SelectionNode root  = CreateRoot(parentTree);
            var           child = new NoneElement(root, parentTree);

            root.ChildNodes.Add(child);
            return(child);
        }
Beispiel #6
0
        private void CreateDropdownItem(TypeItem item)
        {
            (string namespaceName, string typeName) = SplitFullTypeName(item.Path);

            SelectionNode directParentOfNewNode =
                string.IsNullOrEmpty(namespaceName) ? _root : CreateFoldersInPathIfNecessary(namespaceName);

            directParentOfNewNode.CreateChildItem(typeName, item.Type, item.FullTypeName);
        }
        private void ScrollToNodeIfNeeded()
        {
            if (_nodeToScrollTo == null || ScrollCannotBePerformed)
            {
                return;
            }

            ScrollToNode(_nodeToScrollTo.Rect);
            _nodeToScrollTo = null;
        }
Beispiel #8
0
        /// <summary>
        /// Default constructor that creates a child node of another parent node.
        /// </summary>
        /// <param name="name">Name that will show up in the popup.</param>
        /// <param name="parentNode">Parent node of this node.</param>
        /// <param name="parentTree">The tree this node belongs to.</param>
        /// <param name="type"><see cref="System.Type"/>> this node represents.</param>
        /// <param name="fullTypeName">
        /// Full name of the type. It will show up instead of the short name when performing search.
        /// </param>
        protected SelectionNode(
            string name,
            SelectionNode parentNode,
            SelectionTree parentTree,
            Type type,
            string fullTypeName)
        {
            Assert.IsNotNull(name);

            _name        = name;
            ParentNode   = parentNode;
            _parentTree  = parentTree;
            Type         = type;
            FullTypeName = fullTypeName;
        }
Beispiel #9
0
        private SelectionNode CreateFoldersInPathIfNecessary(string path)
        {
            SelectionNode parentNode = _root;

            foreach (string folderName in path.Split('/'))
            {
                SelectionNode folderNode = parentNode.FindChild(folderName);

                if (folderNode == null)
                {
                    folderNode = parentNode.CreateChildFolder(folderName);
                }

                parentNode = folderNode;
            }

            return(parentNode);
        }
Beispiel #10
0
        public SelectionTree(
            SortedSet <TypeItem> items,
            Type selectedType,
            Action <Type> onTypeSelected,
            int searchbarMinItemsCount,
            bool hideNoneElement)
        {
            _root           = SelectionNode.CreateRoot(this);
            _onTypeSelected = onTypeSelected;

            if (!hideNoneElement)
            {
                _noneElement = NoneElement.Create(this);
            }

            SelectionPaths = items.Select(item => item.Path).ToArray();
            FillTreeWithItems(items);
            _drawSearchbar = items.Count >= searchbarMinItemsCount;

            SetSelection(items, selectedType);
        }
        /// <summary>Ask scrollbar to start moving to a node. The process can take several frames.</summary>
        /// <param name="node">The node to scroll to.</param>
        public void RequestScrollToNode(SelectionNode node)
        {
            if (node == null)
            {
                return;
            }

            _nodeToScrollTo = node;

            foreach (SelectionNode parentNode in node.GetParentNodesRecursive(false))
            {
                parentNode.Expanded = true;
            }

            if (ScrollCannotBePerformed)
            {
                return;
            }

            ScrollToNode(node.Rect);
            _nodeToScrollTo = null;
        }
Beispiel #12
0
 private NoneElement(SelectionNode root, SelectionTree parentTree)
     : base(TypeReference.NoneElement, root, parentTree, null, null)
 {
 }