Changeset 5057
- Timestamp:
- 12/07/10 11:49:25 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs
r4300 r5057 34 34 [Content(typeof(IItemCollection<>), false)] 35 35 public partial class ItemCollectionView<T> : ItemView where T : class, IItem { 36 private Dictionary<T, List<ListViewItem>> listViewItemMapping; 36 37 protected TypeSelectorDialog typeSelectorDialog; 37 38 … … 47 48 public ItemCollectionView() { 48 49 InitializeComponent(); 50 listViewItemMapping = new Dictionary<T, List<ListViewItem>>(); 49 51 } 50 52 … … 65 67 base.OnContentChanged(); 66 68 while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]); 69 RebuildImageList(); 67 70 viewHost.Content = null; 68 71 if (Content != null) { … … 105 108 try { 106 109 return (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType(); 107 } 108 catch (Exception ex) { 110 } catch (Exception ex) { 109 111 ErrorHandling.ShowErrorDialog(this, ex); 110 112 } … … 122 124 } 123 125 protected virtual void AddListViewItem(ListViewItem listViewItem) { 126 T item = (listViewItem.Tag as T); 124 127 itemsListView.Items.Add(listViewItem); 125 ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged); 126 ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged); 128 item.ItemImageChanged += new EventHandler(Item_ItemImageChanged); 129 item.ToStringChanged += new EventHandler(Item_ToStringChanged); 130 if (!listViewItemMapping.ContainsKey(item)) 131 listViewItemMapping.Add(item, new List<ListViewItem>()); 132 listViewItemMapping[item].Add(listViewItem); 127 133 sortAscendingButton.Enabled = itemsListView.Items.Count > 1; 128 134 sortDescendingButton.Enabled = itemsListView.Items.Count > 1; 129 135 } 130 136 protected virtual void RemoveListViewItem(ListViewItem listViewItem) { 131 ((T)listViewItem.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged); 132 ((T)listViewItem.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged); 137 T item = (listViewItem.Tag as T); 138 listViewItemMapping[item].Remove(listViewItem); 139 if (listViewItemMapping[item].Count == 0) { 140 listViewItemMapping.Remove(item); 141 item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged); 142 item.ToStringChanged -= new EventHandler(Item_ToStringChanged); 143 } 133 144 listViewItem.Remove(); 134 foreach (ListViewItem other in itemsListView.Items)135 if (other.ImageIndex > listViewItem.ImageIndex) other.ImageIndex--;136 itemsListView.SmallImageList.Images.RemoveAt(listViewItem.ImageIndex);137 145 sortAscendingButton.Enabled = itemsListView.Items.Count > 1; 138 146 sortDescendingButton.Enabled = itemsListView.Items.Count > 1; … … 149 157 } 150 158 protected virtual IEnumerable<ListViewItem> GetListViewItemsForItem(T item) { 151 foreach (ListViewItem listViewItem in itemsListView.Items) { 152 if (((T)listViewItem.Tag) == item) 153 yield return listViewItem; 154 } 159 return listViewItemMapping[item]; 155 160 } 156 161 … … 278 283 if (listviewItem != null) RemoveListViewItem(listviewItem); 279 284 } 285 RebuildImageList(); 280 286 } 281 287 } … … 289 295 if (listviewItem != null) RemoveListViewItem(listviewItem); 290 296 } 297 RebuildImageList(); 291 298 foreach (T item in e.Items) 292 299 AddListViewItem(CreateListViewItem(item)); … … 328 335 } 329 336 } 337 private void RebuildImageList() { 338 itemsListView.SmallImageList.Images.Clear(); 339 foreach (ListViewItem item in itemsListView.Items) { 340 itemsListView.SmallImageList.Images.Add(((T)item.Tag).ItemImage); 341 item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1; 342 } 343 } 330 344 #endregion 331 345 }
Note: See TracChangeset
for help on using the changeset viewer.