Ejemplo n.º 1
0
        public DataElement MoveTo(DataElementContainer newParent, int index)
        {
            // Locate any fixups so we can update them
            // Move element
            DataElement newElem;

            DataElementContainer oldParent = this.parent;

            string newName = this.name;

            for (int i = 0; newParent.ContainsKey(newName); i++)
            {
                newName = this.name + "_" + i;
            }

            oldParent.RemoveAt(oldParent.IndexOf(this));

            if (newName == this.name)
            {
                newElem = this;
            }
            else
            {
                newElem = this.Clone(newName);
                this.ClearRelations();
            }

            newParent.Insert(index, newElem);

            foreach (Relation relation in newElem.relations)
            {
                if (relation.Of == newElem)
                {
                    relation.OfName = newElem.fullName;
                }

                if (relation.From == newElem)
                {
                    relation.FromName = newElem.fullName;
                }
            }

            return(newElem);
        }
Ejemplo n.º 2
0
        private DataElement MoveTo(DataElementContainer newParent, int index)
        {
            DataElementContainer oldParent = this.parent;

            if (oldParent == newParent)
            {
                int oldIdx = oldParent.IndexOf(this);
                oldParent.RemoveAt(oldIdx);
                if (oldIdx < index)
                {
                    --index;
                }
                newParent.Insert(index, this);
                return(this);
            }

            string newName = this.name;

            for (int i = 0; newParent.ContainsKey(newName); i++)
            {
                newName = this.name + "_" + i;
            }

            DataElement newElem;

            if (newName == this.name)
            {
                newElem = this;
            }
            else
            {
                newElem = this.Clone(newName);

                // We are "moving" the element, but doing so by cloning
                // into a new element.  The clone will duplicate relations
                // that reach outside of the element tree, so we need to
                // clean up all old relations that were inside
                // the old element tree.

                ClearBindings(true);
            }

            // Save off relations
            var relations = newElem.relations.Of <Binding>().ToArray();

            oldParent.RemoveAt(oldParent.IndexOf(this));
            newParent.Insert(index, newElem);

            // When an element is moved, the name can change.
            // Additionally, the resolution algorithm might not
            // be able to locate the proper element, so set
            // the 'OfName' to the full name of the new element.

            foreach (var rel in relations)
            {
                rel.OfName = newElem.fullName;
                rel.Resolve();
            }

            return(newElem);
        }