- Timestamp:
- 01/20/14 17:33:22 (11 years ago)
- Location:
- branches/HLScript
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HLScript
- Property svn:mergeinfo changed
/trunk/sources (added) merged: 10346,10348,10355
- Property svn:mergeinfo changed
-
branches/HLScript/HeuristicLab.HLScript.Views/3.3/VariableStoreView.cs
r10332 r10358 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.Drawing; 25 26 using System.Linq; 26 27 using System.Windows.Forms; … … 31 32 using HeuristicLab.MainForm; 32 33 using HeuristicLab.MainForm.WindowsForms; 34 using HeuristicLab.Persistence.Core; 35 using HeuristicLab.Persistence.Default.Xml; 33 36 using HeuristicLab.PluginInfrastructure; 34 37 … … 53 56 InitializeComponent(); 54 57 itemListViewItemMapping = new Dictionary<string, ListViewItem>(); 58 variableListView.SmallImageList.Images.AddRange(new Image[] { 59 HeuristicLab.Common.Resources.VSImageLibrary.Error, 60 HeuristicLab.Common.Resources.VSImageLibrary.Object, 61 HeuristicLab.Common.Resources.VSImageLibrary.Nothing 62 }); 55 63 } 56 64 … … 101 109 variableListView.Enabled = false; 102 110 } else { 103 addButton.Enabled = /*!Content.IsReadOnly &&*/!ReadOnly;111 addButton.Enabled = !Locked && !ReadOnly; 104 112 sortAscendingButton.Enabled = variableListView.Items.Count > 1; 105 113 sortDescendingButton.Enabled = variableListView.Items.Count > 1; 106 removeButton.Enabled = /*!Content.IsReadOnly &&*/!ReadOnly && variableListView.SelectedItems.Count > 0;114 removeButton.Enabled = !Locked && !ReadOnly && variableListView.SelectedItems.Count > 0; 107 115 variableListView.Enabled = true; 108 116 } … … 130 138 string value = (variable.Value ?? "null").ToString(); 131 139 string type = variable.Value == null ? "null" : variable.Value.GetType().ToString(); 132 var listViewItem = new ListViewItem(new[] { variable.Key, value, type }) { ToolTipText = GetToolTipText(variable), Tag = variable }; 133 variableListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Object); 134 listViewItem.ImageIndex = variableListView.SmallImageList.Images.Count - 1; 140 bool serializable = IsSerializable(variable); 141 var listViewItem = new ListViewItem(new[] { variable.Key, value, type }) { ToolTipText = GetToolTipText(variable, serializable), Tag = variable }; 142 if (serializable) { 143 listViewItem.ImageIndex = variable.Value == null ? 2 : 1; 144 } else listViewItem.ImageIndex = 0; 135 145 variableListView.Items.Add(listViewItem); 136 146 itemListViewItemMapping[variable.Key] = listViewItem; … … 160 170 string value = (variable.Value ?? "null").ToString(); 161 171 string type = variable.Value == null ? "null" : variable.Value.GetType().ToString(); 172 bool serializable = IsSerializable(variable); 173 if (serializable) { 174 listViewItem.ImageIndex = variable.Value == null ? 2 : 1; 175 } else listViewItem.ImageIndex = 0; 162 176 listViewItem.SubItems[1].Text = value; 163 177 listViewItem.SubItems[2].Text = type; 164 listViewItem.ToolTipText = GetToolTipText(variable );178 listViewItem.ToolTipText = GetToolTipText(variable, serializable); 165 179 listViewItem.Tag = variable; 166 180 } else throw new ArgumentException("A variable with the specified name does not exist.", "variable"); … … 169 183 #region ListView Events 170 184 protected virtual void variableListView_SelectedIndexChanged(object sender, EventArgs e) { 171 removeButton.Enabled = (Content != null) /*&& !Content.IsReadOnly*/&& !ReadOnly && variableListView.SelectedItems.Count > 0;185 removeButton.Enabled = (Content != null) && !Locked && !ReadOnly && variableListView.SelectedItems.Count > 0; 172 186 AdjustListViewColumnSizes(); 173 187 } 174 188 protected virtual void variableListView_KeyDown(object sender, KeyEventArgs e) { 175 189 if (e.KeyCode == Keys.Delete) { 176 if ((variableListView.SelectedItems.Count > 0) /*&& !Content.IsReadOnly*/&& !ReadOnly) {190 if ((variableListView.SelectedItems.Count > 0) && !Locked && !ReadOnly) { 177 191 foreach (ListViewItem item in variableListView.SelectedItems) 178 192 Content.Remove(item.Text); … … 207 221 if (items.Count == 1) data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items[0]); 208 222 else data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items); 209 if ( /*Content.IsReadOnly ||*/ReadOnly) {223 if (ReadOnly) { 210 224 DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link); 211 225 } else { … … 220 234 protected virtual void variableListView_DragEnter(object sender, DragEventArgs e) { 221 235 validDragOperation = false; 222 if ( /*!Content.IsReadOnly &&*/!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is object)) {236 if (!Locked && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is object)) { 223 237 validDragOperation = true; 224 } else if ( /*!Content.IsReadOnly &&*/!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) {238 } else if (!Locked && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) { 225 239 validDragOperation = true; 226 240 IEnumerable items = (IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); … … 361 375 item.SubItems[1].Text = value; 362 376 item.SubItems[2].Text = variable.Value.Value.GetType().ToString(); 363 item.ToolTipText = GetToolTipText(variable.Value );377 item.ToolTipText = GetToolTipText(variable.Value, item.ImageIndex == 0); 364 378 return; 365 379 } … … 382 396 protected virtual void RebuildImageList() { 383 397 variableListView.SmallImageList.Images.Clear(); 398 variableListView.SmallImageList.Images.AddRange(new Image[] { 399 HeuristicLab.Common.Resources.VSImageLibrary.Error, 400 HeuristicLab.Common.Resources.VSImageLibrary.Object, 401 HeuristicLab.Common.Resources.VSImageLibrary.Nothing 402 }); 384 403 foreach (ListViewItem listViewItem in variableListView.Items) { 385 object item = listViewItem.Tag as object; 386 variableListView.SmallImageList.Images.Add(item == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : HeuristicLab.Common.Resources.VSImageLibrary.Object);//item.ItemImage); 387 listViewItem.ImageIndex = variableListView.SmallImageList.Images.Count - 1; 388 } 389 } 390 391 private string GetToolTipText(KeyValuePair<string, object> variable) { 404 var variable = (KeyValuePair<string, object>)listViewItem.Tag; 405 bool serializable = IsSerializable(variable); 406 if (serializable) { 407 listViewItem.ImageIndex = variable.Value == null ? 2 : 1; 408 } else listViewItem.ImageIndex = 0; 409 } 410 } 411 412 private string GetToolTipText(KeyValuePair<string, object> variable, bool serializable) { 392 413 if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable"); 393 414 string value = (variable.Value ?? "null").ToString(); 415 string type = variable.Value == null ? "null" : variable.Value.GetType().ToString(); 394 416 string[] lines = { 395 417 "Name: " + variable.Key, 396 418 "Value: " + value, 397 "Type: " + variable.Value.GetType()419 "Type: " + type 398 420 }; 399 return string.Join(Environment.NewLine, lines); 421 string toolTipText = string.Join(Environment.NewLine, lines); 422 if (!serializable) 423 toolTipText += Environment.NewLine + "CAUTION: Type is not serializable!"; 424 return toolTipText; 400 425 } 401 426 … … 411 436 return defaultName; 412 437 } 438 439 private bool IsSerializable(KeyValuePair<string, object> variable) { 440 var ser = new Serializer(variable, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()), "ROOT", true); 441 try { 442 return ser.Count() > 0; 443 } catch (PersistenceException) { 444 return false; 445 } 446 } 413 447 #endregion 414 448 }
Note: See TracChangeset
for help on using the changeset viewer.