Beispiel #1
0
        // Drop event.
        // Move Objects to new parents on drag success.
        private void Dropped(Object sender, ModelDropEventArgs e)
        {
            e.Handled = true;
            switch (e.DropTargetLocation)
            {
            case DropTargetLocation.None:
                DragDropMoveNodes(null, e.SourceModels);
                break;

            case DropTargetLocation.Item:
                DragDropMoveNodes(e.TargetModel as BaseTreeNode, e.SourceModels);
                break;

            default:
                return;
            }

            // TODO:
            // We might not be able to use RefreshObjects() if we change the target parent.
            e.RefreshObjects();
        }
Beispiel #2
0
 private void PluginTree_ModelDropped(object sender, ModelDropEventArgs e)
 {
     if (e.DropTargetLocation == DropTargetLocation.Item)
     {
         var group = e.TargetModel as IGroupRecord;
         if (group == null)
         {
             return;
         }
         var objects = new List <BaseRecord>();
         foreach (IRecord record in e.SourceModels)
         {
             if (e.Effect == DragDropEffects.Copy)
             {
                 var r = record.Clone() as BaseRecord;
                 group.AddRecord(r);
                 objects.Add(r);
             }
             else if (e.Effect == DragDropEffects.Move)
             {
                 var r = record as BaseRecord;
                 if (r != null && r.Parent.DeleteRecord(r))
                 {
                     group.AddRecord(r);
                     objects.Add(r);
                 }
             }
         }
         e.RefreshObjects();
         PluginTree.SelectObject(objects);
         PluginTree.RefreshObject(group);
         PluginTree.RefreshObjects(objects);
     }
     else if (e.DropTargetLocation == DropTargetLocation.AboveItem ||
              e.DropTargetLocation == DropTargetLocation.BelowItem)
     {
         int offset = e.DropTargetLocation == DropTargetLocation.BelowItem ? +1 : 0;
         var rec    = (e.TargetModel as IRecord);
         if (rec == null)
         {
             return;
         }
         var group = rec.Parent as IGroupRecord;
         if (group == null)
         {
             return;
         }
         int idx                   = group.IndexOf(rec as BaseRecord) + offset;
         var refreshObjects        = new List <BaseRecord>();
         var selObjects            = new List <BaseRecord>();
         IEnumerable <IRecord> itr = e.SourceModels.OfType <IRecord>();
         if (e.DropTargetLocation == DropTargetLocation.BelowItem)
         {
             itr = itr.Reverse();
         }
         foreach (IRecord record in itr)
         {
             if (e.Effect == DragDropEffects.Copy)
             {
                 var r = record.Clone() as BaseRecord;
                 group.InsertRecord(idx, r);
                 selObjects.Add(r);
             }
             else if (e.Effect == DragDropEffects.Move)
             {
                 var r = record as BaseRecord;
                 var p = r.Parent;
                 if (r.Parent.DeleteRecord(r))
                 {
                     idx = group.IndexOf(rec as BaseRecord) + offset;
                     group.InsertRecord(idx, r);
                     selObjects.Add(r);
                 }
             }
         }
         e.RefreshObjects();
         PluginTree.SelectObject(selObjects);
         PluginTree.RefreshObject(group);
         PluginTree.RefreshObjects(selObjects);
     }
 }