Exemple #1
0
        private bool DeleteElement(SvgElement element, bool deleteFromParent)
        {
            if (element == null)
            {
                return(false);
            }

            var parent = element.GetParent();

            if (parent == null)
            {
                // root node cannot be delete!
                ErrorMessage = "root node cannot be delete!";
                return(false);
            }

            // set the Next reference of the previous
            if (element.GetPrevious() != null)
            {
                element.GetPrevious().SetNext(element.GetNext());
            }

            // set the Previous reference of the next
            if (element.GetNext() != null)
            {
                element.GetNext().SetPrevious(element.GetPrevious());
            }

            // check if the element is the first child
            // the deleteFromParent flag is used to avoid deleting
            // all parent-child relationship. This is used in the Cut
            // operation where the subtree can be pasted
            if (deleteFromParent)
            {
                if (IsFirstChild(element))
                {
                    // set the Child reference of the parent to the next
                    element.GetParent().SetChild(element.GetNext());
                }
            }

            // delete its children
            var child = element.GetChild();

            while (child != null)
            {
                DeleteElement(child, false);
                child = child.GetNext();
            }

            // delete the element from the colloection
            svgDocumentElements.Remove(element.GetInternalId());

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// It moves the element before its current previous sibling.
        /// </summary>
        /// <param name="element">Element to be moved.</param>
        /// <returns>
        /// true if the operation succeeded.
        /// </returns>
        public bool ElementPositionUp(SvgElement element)
        {
            var parent = element.GetParent();

            if (parent == null)
            {
                ErrorMessage = "Root node cannot be moved";
                return(false);
            }

            if (IsFirstChild(element))
            {
                ErrorMessage = "Element is already at the first position";
                return(false);
            }

            var        next      = element.GetNext();
            var        previous  = element.GetPrevious();
            SvgElement previous2 = null;

            element.SetNext(null);
            element.SetPrevious(null);

            // fix Next
            if (next != null)
            {
                next.SetPrevious(previous);
            }

            // fix Previous
            if (previous != null)
            {
                previous.SetNext(next);
                previous2 = previous.GetPrevious();
                previous.SetPrevious(element);

                // check if the Previous is the first child
                if (IsFirstChild(previous))
                {
                    // if yes the moved element has to became the new first child
                    if (previous.GetParent() != null)
                    {
                        previous.GetParent().SetChild(element);
                    }
                }
            }

            // fix Previous/Previous
            if (previous2 != null)
            {
                previous2.SetNext(element);
            }

            // fix Element
            element.SetNext(previous);
            element.SetPrevious(previous2);

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// It moves the element after its current next sibling.
        /// </summary>
        /// <param name="element">Element to be moved.</param>
        /// <returns>
        /// true if the operation succeeded.
        /// </returns>
        public bool ElementPositionDown(SvgElement element)
        {
            var parent = element.GetParent();

            if (parent == null)
            {
                ErrorMessage = "Root node cannot be moved";
                return(false);
            }

            if (IsLastSibling(element))
            {
                ErrorMessage = "Element is already at the last sibling position";
                return(false);
            }

            var        next     = element.GetNext();
            SvgElement next2    = null;
            var        previous = element.GetPrevious();

            // fix Next
            if (next != null)
            {
                next.SetPrevious(element.GetPrevious());
                next2 = next.GetNext();
                next.SetNext(element);
            }

            // fix Previous
            if (previous != null)
            {
                previous.SetNext(next);
            }

            // fix Element
            if (IsFirstChild(element))
            {
                parent.SetChild(next);
            }

            element.SetPrevious(next);
            element.SetNext(next2);

            if (next2 != null)
            {
                next2.SetPrevious(element);
            }

            return(true);
        }
Exemple #4
0
        /// <summary>
        /// It moves the element one level up in the tree hierarchy.
        /// </summary>
        /// <param name="element">Element to be moved.</param>
        /// <returns>
        /// true if the operation succeeded.
        /// </returns>
        public bool ElementLevelUp(SvgElement element)
        {
            var parent = element.GetParent();

            if (parent == null)
            {
                ErrorMessage = "Root node cannot be moved";
                return(false);
            }

            if (parent.GetParent() == null)
            {
                ErrorMessage = "An element cannot be moved up to the root";
                return(false);
            }

            var next = element.GetNext();

            // the first child of the parent became the next
            parent.SetChild(next);

            if (next != null)
            {
                next.SetPrevious(null);
            }

            // get the last sibling of the parent
            var last = GetLastSibling(parent);

            if (last != null)
            {
                last.SetNext(element);
            }

            element.SetParent(parent.GetParent());
            element.SetPrevious(last);
            element.SetNext(null);

            return(true);
        }
Exemple #5
0
        private bool DeleteElement(SvgElement element, bool deleteFromParent)
        {
            if ( element == null )
            {
                return false;
            }

            var parent = element.GetParent();
            if ( parent == null )
            {
                // root node cannot be delete!
                ErrorMessage = "root node cannot be delete!";
                return false;
            }

            // set the Next reference of the previous
            if ( element.GetPrevious() != null )
            {
                element.GetPrevious().SetNext(element.GetNext());
            }

            // set the Previous reference of the next
            if ( element.GetNext() != null )
            {
                element.GetNext().SetPrevious(element.GetPrevious());
            }

            // check if the element is the first child
            // the deleteFromParent flag is used to avoid deleting
            // all parent-child relationship. This is used in the Cut
            // operation where the subtree can be pasted
            if ( deleteFromParent )
            {
                if ( IsFirstChild(element) )
                {
                    // set the Child reference of the parent to the next
                    element.GetParent().SetChild(element.GetNext());
                }
            }

            // delete its children
            var child = element.GetChild();

            while ( child != null )
            {
                DeleteElement(child, false);
                child = child.GetNext();
            }

            // delete the element from the colloection
            svgDocumentElements.Remove(element.GetInternalId());

            return true;
        }
Exemple #6
0
        /// <summary>
        /// It moves the element before its current previous sibling.
        /// </summary>
        /// <param name="element">Element to be moved.</param>
        /// <returns>
        /// true if the operation succeeded.
        /// </returns>
        public bool ElementPositionUp(SvgElement element)
        {
            var parent = element.GetParent();
            if ( parent == null )
            {
                ErrorMessage = "Root node cannot be moved";
                return false;
            }

            if ( IsFirstChild(element) )
            {
                ErrorMessage = "Element is already at the first position";
                return false;
            }

            var next = element.GetNext();
            var previous = element.GetPrevious();
            SvgElement previous2 = null;

            element.SetNext(null);
            element.SetPrevious(null);

            // fix Next
            if ( next != null )
            {
                next.SetPrevious(previous);
            }

            // fix Previous
            if ( previous != null )
            {
                previous.SetNext(next);
                previous2 = previous.GetPrevious();
                previous.SetPrevious(element);

                // check if the Previous is the first child
                if ( IsFirstChild(previous) )
                {
                    // if yes the moved element has to became the new first child
                    if ( previous.GetParent() != null )
                    {
                        previous.GetParent().SetChild(element);
                    }
                }
            }

            // fix Previous/Previous
            if ( previous2 != null )
            {
                previous2.SetNext(element);
            }

            // fix Element
            element.SetNext(previous);
            element.SetPrevious(previous2);

            return true;
        }
Exemple #7
0
        /// <summary>
        /// It moves the element after its current next sibling.
        /// </summary>
        /// <param name="element">Element to be moved.</param>
        /// <returns>
        /// true if the operation succeeded.
        /// </returns>
        public bool ElementPositionDown(SvgElement element)
        {
            var parent = element.GetParent();
            if ( parent == null )
            {
                ErrorMessage = "Root node cannot be moved";
                return false;
            }

            if ( IsLastSibling(element) )
            {
                ErrorMessage = "Element is already at the last sibling position";
                return false;
            }

            var next = element.GetNext();
            SvgElement next2 = null;
            var previous = element.GetPrevious();

            // fix Next
            if ( next != null )
            {
                next.SetPrevious(element.GetPrevious());
                next2 = next.GetNext();
                next.SetNext(element);
            }

            // fix Previous
            if ( previous != null )
            {
                previous.SetNext(next);
            }

            // fix Element
            if ( IsFirstChild(element) )
            {
                parent.SetChild(next);
            }

            element.SetPrevious(next);
            element.SetNext(next2);

            if ( next2 != null )
            {
                next2.SetPrevious(element);
            }

            return true;
        }
Exemple #8
0
        /// <summary>
        /// It moves the element one level up in the tree hierarchy.
        /// </summary>
        /// <param name="element">Element to be moved.</param>
        /// <returns>
        /// true if the operation succeeded.
        /// </returns>
        public bool ElementLevelUp(SvgElement element)
        {
            var parent = element.GetParent();
            if ( parent == null )
            {
                ErrorMessage = "Root node cannot be moved";
                return false;
            }

            if ( parent.GetParent() == null )
            {
                ErrorMessage = "An element cannot be moved up to the root";
                return false;
            }

            var next = element.GetNext();

            // the first child of the parent became the next
            parent.SetChild(next);

            if ( next != null )
            {
                next.SetPrevious(null);
            }

            // get the last sibling of the parent
            var last = GetLastSibling(parent);
            if ( last != null )
            {
                last.SetNext(element);
            }

            element.SetParent(parent.GetParent());
            element.SetPrevious(last);
            element.SetNext(null);

            return true;
        }