コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: SvgDocument.cs プロジェクト: MelvinLervick/r3d
        /// <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;
        }
コード例 #5
0
ファイル: SvgDocument.cs プロジェクト: MelvinLervick/r3d
        /// <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;
        }
コード例 #6
0
ファイル: SvgDocument.cs プロジェクト: MelvinLervick/r3d
        /// <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;
        }