Changeset 11480
- Timestamp:
- 10/17/14 14:26:22 (10 years ago)
- Location:
- trunk/sources/HeuristicLab.Scripting.Views/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Scripting.Views/3.3/ScriptView.cs
r11436 r11480 46 46 47 47 public override bool ReadOnly { 48 get { return codeEditor.ReadOnly ; }49 set { codeEditor.ReadOnly = value; }48 get { return codeEditor.ReadOnly || base.ReadOnly; } 49 set { base.ReadOnly = codeEditor.ReadOnly = value; } 50 50 } 51 51 52 52 public override bool Locked { 53 get { return codeEditor.ReadOnly ; }54 set { codeEditor.ReadOnly = value; }53 get { return codeEditor.ReadOnly || base.Locked; } 54 set { base.Locked = codeEditor.ReadOnly = value; } 55 55 } 56 56 -
trunk/sources/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs
r11479 r11480 119 119 variableListView.Enabled = false; 120 120 } else { 121 addButton.Enabled = !Locked && !ReadOnly; 121 bool enabled = !Locked && !ReadOnly; 122 addButton.Enabled = enabled; 122 123 sortAscendingButton.Enabled = variableListView.Items.Count > 1; 123 124 sortDescendingButton.Enabled = variableListView.Items.Count > 1; 124 removeButton.Enabled = !Locked && !ReadOnly&& variableListView.SelectedItems.Count > 0;125 variableListView.Enabled = true;126 variableListView.LabelEdit = !Locked && !ReadOnly;125 removeButton.Enabled = enabled && variableListView.SelectedItems.Count > 0; 126 variableListView.Enabled = enabled; 127 variableListView.LabelEdit = enabled; 127 128 } 128 129 } … … 147 148 protected virtual void AddVariable(KeyValuePair<string, object> variable) { 148 149 if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable"); 149 string value = (variable.Value ?? "null").ToString();150 string type = variable.Value == null ? "null" : variable.Value.GetType().ToString();151 150 bool serializable = IsSerializable(variable); 152 151 153 var listViewItem = new ListViewItem(new[] { variable.Key, value, type }) { Tag = variable }; 152 var listViewItem = new ListViewItem(); 153 AssignVariableToListViewItem(listViewItem, variable); 154 154 SetImageKey(listViewItem, serializable); 155 155 SetToolTipText(listViewItem, serializable); … … 165 165 protected virtual void RemoveVariable(KeyValuePair<string, object> variable) { 166 166 if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable"); 167 167 168 ListViewItem listViewItem; 168 if ( itemListViewItemMapping.TryGetValue(variable.Key, out listViewItem)) {169 itemListViewItemMapping.Remove(variable.Key); 170 variableListView.Items.Remove(listViewItem);171 sortAscendingButton.Enabled = variableListView.Items.Count > 1;172 sortDescendingButton.Enabled = variableListView.Items.Count > 1;173 var item = variable.Value as IItem;174 if (item != null) item.ToStringChanged -= item_ToStringChanged;175 }169 if (!itemListViewItemMapping.TryGetValue(variable.Key, out listViewItem)) return; 170 171 itemListViewItemMapping.Remove(variable.Key); 172 variableListView.Items.Remove(listViewItem); 173 sortAscendingButton.Enabled = variableListView.Items.Count > 1; 174 sortDescendingButton.Enabled = variableListView.Items.Count > 1; 175 var item = variable.Value as IItem; 176 if (item != null) item.ToStringChanged -= item_ToStringChanged; 176 177 } 177 178 178 179 protected virtual void UpdateVariable(KeyValuePair<string, object> variable) { 179 180 if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable"); 181 180 182 ListViewItem listViewItem; 181 if (itemListViewItemMapping.TryGetValue(variable.Key, out listViewItem)) { 182 string value = (variable.Value ?? "null").ToString(); 183 string type = variable.Value == null ? "null" : variable.Value.GetType().ToString(); 184 bool serializable = IsSerializable(variable); 185 bool validIdentifier = SafeVariableNameRegex.IsMatch(variable.Key); 186 187 listViewItem.Tag = variable; 188 listViewItem.SubItems[1].Text = value; 189 listViewItem.SubItems[2].Text = type; 190 SetImageKey(listViewItem, serializable); 191 SetToolTipText(listViewItem, serializable); 192 } else throw new ArgumentException("A variable with the specified name does not exist.", "variable"); 183 if (!itemListViewItemMapping.TryGetValue(variable.Key, out listViewItem)) 184 throw new ArgumentException("A variable with the specified name does not exist.", "variable"); 185 186 bool serializable = IsSerializable(variable); 187 AssignVariableToListViewItem(listViewItem, variable); 188 SetImageKey(listViewItem, serializable); 189 SetToolTipText(listViewItem, serializable); 190 193 191 } 194 192 … … 221 219 } 222 220 protected virtual void variableListView_DoubleClick(object sender, EventArgs e) { 223 if (variableListView.SelectedItems.Count == 1) { 224 var item = variableListView.SelectedItems[0].Tag as KeyValuePair<string, object>?; 225 if (item != null) { 226 var value = item.Value.Value as IContent; 227 if (value != null) { 228 IContentView view = MainFormManager.MainForm.ShowContent(value); 229 if (view != null) { 230 view.ReadOnly = ReadOnly; 231 view.Locked = Locked; 232 } 233 } 234 } 235 } 221 if (variableListView.SelectedItems.Count != 1) return; 222 var item = variableListView.SelectedItems[0].Tag as KeyValuePair<string, object>?; 223 if (item == null) return; 224 225 var value = item.Value.Value as IContent; 226 if (value == null) return; 227 228 IContentView view = MainFormManager.MainForm.ShowContent(value); 229 if (view == null) return; 230 231 view.ReadOnly = ReadOnly; 232 view.Locked = Locked; 236 233 } 237 234 protected virtual void variableListView_ItemDrag(object sender, ItemDragEventArgs e) { 238 if ( !Locked && variableListView.SelectedItems.Count == 1) {239 var listViewItem = variableListView.SelectedItems[0]; 240 var item = (KeyValuePair<string, object>)listViewItem.Tag;241 if (!(item.Value is IDeepCloneable)) return;242 var data = new DataObject(HeuristicLab.Common.Constants.DragDropDataFormat, item);243 DoDragDrop(data, DragDropEffects.Copy);244 }235 if (Locked || variableListView.SelectedItems.Count != 1) return; 236 237 var listViewItem = variableListView.SelectedItems[0]; 238 var item = (KeyValuePair<string, object>)listViewItem.Tag; 239 if (!(item.Value is IDeepCloneable)) return; 240 var data = new DataObject(HeuristicLab.Common.Constants.DragDropDataFormat, item); 241 DoDragDrop(data, DragDropEffects.Copy); 245 242 } 246 243 protected virtual void variableListView_DragEnter(object sender, DragEventArgs e) { … … 254 251 } 255 252 protected virtual void variableListView_DragDrop(object sender, DragEventArgs e) { 256 if (e.Effect == DragDropEffects.Copy) { 257 object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 258 259 string variableName; 260 object variableValue; 261 bool editLabel; 262 if (item is KeyValuePair<string, object>) { 263 var variable = (KeyValuePair<string, object>)item; 264 variableName = GenerateNewVariableName(out editLabel, variable.Key, false); 265 variableValue = variable.Value; 266 } else { 267 var cloneable = item as IDeepCloneable; 268 variableValue = cloneable != null ? cloneable.Clone() : item; 269 270 var namedItem = item as INamedItem; 271 if (namedItem != null) 272 variableName = GenerateNewVariableName(out editLabel, namedItem.Name, false); 273 else 274 variableName = GenerateNewVariableName(out editLabel); 275 } 276 277 Content.Add(variableName, variableValue); 278 279 var listViewItem = variableListView.FindItemWithText(variableName); 280 variableListView.SelectedItems.Clear(); 281 if (editLabel) listViewItem.BeginEdit(); 282 } 253 if (e.Effect != DragDropEffects.Copy) return; 254 object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 255 256 string variableName; 257 bool editLabel; 258 259 if (item is KeyValuePair<string, object>) { 260 var variable = (KeyValuePair<string, object>)item; 261 variableName = GenerateNewVariableName(out editLabel, variable.Key, false); 262 item = variable.Value; 263 } else { 264 var namedItem = item as INamedItem; 265 if (namedItem != null) 266 variableName = GenerateNewVariableName(out editLabel, namedItem.Name, false); 267 else 268 variableName = GenerateNewVariableName(out editLabel); 269 } 270 271 var cloneable = item as IDeepCloneable; 272 if (cloneable != null) item = cloneable.Clone(); 273 274 Content.Add(variableName, item); 275 276 var listViewItem = variableListView.FindItemWithText(variableName); 277 variableListView.SelectedItems.Clear(); 278 if (editLabel) listViewItem.BeginEdit(); 283 279 } 284 280 … … 377 373 foreach (ListViewItem item in variableListView.Items) { 378 374 var variable = item.Tag as KeyValuePair<string, object>?; 379 if (variable != null && variable.Value.Value == sender) {380 string value = (variable.Value.Value ?? "null").ToString(); 381 item.SubItems[1].Text = value;382 item.SubItems[2].Text = variable.Value.Value.GetType().ToString();383 SetToolTipText(item, item.ImageIndex != 0);384 }375 if (variable == null || variable.Value.Value != sender) continue; 376 377 string value = (variable.Value.Value ?? "null").ToString(); 378 item.SubItems[1].Text = value; 379 item.SubItems[2].Text = variable.Value.Value.GetType().ToString(); 380 SetToolTipText(item, item.ImageIndex != 0); 385 381 } 386 382 } … … 396 392 foreach (ColumnHeader ch in variableListView.Columns) 397 393 ch.Width = -2; 394 } 395 396 protected virtual void AssignVariableToListViewItem(ListViewItem listViewItem, KeyValuePair<string, object> variable) { 397 string value = (variable.Value ?? "null").ToString(); 398 string type = variable.Value == null ? "null" : variable.Value.GetType().ToString(); 399 400 listViewItem.Tag = variable; 401 402 var subItems = listViewItem.SubItems; 403 subItems[0].Text = variable.Key; 404 if (subItems.Count == 1) { // variable information is added; subitems do not exist yet 405 subItems.AddRange(new[] { value, type }); 406 } else { // variable information is updated; subitems are changed 407 subItems[1].Text = value; 408 subItems[2].Text = type; 409 } 398 410 } 399 411 … … 410 422 var variable = (KeyValuePair<string, object>)listViewItem.Tag; 411 423 if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable"); 412 string value = (variable.Value ?? "null").ToString(); 413 string type = variable.Value == null ? "null" : variable.Value.GetType().ToString(); 424 string value = listViewItem.SubItems[1].Text; 425 string type = listViewItem.SubItems[2].Text; 426 414 427 string[] lines = { 415 428 "Name: " + variable.Key, … … 417 430 "Type: " + type 418 431 }; 432 419 433 string toolTipText = string.Join(Environment.NewLine, lines); 420 434 if (!SafeVariableNameRegex.IsMatch(variable.Key))
Note: See TracChangeset
for help on using the changeset viewer.