- Timestamp:
- 03/22/11 16:45:46 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Core.Views/3.3/Clipboard.cs
r5445 r5796 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 24 25 using System.IO; … … 35 36 private TypeSelectorDialog typeSelectorDialog; 36 37 private Dictionary<T, ListViewItem> itemListViewItemMapping; 38 private bool validDragOperation; 39 private bool draggedItemsAlreadyContained; 37 40 38 41 private string itemsPath; … … 264 267 } 265 268 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) { 282 307 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; 291 314 } 292 315 } 293 316 private void listView_DragDrop(object sender, DragEventArgs e) { 294 317 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();297 318 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 } 299 327 } 300 328 catch (Exception ex) {
Note: See TracChangeset
for help on using the changeset viewer.