Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/11 01:08:19 (13 years ago)
Author:
swagner
Message:

Implemented dragging of multiple items in RunCollectionView (#1112)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r5445 r5702  
    263263    private void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) {
    264264      if (!Locked) {
    265         ListViewItem listViewItem = (ListViewItem)e.Item;
    266         IRun item = listViewItem.Tag as IRun;
    267         if (item != null) {
     265        List<IRun> items = new List<IRun>();
     266        foreach (ListViewItem listViewItem in itemsListView.SelectedItems) {
     267          IRun item = listViewItem.Tag as IRun;
     268          if (item != null) items.Add(item);
     269        }
     270
     271        if (items.Count > 0) {
    268272          DataObject data = new DataObject();
    269           data.SetData("Type", item.GetType());
    270           data.SetData("Value", item);
     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          }
    271280          if (Content.IsReadOnly || ReadOnly) {
    272281            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    273282          } else {
    274283            DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    275             if ((result & DragDropEffects.Move) == DragDropEffects.Move)
    276               Content.Remove(item);
     284            if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
     285              foreach (IRun item in items) Content.Remove(item);
     286            }
    277287          }
    278288        }
     
    282292      e.Effect = DragDropEffects.None;
    283293      Type type = e.Data.GetData("Type") as Type;
    284       if (!Content.IsReadOnly && !ReadOnly && (type != null) && (typeof(IRun).IsAssignableFrom(type))) {
     294      if (!Content.IsReadOnly && !ReadOnly && (type != null) && (typeof(IRun).IsAssignableFrom(type) || typeof(IEnumerable<IRun>).IsAssignableFrom(type))) {
    285295        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    286296        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
     
    292302    private void itemsListView_DragDrop(object sender, DragEventArgs e) {
    293303      if (e.Effect != DragDropEffects.None) {
    294         IRun item = e.Data.GetData("Value") as IRun;
    295         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (IRun)item.Clone();
    296         Content.Add(item);
     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);
     314        }
    297315      }
    298316    }
Note: See TracChangeset for help on using the changeset viewer.