- Timestamp:
- 03/18/11 01:38:23 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs
r5702 r5744 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 24 25 using System.Drawing; … … 37 38 public sealed partial class RunCollectionView : ItemView { 38 39 private Dictionary<IRun, List<ListViewItem>> itemListViewItemMapping; 40 private bool validDragOperation; 39 41 40 42 public new IItemCollection<IRun> Content { … … 271 273 if (items.Count > 0) { 272 274 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); 280 277 if (Content.IsReadOnly || ReadOnly) { 281 278 DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link); 282 279 } else { 283 280 DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move); 284 if ( (result & DragDropEffects.Move) == DragDropEffects.Move) {281 if (result.HasFlag(DragDropEffects.Move)) { 285 282 foreach (IRun item in items) Content.Remove(item); 286 283 } … … 289 286 } 290 287 } 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) { 292 301 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) { 295 303 if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key 296 304 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; 300 308 } 301 309 } 302 310 private void itemsListView_DragDrop(object sender, DragEventArgs e) { 303 311 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); 314 319 } 315 320 }
Note: See TracChangeset
for help on using the changeset viewer.