- Timestamp:
- 04/14/10 05:09:59 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/ItemArrayView.cs
r3228 r3341 112 112 } 113 113 protected virtual ListViewItem CreateListViewItem(T item) { 114 if (item == null) { 115 return new ListViewItem("null"); 116 } else { 117 if (!itemsListView.SmallImageList.Images.ContainsKey(item.GetType().FullName)) 118 itemsListView.SmallImageList.Images.Add(item.GetType().FullName, item.ItemImage); 119 120 ListViewItem listViewItem = new ListViewItem(); 121 listViewItem.Text = item.ToString(); 122 listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription; 123 listViewItem.ImageIndex = itemsListView.SmallImageList.Images.IndexOfKey(item.GetType().FullName); 124 listViewItem.Tag = item; 125 return listViewItem; 126 } 114 ListViewItem listViewItem = new ListViewItem(); 115 listViewItem.Text = item == null ? "null" : item.ToString(); 116 listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription; 117 itemsListView.SmallImageList.Images.Add(item == null ? HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing : item.ItemImage); 118 listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1; 119 listViewItem.Tag = item; 120 return listViewItem; 127 121 } 128 122 protected virtual void AddListViewItem(ListViewItem listViewItem) { 129 123 itemsListView.Items.Add(listViewItem); 130 if (listViewItem.Tag != null) 124 if (listViewItem.Tag != null) { 125 ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged); 131 126 ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged); 127 } 132 128 } 133 129 protected virtual void InsertListViewItem(int index, ListViewItem listViewItem) { 134 130 itemsListView.Items.Insert(index, listViewItem); 135 if (listViewItem.Tag != null) 131 if (listViewItem.Tag != null) { 132 ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged); 136 133 ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged); 134 } 137 135 } 138 136 protected virtual void RemoveListViewItem(ListViewItem listViewItem) { 139 if (listViewItem.Tag != null) 137 if (listViewItem.Tag != null) { 138 ((T)listViewItem.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged); 140 139 ((T)listViewItem.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged); 140 } 141 141 listViewItem.Remove(); 142 } 143 protected virtual void UpdateListViewItem(ListViewItem listViewItem) { 142 foreach (ListViewItem other in itemsListView.Items) 143 if (other.ImageIndex > listViewItem.ImageIndex) other.ImageIndex--; 144 itemsListView.SmallImageList.Images.RemoveAt(listViewItem.ImageIndex); 145 } 146 protected virtual void UpdateListViewItemImage(ListViewItem listViewItem) { 144 147 T item = listViewItem.Tag as T; 145 if ((item != null) && (!itemsListView.SmallImageList.Images.ContainsKey(item.GetType().FullName))) 146 itemsListView.SmallImageList.Images.Add(item.GetType().FullName, item.ItemImage); 147 148 int i = listViewItem.ImageIndex; 149 listViewItem.ImageList.Images[i] = item == null ? HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing : item.ItemImage; 150 listViewItem.ImageIndex = -1; 151 listViewItem.ImageIndex = i; 152 } 153 protected virtual void UpdateListViewItemText(ListViewItem listViewItem) { 154 T item = listViewItem.Tag as T; 148 155 listViewItem.Text = item == null ? "null" : item.ToString(); 149 156 listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription; 150 listViewItem.ImageIndex = item == null ? -1 : itemsListView.SmallImageList.Images.IndexOfKey(item.GetType().FullName);151 157 } 152 158 153 159 protected virtual void itemsListView_SelectedIndexChanged(object sender, EventArgs e) { 160 addButton.Enabled = itemsListView.SelectedItems.Count > 0 && !Content.IsReadOnly; 154 161 moveUpButton.Enabled = itemsListView.SelectedItems.Count == 1 && 155 162 itemsListView.SelectedIndices[0] != 0 && … … 158 165 itemsListView.SelectedIndices[0] != itemsListView.Items.Count - 1 && 159 166 !Content.IsReadOnly; 167 removeButton.Enabled = itemsListView.SelectedItems.Count > 0 && !Content.IsReadOnly; 160 168 161 169 if (itemsListView.SelectedItems.Count == 1) { … … 239 247 240 248 #region Button Events 249 protected virtual void addButton_Click(object sender, EventArgs e) { 250 if (itemsListView.SelectedItems.Count > 0) { 251 T item = CreateItem(); 252 if (item != null) { 253 foreach (ListViewItem listViewItem in itemsListView.SelectedItems) 254 Content[listViewItem.Index] = item; 255 } 256 } 257 } 241 258 protected virtual void moveUpButton_Click(object sender, EventArgs e) { 242 259 if (itemsListView.SelectedItems.Count == 1) { … … 259 276 } 260 277 } 278 protected virtual void removeButton_Click(object sender, EventArgs e) { 279 if (itemsListView.SelectedItems.Count > 0) { 280 foreach (ListViewItem item in itemsListView.SelectedItems) 281 Content[item.Index] = null; 282 } 283 } 261 284 #endregion 262 285 … … 289 312 ListViewItem listViewItem = itemsListView.Items[item.Index]; 290 313 listViewItem.Tag = item.Value; 291 UpdateListViewItem(listViewItem); 314 UpdateListViewItemImage(listViewItem); 315 UpdateListViewItemText(listViewItem); 292 316 } 293 317 } … … 310 334 311 335 #region Item Events 312 protected virtual void Item_ ToStringChanged(object sender, EventArgs e) {313 if (InvokeRequired) 314 Invoke(new EventHandler(Item_ ToStringChanged), sender, e);336 protected virtual void Item_ItemImageChanged(object sender, EventArgs e) { 337 if (InvokeRequired) 338 Invoke(new EventHandler(Item_ItemImageChanged), sender, e); 315 339 else { 316 340 T item = (T)sender; 317 341 foreach (ListViewItem listViewItem in itemsListView.Items) { 318 342 if (((T)listViewItem.Tag) == item) 319 UpdateListViewItem(listViewItem); 343 UpdateListViewItemImage(listViewItem); 344 } 345 } 346 } 347 protected virtual void Item_ToStringChanged(object sender, EventArgs e) { 348 if (InvokeRequired) 349 Invoke(new EventHandler(Item_ToStringChanged), sender, e); 350 else { 351 T item = (T)sender; 352 foreach (ListViewItem listViewItem in itemsListView.Items) { 353 if (((T)listViewItem.Tag) == item) 354 UpdateListViewItemText(listViewItem); 320 355 } 321 356 }
Note: See TracChangeset
for help on using the changeset viewer.