public void StackNodeContainsAddedElements()
        {
            // Create a stack
            StackNode stack = CreateFilteredStackNode(k_DefaultX, k_DefaultY);
            Node      footer;

            // Verify that nodes are properly added to the stack
            stack.AddElement(m_Node1);
            stack.AddElement(m_Node2);
            stack.InsertElement(0, m_Node3);
            stack.InsertElement(0, footer = new FooterNode());

            Assert.AreEqual(4, stack.childCount);
            Assert.AreEqual(stack, m_Node1.parent);
            Assert.AreEqual(stack, m_Node2.parent);
            Assert.AreEqual(stack, m_Node3.parent);
            Assert.AreEqual(stack, footer.parent);
            Assert.AreEqual(0, stack.IndexOf(m_Node3));
            // Verify that the footer is added at the end of the stack even though we tried to insert it at the begining
            Assert.AreEqual(stack.childCount - 1, stack.IndexOf(footer));
        }
        public bool OnSelectEntry(SearchTreeEntry entry, SearchWindowContext context)
        {
            if (!(entry is SearchTreeGroupEntry))
            {
                if (!GraphViewStaticBridge.HasGUIView(graphView))
                {
                    return(false);
                }

                MathNode node = ScriptableObject.CreateInstance(entry.userData as Type) as MathNode;

                AddNode(node);
                Node nodeUI = CreateNode(node) as Node;
                if (nodeUI != null)
                {
                    if (m_InsertStack != null)
                    {
                        MathStackNode stackNode = m_InsertStack.userData as MathStackNode;

                        stackNode.InsertNode(m_InsertIndex, node);
                        m_InsertStack.InsertElement(m_InsertIndex, nodeUI);
                    }
                    else
                    {
                        graphView.AddElement(nodeUI);

                        Vector2 pointInWindow = context.screenMousePosition - position.position;
                        Vector2 pointInGraph  = nodeUI.parent.WorldToLocal(pointInWindow);

                        nodeUI.SetPosition(new Rect(pointInGraph, Vector2.zero)); // it's ok to pass zero here because width/height is dynamic
                    }
                    nodeUI.Select(graphView, false);
                }
                else
                {
                    Debug.LogError("Failed to create element for " + node);
                    return(false);
                }

                return(true);
            }
            return(false);
        }