Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5744


Ignore:
Timestamp:
03/18/11 01:38:23 (14 years ago)
Author:
swagner
Message:

Implemented dragging of multiple items in all collection views and refactored drag & drop code (#1112)

Location:
trunk/sources
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/CrossValidationView.cs

    r5445 r5744  
    317317    private void algorithmTabPage_DragEnterOver(object sender, DragEventArgs e) {
    318318      e.Effect = DragDropEffects.None;
    319       if (ReadOnly) return;
    320       Type type = e.Data.GetData("Type") as Type;
    321       IAlgorithm algorithm = e.Data.GetData("Value") as IAlgorithm;
    322       if ((type != null) && (typeof(IAlgorithm).IsAssignableFrom(type)) &&
    323         algorithm != null && Content.ProblemType.IsAssignableFrom(algorithm.Problem.GetType())) {
     319      IAlgorithm algorithm = e.Data.GetData("HeuristicLab") as IAlgorithm;
     320      if (!ReadOnly && (algorithm != null) && Content.ProblemType.IsAssignableFrom(algorithm.Problem.GetType())) {
    324321        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    325322        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    326         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    327         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    328         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     323        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     324        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     325        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    329326      }
    330327    }
    331328    private void algorithmTabPage_DragDrop(object sender, DragEventArgs e) {
    332329      if (e.Effect != DragDropEffects.None) {
    333         IAlgorithm algorithm = e.Data.GetData("Value") as IAlgorithm;
    334         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) algorithm = (IAlgorithm)algorithm.Clone();
     330        IAlgorithm algorithm = e.Data.GetData("HeuristicLab") as IAlgorithm;
     331        if (e.Effect.HasFlag(DragDropEffects.Copy)) algorithm = (IAlgorithm)algorithm.Clone();
    335332        Content.Algorithm = algorithm;
    336333      }
     
    339336    private void algorithmProblemTabPage_DragEnterOver(object sender, DragEventArgs e) {
    340337      e.Effect = DragDropEffects.None;
    341       if (ReadOnly) return;
    342       Type type = e.Data.GetData("Type") as Type;
    343       if ((type != null) && (Content.ProblemType.IsAssignableFrom(type)) &&
    344         (Content.Algorithm.ProblemType.IsAssignableFrom(type))) {
     338      Type type = e.Data.GetData("HeuristicLab") != null ? e.Data.GetData("HeuristicLab").GetType() : null;
     339      if (!ReadOnly && (type != null) && Content.ProblemType.IsAssignableFrom(type) && Content.Algorithm.ProblemType.IsAssignableFrom(type)) {
    345340        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    346341        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    347         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    348         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    349         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     342        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     343        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     344        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    350345      }
    351346    }
    352347    private void algorithmProblemTabPage_DragDrop(object sender, DragEventArgs e) {
    353348      if (e.Effect != DragDropEffects.None) {
    354         ISingleObjectiveDataAnalysisProblem problem = e.Data.GetData("Value") as ISingleObjectiveDataAnalysisProblem;
    355         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) problem = (ISingleObjectiveDataAnalysisProblem)problem.Clone();
     349        ISingleObjectiveDataAnalysisProblem problem = e.Data.GetData("HeuristicLab") as ISingleObjectiveDataAnalysisProblem;
     350        if (e.Effect.HasFlag(DragDropEffects.Copy)) problem = (ISingleObjectiveDataAnalysisProblem)problem.Clone();
    356351        Content.Problem = problem;
    357352      }
  • trunk/sources/HeuristicLab.Core.Views/3.3/Clipboard.Designer.cs

    r5445 r5744  
    7474      this.listView.DoubleClick += new System.EventHandler(this.listView_DoubleClick);
    7575      this.listView.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView_DragDrop);
    76       this.listView.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView_DragEnterOver);
     76      this.listView.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView_DragEnter);
    7777      this.listView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listView_KeyDown);
    7878      this.listView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.listView_ItemDrag);
    79       this.listView.DragOver += new System.Windows.Forms.DragEventHandler(this.listView_DragEnterOver);
     79      this.listView.DragOver += new System.Windows.Forms.DragEventHandler(this.listView_DragOver);
    8080      //
    8181      // imageList
  • trunk/sources/HeuristicLab.Core.Views/3.3/Clipboard.cs

    r5445 r5744  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
    2425using System.IO;
     
    3536    private TypeSelectorDialog typeSelectorDialog;
    3637    private Dictionary<T, ListViewItem> itemListViewItemMapping;
     38    private bool validDragOperation;
     39    private bool draggedItemsAlreadyContained;
    3740
    3841    private string itemsPath;
     
    264267    }
    265268    private void listView_ItemDrag(object sender, ItemDragEventArgs e) {
    266       ListViewItem listViewItem = (ListViewItem)e.Item;
    267       T item = (T)listViewItem.Tag;
    268       DataObject data = new DataObject();
    269       data.SetData("Type", item.GetType());
    270       data.SetData("Value", item);
    271       if (ReadOnly) {
    272         DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    273       } else {
    274         DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    275         if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
    276           RemoveItem(item);
    277           RebuildImageList();
    278         }
    279       }
    280     }
    281     private void listView_DragEnterOver(object sender, DragEventArgs e) {
     269      List<T> items = new List<T>();
     270      foreach (ListViewItem listViewItem in listView.SelectedItems) {
     271        T item = listViewItem.Tag as T;
     272        if (item != null) items.Add(item);
     273      }
     274
     275      if (items.Count > 0) {
     276        DataObject data = new DataObject();
     277        if (items.Count == 1) data.SetData("HeuristicLab", items[0]);
     278        else data.SetData("HeuristicLab", items);
     279        if (ReadOnly) {
     280          DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
     281        } else {
     282          DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
     283          if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
     284            foreach (T item in items) RemoveItem(item);
     285            RebuildImageList();
     286          }
     287        }
     288      }
     289    }
     290    private void listView_DragEnter(object sender, DragEventArgs e) {
     291      validDragOperation = false;
     292      draggedItemsAlreadyContained = false;
     293      if (e.Data.GetData("HeuristicLab") is T) {
     294        validDragOperation = true;
     295        draggedItemsAlreadyContained = itemListViewItemMapping.ContainsKey((T)e.Data.GetData("HeuristicLab"));
     296      } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     297        validDragOperation = true;
     298        IEnumerable items = (IEnumerable)e.Data.GetData("HeuristicLab");
     299        foreach (object item in items) {
     300          validDragOperation = validDragOperation && (item is T);
     301          draggedItemsAlreadyContained = draggedItemsAlreadyContained || itemListViewItemMapping.ContainsKey((T)item);
     302        }
     303      }
     304      validDragOperation = validDragOperation && !ReadOnly;
     305    }
     306    private void listView_DragOver(object sender, DragEventArgs e) {
    282307      e.Effect = DragDropEffects.None;
    283       Type type = e.Data.GetData("Type") as Type;
    284       T item = e.Data.GetData("Value") as T;
    285       if (!ReadOnly && (type != null) && (item != null)) {
    286         if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    287         else if (((e.KeyState & 4) == 4) && !itemListViewItemMapping.ContainsKey(item)) e.Effect = DragDropEffects.Move;  // SHIFT key
    288         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    289         else if (((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) && !itemListViewItemMapping.ContainsKey(item)) e.Effect = DragDropEffects.Move;
    290         else if (((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) && !itemListViewItemMapping.ContainsKey(item)) e.Effect = DragDropEffects.Link;
     308      if (validDragOperation) {
     309        if (((e.KeyState & 32) == 32) && !draggedItemsAlreadyContained) e.Effect = DragDropEffects.Link;  // ALT key
     310        else if (((e.KeyState & 4) == 4) && !draggedItemsAlreadyContained) e.Effect = DragDropEffects.Move;  // SHIFT key
     311        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     312        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move) && !draggedItemsAlreadyContained) e.Effect = DragDropEffects.Move;
     313        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link) && !draggedItemsAlreadyContained) e.Effect = DragDropEffects.Link;
    291314      }
    292315    }
    293316    private void listView_DragDrop(object sender, DragEventArgs e) {
    294317      if (e.Effect != DragDropEffects.None) {
    295         T item = e.Data.GetData("Value") as T;
    296         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
    297318        try {
    298           AddItem(item);
     319          if (e.Data.GetData("HeuristicLab") is T) {
     320            T item = (T)e.Data.GetData("HeuristicLab");
     321            AddItem(e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item);
     322          } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     323            IEnumerable<T> items = ((IEnumerable)e.Data.GetData("HeuristicLab")).Cast<T>();
     324            foreach (T item in items)
     325              AddItem(e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item);
     326          }
    299327        }
    300328        catch (Exception ex) {
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemArrayView.Designer.cs

    r5445 r5744  
    149149      this.itemsListView.SelectedIndexChanged += new System.EventHandler(this.itemsListView_SelectedIndexChanged);
    150150      this.itemsListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragDrop);
    151       this.itemsListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnterOver);
    152       this.itemsListView.DragOver += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnterOver);
     151      this.itemsListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnter);
     152      this.itemsListView.DragOver += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragOver);
    153153      this.itemsListView.DoubleClick += new System.EventHandler(this.itemsListView_DoubleClick);
    154154      this.itemsListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.itemsListView_KeyDown);
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemArrayView.cs

    r5445 r5744  
    3737    protected Dictionary<T, List<ListViewItem>> itemListViewItemMapping;
    3838    protected TypeSelectorDialog typeSelectorDialog;
     39    protected bool validDragOperation;
    3940
    4041    public new IItemArray<T> Content {
     
    274275    protected virtual void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) {
    275276      if (!Locked) {
    276         ListViewItem listViewItem = (ListViewItem)e.Item;
    277         T item = listViewItem.Tag as T;
    278         if (item != null) {
     277        List<T> items = new List<T>();
     278        foreach (ListViewItem listViewItem in itemsListView.SelectedItems) {
     279          T item = listViewItem.Tag as T;
     280          if (item != null) items.Add(item);
     281        }
     282
     283        if (items.Count > 0) {
    279284          DataObject data = new DataObject();
    280           data.SetData("Type", item.GetType());
    281           data.SetData("Value", item);
     285          if (items.Count == 1) data.SetData("HeuristicLab", items[0]);
     286          else data.SetData("HeuristicLab", items);
    282287          if (Content.IsReadOnly || ReadOnly) {
    283288            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    284289          } else {
    285290            DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    286             if ((result & DragDropEffects.Move) == DragDropEffects.Move)
    287               Content[listViewItem.Index] = null;
     291            if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
     292              foreach (ListViewItem listViewItem in itemsListView.SelectedItems.Cast<ListViewItem>().ToArray())
     293                Content[listViewItem.Index] = null;
     294            }
    288295          }
    289296        }
    290297      }
    291298    }
    292     protected virtual void itemsListView_DragEnterOver(object sender, DragEventArgs e) {
     299    protected virtual void itemsListView_DragEnter(object sender, DragEventArgs e) {
     300      validDragOperation = !Content.IsReadOnly && !ReadOnly && e.Data.GetData("HeuristicLab") is T;
     301    }
     302    protected virtual void itemsListView_DragOver(object sender, DragEventArgs e) {
    293303      e.Effect = DragDropEffects.None;
    294       Type type = e.Data.GetData("Type") as Type;
    295       if (!Content.IsReadOnly && !ReadOnly && (type != null) && (typeof(T).IsAssignableFrom(type))) {
     304      if (validDragOperation) {
    296305        Point p = itemsListView.PointToClient(new Point(e.X, e.Y));
    297306        ListViewItem listViewItem = itemsListView.GetItemAt(p.X, p.Y);
     
    299308          if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    300309          else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    301           else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    302           else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    303           else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     310          else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     311          else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     312          else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    304313        }
    305314      }
     
    307316    protected virtual void itemsListView_DragDrop(object sender, DragEventArgs e) {
    308317      if (e.Effect != DragDropEffects.None) {
    309         T item = e.Data.GetData("Value") as T;
    310         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
    311 
    312318        Point p = itemsListView.PointToClient(new Point(e.X, e.Y));
    313319        ListViewItem listViewItem = itemsListView.GetItemAt(p.X, p.Y);
    314         Content[listViewItem.Index] = item;
     320        T item = e.Data.GetData("HeuristicLab") as T;
     321        Content[listViewItem.Index] = e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item;
    315322      }
    316323    }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.Designer.cs

    r5445 r5744  
    102102      this.itemsListView.SelectedIndexChanged += new System.EventHandler(this.itemsListView_SelectedIndexChanged);
    103103      this.itemsListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragDrop);
    104       this.itemsListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnterOver);
    105       this.itemsListView.DragOver += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnterOver);
     104      this.itemsListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnter);
     105      this.itemsListView.DragOver += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragOver);
    106106      this.itemsListView.DoubleClick += new System.EventHandler(this.itemsListView_DoubleClick);
    107107      this.itemsListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.itemsListView_KeyDown);
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs

    r5445 r5744  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
    2425using System.Linq;
     
    3637    protected Dictionary<T, List<ListViewItem>> itemListViewItemMapping;
    3738    protected TypeSelectorDialog typeSelectorDialog;
     39    protected bool validDragOperation;
    3840
    3941    public new IItemCollection<T> Content {
     
    243245    protected virtual void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) {
    244246      if (!Locked) {
    245         ListViewItem listViewItem = (ListViewItem)e.Item;
    246         T item = listViewItem.Tag as T;
    247         if (item != null) {
     247        List<T> items = new List<T>();
     248        foreach (ListViewItem listViewItem in itemsListView.SelectedItems) {
     249          T item = listViewItem.Tag as T;
     250          if (item != null) items.Add(item);
     251        }
     252
     253        if (items.Count > 0) {
    248254          DataObject data = new DataObject();
    249           data.SetData("Type", item.GetType());
    250           data.SetData("Value", item);
     255          if (items.Count == 1) data.SetData("HeuristicLab", items[0]);
     256          else data.SetData("HeuristicLab", items);
    251257          if (Content.IsReadOnly || ReadOnly) {
    252258            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    253259          } else {
    254260            DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    255             if ((result & DragDropEffects.Move) == DragDropEffects.Move)
    256               Content.Remove(item);
     261            if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
     262              foreach (T item in items) Content.Remove(item);
     263            }
    257264          }
    258265        }
    259266      }
    260267    }
    261     protected virtual void itemsListView_DragEnterOver(object sender, DragEventArgs e) {
     268    protected virtual void itemsListView_DragEnter(object sender, DragEventArgs e) {
     269      validDragOperation = false;
     270      if (e.Data.GetData("HeuristicLab") is T) {
     271        validDragOperation = true;
     272      } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     273        validDragOperation = true;
     274        IEnumerable items = (IEnumerable)e.Data.GetData("HeuristicLab");
     275        foreach (object item in items)
     276          validDragOperation = validDragOperation && (item is T);
     277      }
     278      validDragOperation = validDragOperation && !Content.IsReadOnly && !ReadOnly;
     279    }
     280    protected virtual void itemsListView_DragOver(object sender, DragEventArgs e) {
    262281      e.Effect = DragDropEffects.None;
    263       Type type = e.Data.GetData("Type") as Type;
    264       if (!Content.IsReadOnly && !ReadOnly && (type != null) && (typeof(T).IsAssignableFrom(type))) {
     282      if (validDragOperation) {
    265283        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    266284        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    267         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    268         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    269         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     285        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     286        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     287        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    270288      }
    271289    }
    272290    protected virtual void itemsListView_DragDrop(object sender, DragEventArgs e) {
    273291      if (e.Effect != DragDropEffects.None) {
    274         T item = e.Data.GetData("Value") as T;
    275         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
    276         Content.Add(item);
     292        if (e.Data.GetData("HeuristicLab") is T) {
     293          T item = (T)e.Data.GetData("HeuristicLab");
     294          Content.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item);
     295        } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     296          IEnumerable<T> items = ((IEnumerable)e.Data.GetData("HeuristicLab")).Cast<T>();
     297          foreach (T item in items)
     298            Content.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item);
     299        }
    277300      }
    278301    }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.Designer.cs

    r5445 r5744  
    151151      this.itemsListView.SelectedIndexChanged += new System.EventHandler(this.itemsListView_SelectedIndexChanged);
    152152      this.itemsListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragDrop);
    153       this.itemsListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnterOver);
    154       this.itemsListView.DragOver += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnterOver);
     153      this.itemsListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnter);
     154      this.itemsListView.DragOver += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragOver);
    155155      this.itemsListView.DoubleClick += new System.EventHandler(this.itemsListView_DoubleClick);
    156156      this.itemsListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.itemsListView_KeyDown);
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.cs

    r5445 r5744  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
    2425using System.Drawing;
     
    3738    protected Dictionary<T, List<ListViewItem>> itemListViewItemMapping;
    3839    protected TypeSelectorDialog typeSelectorDialog;
     40    protected bool validDragOperation;
    3941
    4042    public new IItemList<T> Content {
     
    277279    protected virtual void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) {
    278280      if (!Locked) {
    279         ListViewItem listViewItem = (ListViewItem)e.Item;
    280         T item = listViewItem.Tag as T;
    281         if (item != null) {
     281        List<T> items = new List<T>();
     282        foreach (ListViewItem listViewItem in itemsListView.SelectedItems) {
     283          T item = listViewItem.Tag as T;
     284          if (item != null) items.Add(item);
     285        }
     286
     287        if (items.Count > 0) {
    282288          DataObject data = new DataObject();
    283           data.SetData("Type", item.GetType());
    284           data.SetData("Value", item);
     289          if (items.Count == 1) data.SetData("HeuristicLab", items[0]);
     290          else data.SetData("HeuristicLab", items);
    285291          if (Content.IsReadOnly || ReadOnly) {
    286292            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    287293          } else {
    288294            DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    289             if ((result & DragDropEffects.Move) == DragDropEffects.Move)
    290               Content.RemoveAt(listViewItem.Index);
     295            if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
     296              foreach (ListViewItem listViewItem in itemsListView.SelectedItems.Cast<ListViewItem>().ToArray()) {
     297                if (listViewItem.Tag != null) Content.RemoveAt(listViewItem.Index);
     298              }
     299            }
    291300          }
    292301        }
    293302      }
    294303    }
    295     protected virtual void itemsListView_DragEnterOver(object sender, DragEventArgs e) {
     304    protected virtual void itemsListView_DragEnter(object sender, DragEventArgs e) {
     305      validDragOperation = false;
     306      if (e.Data.GetData("HeuristicLab") is T) {
     307        validDragOperation = true;
     308      } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     309        validDragOperation = true;
     310        IEnumerable items = (IEnumerable)e.Data.GetData("HeuristicLab");
     311        foreach (object item in items)
     312          validDragOperation = validDragOperation && (item is T);
     313      }
     314      validDragOperation = validDragOperation && !Content.IsReadOnly && !ReadOnly;
     315    }
     316    protected virtual void itemsListView_DragOver(object sender, DragEventArgs e) {
    296317      e.Effect = DragDropEffects.None;
    297       Type type = e.Data.GetData("Type") as Type;
    298       if (!Content.IsReadOnly && !ReadOnly && (type != null) && (typeof(T).IsAssignableFrom(type))) {
     318      if (validDragOperation) {
    299319        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    300320        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    301         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    302         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    303         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     321        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     322        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     323        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    304324      }
    305325    }
    306326    protected virtual void itemsListView_DragDrop(object sender, DragEventArgs e) {
    307327      if (e.Effect != DragDropEffects.None) {
    308         T item = e.Data.GetData("Value") as T;
    309         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
    310 
    311328        Point p = itemsListView.PointToClient(new Point(e.X, e.Y));
    312329        ListViewItem listViewItem = itemsListView.GetItemAt(p.X, p.Y);
    313         if (listViewItem != null) Content.Insert(listViewItem.Index, item);
    314         else Content.Add(item);
     330
     331        if (e.Data.GetData("HeuristicLab") is T) {
     332          T item = (T)e.Data.GetData("HeuristicLab");
     333          if (listViewItem != null) Content.Insert(listViewItem.Index, e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item);
     334          else Content.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item);
     335        } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     336          IEnumerable<T> items = ((IEnumerable)e.Data.GetData("HeuristicLab")).Cast<T>();
     337          foreach (T item in items) {
     338            if (listViewItem != null) Content.Insert(listViewItem.Index, e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item);
     339            else Content.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item);
     340          }
     341        }
    315342      }
    316343    }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemSetView.cs

    r5445 r5744  
    2020#endregion
    2121
     22using System.Collections;
    2223using System.Windows.Forms;
    2324using HeuristicLab.MainForm;
     
    2829  [Content(typeof(IItemSet<>), false)]
    2930  public partial class ItemSetView<T> : ItemCollectionView<T> where T : class, IItem {
     31    protected bool draggedItemsAlreadyContained;
     32
    3033    public new IItemSet<T> Content {
    3134      get { return (IItemSet<T>)base.Content; }
     
    3740    }
    3841
    39     protected override void itemsListView_DragEnterOver(object sender, DragEventArgs e) {
    40       base.itemsListView_DragEnterOver(sender, e);
    41       if (e.Effect == DragDropEffects.Link || e.Effect == DragDropEffects.Move) {
    42         T item = e.Data.GetData("Value") as T;
    43         if (Content.Contains(item)) e.Effect = DragDropEffects.None;
     42    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
     43      base.itemsListView_DragEnter(sender, e);
     44      draggedItemsAlreadyContained = false;
     45      if (validDragOperation) {
     46        if (e.Data.GetData("HeuristicLab") is T) {
     47          draggedItemsAlreadyContained = Content.Contains((T)e.Data.GetData("HeuristicLab"));
     48        } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     49          IEnumerable items = (IEnumerable)e.Data.GetData("HeuristicLab");
     50          foreach (object item in items)
     51            draggedItemsAlreadyContained = draggedItemsAlreadyContained || Content.Contains((T)item);
     52        }
     53      }
     54    }
     55    protected override void itemsListView_DragOver(object sender, DragEventArgs e) {
     56      e.Effect = DragDropEffects.None;
     57      if (validDragOperation) {
     58        if (((e.KeyState & 32) == 32) && !draggedItemsAlreadyContained) e.Effect = DragDropEffects.Link;  // ALT key
     59        else if (((e.KeyState & 4) == 4) && !draggedItemsAlreadyContained) e.Effect = DragDropEffects.Move;  // SHIFT key
     60        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     61        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move) && !draggedItemsAlreadyContained) e.Effect = DragDropEffects.Move;
     62        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link) && !draggedItemsAlreadyContained) e.Effect = DragDropEffects.Link;
    4463      }
    4564    }
  • trunk/sources/HeuristicLab.Core.Views/3.3/NamedItemCollectionView.cs

    r5445 r5744  
    2020#endregion
    2121
     22using System.Collections;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using System.Windows.Forms;
    2326using HeuristicLab.Collections;
     
    7578
    7679    #region ListView Events
    77     protected override void itemsListView_DragEnterOver(object sender, DragEventArgs e) {
    78       base.itemsListView_DragEnterOver(sender, e);
    79       if (e.Effect != DragDropEffects.None) {
    80         T item = e.Data.GetData("Value") as T;
    81         if ((item == null) || (Content.ContainsKey(item.Name)))
    82           e.Effect = DragDropEffects.None;
     80    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
     81      base.itemsListView_DragEnter(sender, e);
     82      if (validDragOperation) {
     83        if (e.Data.GetData("HeuristicLab") is T) {
     84          validDragOperation = validDragOperation && !Content.ContainsKey(((T)e.Data.GetData("HeuristicLab")).Name);
     85        } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     86          IEnumerable<T> items = ((IEnumerable)e.Data.GetData("HeuristicLab")).Cast<T>();
     87          foreach (T item in items)
     88            validDragOperation = validDragOperation && !Content.ContainsKey(item.Name);
     89        }
    8390      }
    8491    }
  • trunk/sources/HeuristicLab.Core.Views/3.3/OperatorTreeView.cs

    r5445 r5744  
    353353        IOperator op = GetOperatorTag(node);
    354354        DataObject data = new DataObject();
    355         data.SetData("Type", op.GetType());
    356         data.SetData("Value", op);
     355        data.SetData("HeuristicLab", op);
    357356        if (ReadOnly || (opParam == null)) {
    358357          DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
     
    366365    private void graphTreeView_DragEnterOver(object sender, DragEventArgs e) {
    367366      e.Effect = DragDropEffects.None;
    368       Type type = e.Data.GetData("Type") as Type;
    369       if (!ReadOnly && (type != null) && (typeof(IOperator).IsAssignableFrom(type))) {
     367      if (!ReadOnly && (e.Data.GetData("HeuristicLab") is IOperator)) {
    370368        TreeNode node = graphTreeView.GetNodeAt(graphTreeView.PointToClient(new Point(e.X, e.Y)));
    371369        if ((node != null) && !node.IsExpanded) node.Expand();
     
    373371          if ((e.KeyState & 8) == 8) e.Effect = DragDropEffects.Copy;  // CTRL key
    374372          else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    375           else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
    376           else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    377           else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
     373          else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
     374          else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     375          else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
    378376        }
    379377      }
     
    381379    private void graphTreeView_DragDrop(object sender, DragEventArgs e) {
    382380      if (e.Effect != DragDropEffects.None) {
    383         IOperator op = e.Data.GetData("Value") as IOperator;
    384         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) op = (IOperator)op.Clone();
     381        IOperator op = e.Data.GetData("HeuristicLab") as IOperator;
     382        if (e.Effect.HasFlag(DragDropEffects.Copy)) op = (IOperator)op.Clone();
    385383        TreeNode node = graphTreeView.GetNodeAt(graphTreeView.PointToClient(new Point(e.X, e.Y)));
    386384        IValueParameter opParam = GetOperatorParameterTag(node);
  • trunk/sources/HeuristicLab.Core.Views/3.3/ScopeView.cs

    r5445 r5744  
    168168        if (scope != null) {
    169169          DataObject data = new DataObject();
    170           data.SetData("Type", scope.GetType());
    171           data.SetData("Value", scope);
     170          data.SetData("HeuristicLab", scope);
    172171          DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    173172        }
  • trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelector.cs

    r5445 r5744  
    137137                  imageList.Images.Add(type.FullName, item.ItemImage);
    138138                  typeNode.ImageIndex = imageList.Images.IndexOfKey(type.FullName);
    139                 } catch (Exception) { }
     139                }
     140                catch (Exception) { }
    140141              }
    141142              typeNode.SelectedImageIndex = typeNode.ImageIndex;
     
    317318        object o = Activator.CreateInstance(type);
    318319        DataObject data = new DataObject();
    319         data.SetData("Type", type);
    320         data.SetData("Value", o);
     320        data.SetData("HeuristicLab", o);
    321321        DoDragDrop(data, DragDropEffects.Copy);
    322322      }
  • trunk/sources/HeuristicLab.Core.Views/3.3/VariableValueView.cs

    r5445 r5744  
    8888    protected virtual void VariableValueView_DragEnterOver(object sender, DragEventArgs e) {
    8989      e.Effect = DragDropEffects.None;
    90       Type type = e.Data.GetData("Type") as Type;
    91       if (!ReadOnly && (type != null) && (typeof(IItem).IsAssignableFrom(type))) {
     90      if (!ReadOnly && (e.Data.GetData("HeuristicLab") is IItem)) {
    9291        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    9392        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    94         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    95         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    96         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     93        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     94        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     95        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    9796      }
    9897    }
    9998    protected virtual void VariableValueView_DragDrop(object sender, DragEventArgs e) {
    10099      if (e.Effect != DragDropEffects.None) {
    101         IItem item = e.Data.GetData("Value") as IItem;
    102         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (IItem)item.Clone();
     100        IItem item = e.Data.GetData("HeuristicLab") as IItem;
     101        if (e.Effect.HasFlag(DragDropEffects.Copy)) item = (IItem)item.Clone();
    103102        Content.Value = item;
    104103      }
  • trunk/sources/HeuristicLab.Core.Views/3.3/VariableView.cs

    r5445 r5744  
    135135    protected virtual void valuePanel_DragEnterOver(object sender, DragEventArgs e) {
    136136      e.Effect = DragDropEffects.None;
    137       Type type = e.Data.GetData("Type") as Type;
    138       if (!ReadOnly && (type != null) && (typeof(IItem).IsAssignableFrom(type))) {
     137      if (!ReadOnly && (e.Data.GetData("HeuristicLab") is IItem)) {
    139138        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    140139        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    141         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    142         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    143         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     140        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     141        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     142        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    144143      }
    145144    }
    146145    protected virtual void valuePanel_DragDrop(object sender, DragEventArgs e) {
    147146      if (e.Effect != DragDropEffects.None) {
    148         IItem item = e.Data.GetData("Value") as IItem;
    149         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (IItem)item.Clone();
     147        IItem item = e.Data.GetData("HeuristicLab") as IItem;
     148        if (e.Effect.HasFlag(DragDropEffects.Copy)) item = (IItem)item.Clone();
    150149        Content.Value = item;
    151150      }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.cs

    r5463 r5744  
    281281      if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left && startDragAndDrop) {
    282282        DataObject data = new DataObject();
    283         data.SetData("Type", Content.GetType());
    284         data.SetData("Value", Content);
     283        data.SetData("HeuristicLab", Content);
    285284        DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    286285      } else
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorGraphView.cs

    r5445 r5744  
    204204    private void OperatorGraphView_DragEnterOver(object sender, DragEventArgs e) {
    205205      e.Effect = DragDropEffects.None;
    206       Type type = e.Data.GetData("Type") as Type;
    207       if (!ReadOnly && (type != null) && (typeof(IOperator).IsAssignableFrom(type))) {
     206      if (!ReadOnly && (e.Data.GetData("HeuristicLab") is IOperator)) {
    208207        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    209208        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    210         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    211         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    212         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     209        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     210        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     211        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    213212      }
    214213    }
     
    216215    private void OperatorGraphView_DragDrop(object sender, DragEventArgs e) {
    217216      if (e.Effect != DragDropEffects.None) {
    218         IOperator op = e.Data.GetData("Value") as IOperator;
    219         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) op = (IOperator)op.Clone();
     217        IOperator op = e.Data.GetData("HeuristicLab") as IOperator;
     218        if (e.Effect.HasFlag(DragDropEffects.Copy)) op = (IOperator)op.Clone();
    220219        IOperatorShapeInfo shapeInfo = OperatorShapeInfoFactory.CreateOperatorShapeInfo(op);
    221220        Point mouse = new Point(MousePosition.X, MousePosition.Y);
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r5445 r5744  
    278278    protected virtual void problemTabPage_DragEnterOver(object sender, DragEventArgs e) {
    279279      e.Effect = DragDropEffects.None;
    280       Type type = e.Data.GetData("Type") as Type;
    281       if ((type != null) && (Content.ProblemType.IsAssignableFrom(type))) {
     280      if (!ReadOnly && (e.Data.GetData("HeuristicLab") != null) && Content.ProblemType.IsAssignableFrom(e.Data.GetData("HeuristicLab").GetType())) {
    282281        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    283282        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    284         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    285         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    286         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     283        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     284        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     285        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    287286      }
    288287    }
    289288    protected virtual void problemTabPage_DragDrop(object sender, DragEventArgs e) {
    290289      if (e.Effect != DragDropEffects.None) {
    291         IProblem problem = e.Data.GetData("Value") as IProblem;
    292         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) problem = (IProblem)problem.Clone();
     290        IProblem problem = e.Data.GetData("HeuristicLab") as IProblem;
     291        if (e.Effect.HasFlag(DragDropEffects.Copy)) problem = (IProblem)problem.Clone();
    293292        Content.Problem = problem;
    294293      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.cs

    r5445 r5744  
    253253    private void optimizerTabPage_DragEnterOver(object sender, DragEventArgs e) {
    254254      e.Effect = DragDropEffects.None;
    255       if (ReadOnly)
    256         return;
    257       Type type = e.Data.GetData("Type") as Type;
    258       if ((type != null) && (typeof(IOptimizer).IsAssignableFrom(type))) {
     255      if (!ReadOnly && (e.Data.GetData("HeuristicLab") is IOptimizer)) {
    259256        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    260257        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    261         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    262         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    263         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     258        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     259        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     260        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    264261      }
    265262    }
    266263    private void optimizerTabPage_DragDrop(object sender, DragEventArgs e) {
    267264      if (e.Effect != DragDropEffects.None) {
    268         IOptimizer optimizer = e.Data.GetData("Value") as IOptimizer;
    269         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) optimizer = (IOptimizer)optimizer.Clone();
     265        IOptimizer optimizer = e.Data.GetData("HeuristicLab") as IOptimizer;
     266        if (e.Effect.HasFlag(DragDropEffects.Copy)) optimizer = (IOptimizer)optimizer.Clone();
    270267        Content.Optimizer = optimizer;
    271268      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.cs

    r5445 r5744  
    452452        if (this.draggedRun != null && h.ChartElementType != ChartElementType.DataPoint) {
    453453          DataObject data = new DataObject();
    454           data.SetData("Type", draggedRun.GetType());
    455           data.SetData("Value", draggedRun);
     454          data.SetData("HeuristicLab", draggedRun);
    456455          if (ReadOnly)
    457456            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.Designer.cs

    r5466 r5744  
    170170      this.itemsListView.SelectedIndexChanged += new System.EventHandler(this.itemsListView_SelectedIndexChanged);
    171171      this.itemsListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragDrop);
    172       this.itemsListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnterOver);
    173       this.itemsListView.DragOver += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnterOver);
     172      this.itemsListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnter);
     173      this.itemsListView.DragOver += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragOver);
    174174      this.itemsListView.DoubleClick += new System.EventHandler(this.itemsListView_DoubleClick);
    175175      this.itemsListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.itemsListView_KeyDown);
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r5702 r5744  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
    2425using System.Drawing;
     
    3738  public sealed partial class RunCollectionView : ItemView {
    3839    private Dictionary<IRun, List<ListViewItem>> itemListViewItemMapping;
     40    private bool validDragOperation;
    3941
    4042    public new IItemCollection<IRun> Content {
     
    271273        if (items.Count > 0) {
    272274          DataObject data = new DataObject();
    273           if (items.Count == 1) {
    274             data.SetData("Type", items[0].GetType());
    275             data.SetData("Value", items[0]);
    276           } else {
    277             data.SetData("Type", typeof(IEnumerable<IRun>));
    278             data.SetData("Value", items);
    279           }
     275          if (items.Count == 1) data.SetData("HeuristicLab", items[0]);
     276          else data.SetData("HeuristicLab", items);
    280277          if (Content.IsReadOnly || ReadOnly) {
    281278            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    282279          } else {
    283280            DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    284             if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
     281            if (result.HasFlag(DragDropEffects.Move)) {
    285282              foreach (IRun item in items) Content.Remove(item);
    286283            }
     
    289286      }
    290287    }
    291     private void itemsListView_DragEnterOver(object sender, DragEventArgs e) {
     288    private void itemsListView_DragEnter(object sender, DragEventArgs e) {
     289      validDragOperation = false;
     290      if (e.Data.GetData("HeuristicLab") is IRun) {
     291        validDragOperation = true;
     292      } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     293        validDragOperation = true;
     294        IEnumerable items = (IEnumerable)e.Data.GetData("HeuristicLab");
     295        foreach (object item in items)
     296          validDragOperation = validDragOperation && (item is IRun);
     297      }
     298      validDragOperation = validDragOperation && !Content.IsReadOnly && !ReadOnly;
     299    }
     300    private void itemsListView_DragOver(object sender, DragEventArgs e) {
    292301      e.Effect = DragDropEffects.None;
    293       Type type = e.Data.GetData("Type") as Type;
    294       if (!Content.IsReadOnly && !ReadOnly && (type != null) && (typeof(IRun).IsAssignableFrom(type) || typeof(IEnumerable<IRun>).IsAssignableFrom(type))) {
     302      if (validDragOperation) {
    295303        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    296304        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    297         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    298         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    299         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     305        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     306        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     307        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    300308      }
    301309    }
    302310    private void itemsListView_DragDrop(object sender, DragEventArgs e) {
    303311      if (e.Effect != DragDropEffects.None) {
    304         object value = e.Data.GetData("Value");
    305         IEnumerable<IRun> items = Enumerable.Empty<IRun>();
    306         if (value is IRun)
    307           items = new IRun[] { (IRun)value };
    308         else if (value is IEnumerable<IRun>)
    309           items = (IEnumerable<IRun>)value;
    310 
    311         foreach (IRun item in items) {
    312           if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) Content.Add((IRun)item.Clone());
    313           else Content.Add(item);
     312        if (e.Data.GetData("HeuristicLab") is IRun) {
     313          IRun item = (IRun)e.Data.GetData("HeuristicLab");
     314          Content.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (IRun)item.Clone() : item);
     315        } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     316          IEnumerable<IRun> items = ((IEnumerable)e.Data.GetData("HeuristicLab")).Cast<IRun>();
     317          foreach (IRun item in items)
     318            Content.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (IRun)item.Clone() : item);
    314319        }
    315320      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunView.cs

    r5445 r5744  
    149149        if (item != null) {
    150150          DataObject data = new DataObject();
    151           data.SetData("Type", item.GetType());
    152           data.SetData("Value", item);
     151          data.SetData("HeuristicLab", item);
    153152          DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
    154153        }
  • trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.cs

    r5445 r5744  
    122122      IItem item = (IItem)listViewItem.Tag;
    123123      DataObject data = new DataObject();
    124       data.SetData("Type", item.GetType());
    125       data.SetData("Value", item);
     124      data.SetData("HeuristicLab", item);
    126125      DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
    127126    }
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueLookupParameterView.cs

    r5445 r5744  
    162162    protected virtual void valueGroupBox_DragEnterOver(object sender, DragEventArgs e) {
    163163      e.Effect = DragDropEffects.None;
    164       Type type = e.Data.GetData("Type") as Type;
    165       if (!ReadOnly && (type != null) && (Content.DataType.IsAssignableFrom(type))) {
     164      if (!ReadOnly && (e.Data.GetData("HeuristicLab") != null) && Content.DataType.IsAssignableFrom(e.Data.GetData("HeuristicLab").GetType())) {
    166165        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    167166        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    168         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    169         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    170         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     167        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     168        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     169        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    171170      }
    172171    }
    173172    protected virtual void valueGroupBox_DragDrop(object sender, DragEventArgs e) {
    174173      if (e.Effect != DragDropEffects.None) {
    175         T value = e.Data.GetData("Value") as T;
    176         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) value = (T)value.Clone();
     174        T value = e.Data.GetData("HeuristicLab") as T;
     175        if (e.Effect.HasFlag(DragDropEffects.Copy)) value = (T)value.Clone();
    177176        Content.Value = value;
    178177      }
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueParameterView.cs

    r5445 r5744  
    148148    protected virtual void valueGroupBox_DragEnterOver(object sender, DragEventArgs e) {
    149149      e.Effect = DragDropEffects.None;
    150       Type type = e.Data.GetData("Type") as Type;
    151       if (!ReadOnly && (type != null) && (Content.DataType.IsAssignableFrom(type))) {
     150      if (!ReadOnly && (e.Data.GetData("HeuristicLab") != null) && Content.DataType.IsAssignableFrom(e.Data.GetData("HeuristicLab").GetType())) {
    152151        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    153152        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    154         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    155         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    156         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     153        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     154        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     155        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    157156      }
    158157    }
    159158    protected virtual void valueGroupBox_DragDrop(object sender, DragEventArgs e) {
    160159      if (e.Effect != DragDropEffects.None) {
    161         T value = e.Data.GetData("Value") as T;
    162         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) value = (T)value.Clone();
     160        T value = e.Data.GetData("HeuristicLab") as T;
     161        if (e.Effect.HasFlag(DragDropEffects.Copy)) value = (T)value.Clone();
    163162        Content.Value = value;
    164163      }
Note: See TracChangeset for help on using the changeset viewer.