Example #1
0
        private void MoveNode(NodeWriteAccess nodeToMove, NodeWriteAccess targetNode, DropLocation operation)
        {
            var siblings = targetNode.Siblings;
            var dropPos  = siblings.IndexOf(targetNode);

            if (operation == DropLocation.After)
            {
                dropPos++;
            }

            if (siblings.Contains(nodeToMove))
            {
                var oldPos = siblings.IndexOf(nodeToMove);
                if (oldPos < dropPos)
                {
                    // ObservableCollection first removes the item and then reinserts which invalidates the index
                    dropPos--;
                }

                siblings.Move(oldPos, dropPos);
            }
            else
            {
                if (dropPos < siblings.Count)
                {
                    ChangeParent(nodeToMove, n => siblings.Insert(dropPos, n), targetNode.GetParent());
                }
                else
                {
                    ChangeParent(nodeToMove, n => siblings.Add(n), targetNode.GetParent());
                }
            }
        }
Example #2
0
        private void ChangeParent(NodeWriteAccess nodeToMove, Action <NodeWriteAccess> insertionOperation, NodeWriteAccess newParent)
        {
            var oldParent = nodeToMove.GetParent();

            oldParent.Children.Remove(nodeToMove);

            insertionOperation(nodeToMove);

            nodeToMove.SetParent(newParent.Node);
        }
Example #3
0
        public void ApplyDrop(NodeDropRequest request)
        {
            var droppedNode = new NodeWriteAccess(request.DroppedNode);
            var dropTarget  = new NodeWriteAccess(request.DropTarget);

            if (request.DropTarget == myRoot)
            {
                ChangeParent(droppedNode, n => myRoot.Children.Add(n), myRoot);
            }
            else if (request.Location == DropLocation.Before || request.Location == DropLocation.After)
            {
                MoveNode(droppedNode, dropTarget, request.Location);
            }
            else
            {
                ChangeParent(droppedNode, n => dropTarget.Children.Add(n), dropTarget);
            }
        }
Example #4
0
 public bool Contains(NodeWriteAccess node)
 {
     return(myCollection.Contains(node.Node));
 }
Example #5
0
 public int IndexOf(NodeWriteAccess node)
 {
     return(myCollection.IndexOf(node.Node));
 }
Example #6
0
 public void Remove(NodeWriteAccess node)
 {
     (( IList )myCollection).Remove(node.Node);
 }
Example #7
0
 public void Insert(int pos, NodeWriteAccess node)
 {
     (( IList )myCollection).Insert(pos, node.Node);
 }
Example #8
0
 public void Add(NodeWriteAccess node)
 {
     (( IList )myCollection).Add(node.Node);
 }
Example #9
0
        public DragDropBehavior(INode root)
        {
            Contract.RequiresNotNull(root, "root");

            myRoot = new NodeWriteAccess(root);
        }