Beispiel #1
0
        public void QueryAllowedDragPositions(QueryAllowedPositionsEventArgs args)
        {
            args.AllowedCopyPositions = DropLinePosition.None;
            args.AllowedMovePositions = DropLinePosition.None;
            DesignerNodeData sourceNodeData = args.Source as DesignerNodeData;

            if (sourceNodeData != null)
            {
                INode source = sourceNodeData.TreeNode.Node;
                INode target = ((DesignerNode)args.TargetNode).Node;
                if (target.IsValidChild(source))
                {
                    args.AllowedCopyPositions |= DropLinePosition.OnNode;
                    if (!IsNodeContained(source, target, true))
                    {
                        args.AllowedMovePositions |= DropLinePosition.OnNode;
                    }
                }

                if ((args.TargetNode.Parent != null) && target.Parent.IsValidChild(source))
                {
                    args.AllowedCopyPositions |= (DropLinePosition.AboveNode | DropLinePosition.BelowNode);
                    if (!IsNodeContained(source, target.Parent, true) && !Object.ReferenceEquals(target, source))
                    {
                        int index = target.Parent.Children.IndexOf(target);
                        if
                        (
                            (index == 0) ||
                            ((index > 0) && !ReferenceEquals(target.Parent.Children[index - 1], source))
                        )
                        {
                            args.AllowedMovePositions |= DropLinePosition.AboveNode;
                        }
                        if
                        (
                            (index == target.Parent.Children.Count - 1) ||
                            ((index < target.Parent.Children.Count - 1) && !ReferenceEquals(target.Parent.Children[index + 1], source))
                        )
                        {
                            args.AllowedMovePositions |= DropLinePosition.BelowNode;
                        }
                    }
                }
            }
        }
Beispiel #2
0
 protected override void OnDragDrop(DragEventArgs args)
 {
     if (args.Effect != DragDropEffects.None)
     {
         try
         {
             base.OnDragDrop(args);
             DesignerNodeData data = args.Data as DesignerNodeData;
             if
             (
                 (_dropFilter.DropHighlightNode != null) &&
                 (_dropFilter.DropLinePosition != DropLinePosition.None) &&
                 (data != null)
             )
             {
                 if (data.RightButton)
                 {
                     new DesignerTreeDropMenu(data.TreeNode, (DesignerNode)_dropFilter.DropHighlightNode, _dropFilter.DropLinePosition, _dropFilter.DropOperation).Show(this, PointToClient(Control.MousePosition));
                 }
                 else
                 {
                     if (Control.ModifierKeys == Keys.Control)
                     {
                         ((DesignerNode)_dropFilter.DropHighlightNode).CopyFromNode(data.TreeNode, _dropFilter.DropLinePosition);
                     }
                     else
                     {
                         ((DesignerNode)_dropFilter.DropHighlightNode).MoveFromNode(data.TreeNode, _dropFilter.DropLinePosition);
                     }
                 }
             }
             EndDrag();
         }
         catch (Exception exception)
         {
             // must handle exceptions because the framework ignores them
             FormDesigner.Dataphoria.Warnings.AppendError(FormDesigner, exception, false);
             // do not re-throw
         }
     }
 }