Beispiel #1
0
 //create link
 private void DragLink()
 {
     //when you drag from datatree in simulation to datatree in a toolbox the PathsBeingDragged disappear and it causes an error. I have done this to avoid the error but creating a link does not really make sense in this situation anywhere. Instead just doing nothing makes more sense.
     if ((PathsBeingDragged != null))
     {
         //add all the dragged node as a link to the destination node
         foreach (string DraggedPath in PathsBeingDragged)
         {
             ApsimFile.Component Comp = Controller.ApsimData.Find(DraggedPath);
             if ((Comp != null) && !Comp.IsAncestorOf(Controller.Selection))
             {
                 Controller.Selection.AddShortCut(Comp);
                 //add one of the dragged nodes as a link to the destination node (destination node is stored as the current selection in the controller)
             }
         }
     }
 }
Beispiel #2
0
        private void TreeView_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
        {
            // --------------------------------------------------
            // User has dragged a node over us - allow drop?
            // --------------------------------------------------

            //Make sure you are actually dragging something
            //check the "data" Drag Event Argument
            if (e.Data.GetDataPresent(typeof(System.String)))
            {
                //If the mouse is currently dragging over a node and not over blank area
                Point pt = PointToClient(new Point(e.X, e.Y));
                //get the drop location
                TreeNode DestinationNode = GetNodeAt(pt);
                //find the node closest to the drop location

                if ((DestinationNode != null))
                {
                    //Work out the type of left drag this is (copy, move, create link/shortcut), and store it in the "Effect" Drag Event Argument
                    string FullXML = (string)e.Data.GetData(DataFormats.Text);
                    ApsimFile.Component DropComp = Controller.ApsimData.Find(GetPathFromNode(DestinationNode));
                    //get the corresponding component for the destination node.
                    //if allowed to drop this node onto this destination node
                    if (DropComp.AllowAdd(FullXML))
                    {
                        if ((PathsBeingDragged != null) && PathsBeingDragged.Count > 0 && (Control.ModifierKeys & Keys.Shift) == Keys.Shift)
                        {
                            e.Effect = DragDropEffects.Move;
                            //these DragDropEffects are just the changes to the mouse icon when you hover over a node whilst dragging
                        }
                        else if ((PathsBeingDragged != null) && (PathsBeingDragged.Count > 0) && (Control.ModifierKeys & Keys.Alt) == Keys.Alt)
                        {
                            bool isOk = true;
                            foreach (string DraggedPath in PathsBeingDragged)
                            {
                                ApsimFile.Component Comp = Controller.ApsimData.Find(DraggedPath);
                                if ((Comp != null) && Comp.IsAncestorOf(DropComp))
                                {
                                    isOk = false;
                                }
                            }
                            if (isOk)
                            {
                                e.Effect = DragDropEffects.Link;
                            }
                            else
                            {
                                e.Effect = DragDropEffects.None;
                            }
                        }
                        else
                        {
                            e.Effect = DragDropEffects.Copy;
                        }
                        //if NOT allowed to drop this node onto this destination node
                    }
                    else
                    {
                        e.Effect = DragDropEffects.None;
                        //display circle with line through it symbol
                    }

                    //If this is a right mouse drag, set the global variable flag
                    //you have to do this test in "DragOver" event because the DragEventArgs disappear once the "DragDrop" event occurs [even thought it has a DragEventArgs parameter]
                    if ((e.KeyState == 2))
                    {
                        isRightBtnDrag = true;
                        //set the flag to true
                    }
                }
            }
        }