Example #1
0
        private static void AddChildrenToLightStack(LightStack <SkipTreeNode> stack, SkipTreeNode parent, bool includeDisabled)
        {
            SkipTreeNode ptr = parent.firstChild;

            while (ptr != null)
            {
                if (includeDisabled || !ptr.isDisabled)
                {
                    stack.Push(ptr);
                }

                ptr = ptr.nextSibling;
            }
        }
Example #2
0
        public void RemoveHierarchy(IHierarchical item)
        {
            SkipTreeNode              node;
            IHierarchical             element = item.Element;
            LightStack <SkipTreeNode> stack   = LightStack <SkipTreeNode> .Get();

            SkipTreeNode parent = FindParent(item) ?? root;

            if (!nodeMap.TryGetValue(element.UniqueId, out node))
            {
                SkipTreeNode trail = null;
                SkipTreeNode ptr   = parent.firstChild;
                while (ptr != null)
                {
                    if (IsDescendantOf(ptr.item, item))
                    {
                        if (ptr == parent.firstChild)
                        {
                            parent.firstChild = ptr.nextSibling;
                        }
                        else if (trail != null)
                        {
                            trail.nextSibling = ptr.nextSibling;
                        }

                        stack.Push(ptr);
                    }
                    else
                    {
                        trail = ptr;
                    }

                    ptr = ptr.nextSibling;
                }
            }
            else
            {
                SkipTreeNode nodeNext = node.nextSibling;
                SkipTreeNode nodePrev = FindPreviousSibling(node);

                if (nodePrev != null)
                {
                    nodePrev.nextSibling = nodeNext;
                }
                else if (parent.firstChild == node)
                {
                    parent.firstChild = nodeNext;
                }

                stack.Push(node);
            }

            while (stack.Count > 0)
            {
                SkipTreeNode current = stack.Pop();
                nodeMap.Remove(current.item.UniqueId);
                AddChildrenToLightStack(stack, current, true);
            }

            onTreeChanged?.Invoke(TreeChangeType.HierarchyRemoved);
            LightStack <SkipTreeNode> .Release(ref stack);
        }