Esempio n. 1
0
        /// <summary>Replaces the child at the specific position with the provided node.</summary>
        /// <param name="index">Zero-based position.</param>
        /// <param name="node">The node to add.</param>
        /// <returns>True if it succeeds, false if it fails.</returns>
        public virtual bool ReplaceChildNode(int index, BaseNode node)
        {
            if (node == null)
            {
                return(false);
            }
            if (index < 0 || index >= nodes.Count)
            {
                return(false);
            }

            var oldNode = nodes[index];

            node.CopyFromNode(oldNode);

            node.ParentNode = this;
            node.ClearSelection();

            nodes[index] = node;

            var oldSize = oldNode.MemorySize;
            var newSize = node.MemorySize;

            if (newSize < oldSize)
            {
                InsertBytes(index + 1, oldSize - newSize);
            }
            else if (newSize > oldSize)
            {
                //RemoveNodes(index + 1, newSize - oldSize);
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>Replaces the old node with the new node.</summary>
        /// <param name="oldNode">The old node to replacce.</param>
        /// <param name="newNode">The new node.</param>
        /// <param name="additionalCreatedNodes">[out] A list for additional created nodes (see <see cref="ShouldCompensateSizeChanges"/>) or null if not needed.</param>
        public void ReplaceChildNode(BaseNode oldNode, BaseNode newNode, ref List <BaseNode> additionalCreatedNodes)
        {
            Contract.Requires(oldNode != null);
            Contract.Requires(newNode != null);

            CheckCanHandleChildNode(newNode);

            var index = FindNodeIndex(oldNode);

            if (index == -1)
            {
                throw new ArgumentException($"Node {oldNode} is not a child of {this}.");
            }

            newNode.CopyFromNode(oldNode);

            newNode.ParentNode = this;

            nodes[index] = newNode;

            if (ShouldCompensateSizeChanges)
            {
                var oldSize = oldNode.MemorySize;
                var newSize = newNode.MemorySize;

                if (newSize < oldSize)
                {
                    InsertBytes(index + 1, oldSize - newSize, ref additionalCreatedNodes);
                }

                /*else if (newSize > oldSize)
                 * {
                 *      RemoveNodes(index + 1, newSize - oldSize);
                 * }*/
            }

            UpdateOffsets();

            GetParentContainer()?.ChildHasChanged(this);
        }