Changeset 11436
- Timestamp:
- 10/09/14 16:59:34 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CodeEditor/3.3/CodeEditor.cs
r10359 r11436 133 133 } 134 134 135 public bool ReadOnly { 136 get { return Doc.ReadOnly; } 137 set { Doc.ReadOnly = value; } 138 } 139 135 140 #endregion 136 141 -
trunk/sources/HeuristicLab.Scripting.Views/3.3/ScriptView.cs
r11171 r11436 45 45 } 46 46 47 public override bool ReadOnly { 48 get { return codeEditor.ReadOnly; } 49 set { codeEditor.ReadOnly = value; } 50 } 51 52 public override bool Locked { 53 get { return codeEditor.ReadOnly; } 54 set { codeEditor.ReadOnly = value; } 55 } 56 47 57 protected override void RegisterContentEvents() { 48 58 base.RegisterContentEvents(); … … 83 93 base.SetEnabledStateOfControls(); 84 94 compileButton.Enabled = Content != null && !Locked && !ReadOnly; 85 codeEditor.Enabled = Content != null && !Locked && !ReadOnly;95 codeEditor.Enabled = Content != null; 86 96 } 87 97 -
trunk/sources/HeuristicLab.Scripting.Views/3.3/VariableStoreView.Designer.cs
r10506 r11436 66 66 this.variableListView.LabelEdit = true; 67 67 this.variableListView.Location = new System.Drawing.Point(6, 49); 68 this.variableListView.MultiSelect = false;69 68 this.variableListView.Name = "variableListView"; 70 69 this.variableListView.ShowItemToolTips = true; -
trunk/sources/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs
r11014 r11436 58 58 variableListView.SmallImageList.Images.AddRange(new Image[] { 59 59 HeuristicLab.Common.Resources.VSImageLibrary.Error, 60 HeuristicLab.Common.Resources.VSImageLibrary.Warning, 60 61 HeuristicLab.Common.Resources.VSImageLibrary.Object, 61 62 HeuristicLab.Common.Resources.VSImageLibrary.Nothing … … 90 91 variableListView.Items.Clear(); 91 92 itemListViewItemMapping.Clear(); 92 RebuildImageList();93 93 if (Content != null) { 94 94 Caption += " (" + Content.GetType().Name + ")"; … … 141 141 bool serializable = IsSerializable(variable); 142 142 var listViewItem = new ListViewItem(new[] { variable.Key, value, type }) { ToolTipText = GetToolTipText(variable, serializable), Tag = variable }; 143 if (serializable) { 144 listViewItem.ImageIndex = variable.Value == null ? 2 : 1; 145 } else listViewItem.ImageIndex = 0; 143 bool validIdentifier = SafeVariableNameRegex.IsMatch(variable.Key); 144 if (!serializable) listViewItem.ImageIndex = 0; 145 else if (!validIdentifier) listViewItem.ImageIndex = 1; 146 else if (variable.Value != null) listViewItem.ImageIndex = 2; 147 else listViewItem.ImageIndex = 3; 146 148 variableListView.Items.Add(listViewItem); 147 149 itemListViewItemMapping[variable.Key] = listViewItem; … … 172 174 string type = variable.Value == null ? "null" : variable.Value.GetType().ToString(); 173 175 bool serializable = IsSerializable(variable); 174 if ( serializable) {175 listViewItem.ImageIndex = variable.Value == null ? 2 : 1;176 } else listViewItem.ImageIndex = 0;176 if (!serializable) listViewItem.ImageIndex = 0; 177 else if (variable.Value != null) listViewItem.ImageIndex = 2; 178 else listViewItem.ImageIndex = 3; 177 179 listViewItem.SubItems[1].Text = value; 178 180 listViewItem.SubItems[2].Text = type; … … 188 190 } 189 191 protected virtual void variableListView_KeyDown(object sender, KeyEventArgs e) { 190 if (e.KeyCode == Keys.Delete) { 191 if ((variableListView.SelectedItems.Count > 0) && !Locked && !ReadOnly) { 192 foreach (ListViewItem item in variableListView.SelectedItems) 193 Content.Remove(item.Text); 194 } 192 switch (e.KeyCode) { 193 case Keys.Delete: 194 if ((variableListView.SelectedItems.Count > 0) && !Locked && !ReadOnly) { 195 foreach (ListViewItem item in variableListView.SelectedItems) 196 Content.Remove(item.Text); 197 } 198 break; 199 case Keys.F2: 200 var focusedItem = variableListView.FocusedItem; 201 if (variableListView.LabelEdit && focusedItem.Selected) 202 focusedItem.BeginEdit(); 203 break; 204 case Keys.A: 205 if (e.Modifiers.HasFlag(Keys.Control)) { 206 foreach (ListViewItem item in variableListView.Items) 207 item.Selected = true; 208 } 209 break; 195 210 } 196 211 } … … 211 226 } 212 227 protected virtual void variableListView_ItemDrag(object sender, ItemDragEventArgs e) { 213 if (!Locked) { 214 var items = new List<object>(); 215 foreach (ListViewItem listViewItem in variableListView.SelectedItems) { 216 var item = (KeyValuePair<string, object>)listViewItem.Tag as KeyValuePair<string, object>?; 217 if (item != null) items.Add(item.Value.Value); 218 } 219 220 if (items.Count > 0) { 221 var data = new DataObject(); 222 if (items.Count == 1) data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items[0]); 223 else data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items); 224 if (ReadOnly) { 225 DoDragDrop(data, DragDropEffects.Copy); 226 } else { 227 var result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move); 228 if ((result & DragDropEffects.Move) == DragDropEffects.Move) { 229 foreach (string item in items) Content.Remove(item); 230 } 231 } 232 } 228 if (!Locked && variableListView.SelectedItems.Count == 1) { 229 var listViewItem = variableListView.SelectedItems[0]; 230 var item = (KeyValuePair<string, object>)listViewItem.Tag; 231 var data = new DataObject(HeuristicLab.Common.Constants.DragDropDataFormat, item.Value); 232 DoDragDrop(data, DragDropEffects.Copy); 233 233 } 234 234 } … … 239 239 e.Effect = DragDropEffects.None; 240 240 if (validDragOperation) { 241 if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key 242 else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key 243 else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy; 244 else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move; 245 else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link; 241 if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy; 246 242 } 247 243 } 248 244 protected virtual void variableListView_DragDrop(object sender, DragEventArgs e) { 249 if (e.Effect != DragDropEffects.None) {245 if (e.Effect == DragDropEffects.Copy) { 250 246 object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 251 if (e.Effect.HasFlag(DragDropEffects.Copy)) {252 var cloner = new Cloner();253 var dc = item as IDeepCloneable;254 if (dc != null) item = cloner.Clone(dc);255 }256 string name = GenerateNewVariableName();247 var cloner = new Cloner(); 248 var dc = item as IDeepCloneable; 249 if (dc != null) item = cloner.Clone(dc); 250 var namedItem = item as INamedItem; 251 bool nameValid = namedItem != null && !string.IsNullOrEmpty(namedItem.Name); 252 string name = nameValid ? GenerateNewVariableName(namedItem.Name, false) : GenerateNewVariableName(); 257 253 Content.Add(name, item); 258 254 var listViewItem = variableListView.FindItemWithText(name); 259 listViewItem.BeginEdit();255 if (!nameValid) listViewItem.BeginEdit(); 260 256 } 261 257 } 262 258 263 259 private readonly Regex SafeVariableNameRegex = new Regex("^[@]?[_a-zA-Z][_a-zA-Z0-9]*$"); 260 private const string DefaultVariableName = "enter_name"; 261 264 262 private void variableListView_AfterLabelEdit(object sender, LabelEditEventArgs e) { 265 263 string name = e.Label; … … 327 325 foreach (var item in e.Items) 328 326 RemoveVariable(item); 329 RebuildImageList();330 327 AdjustListViewColumnSizes(); 331 328 } … … 337 334 foreach (var item in e.OldItems) 338 335 RemoveVariable(item); 339 RebuildImageList();340 336 foreach (var item in e.Items) 341 337 AddVariable(item); … … 352 348 item.SubItems[2].Text = variable.Value.Value.GetType().ToString(); 353 349 item.ToolTipText = GetToolTipText(variable.Value, item.ImageIndex != 0); 354 return;355 350 } 356 351 } … … 367 362 foreach (ColumnHeader ch in variableListView.Columns) 368 363 ch.Width = -2; 369 }370 protected virtual void RebuildImageList() {371 variableListView.SmallImageList.Images.Clear();372 variableListView.SmallImageList.Images.AddRange(new Image[] {373 HeuristicLab.Common.Resources.VSImageLibrary.Error,374 HeuristicLab.Common.Resources.VSImageLibrary.Object,375 HeuristicLab.Common.Resources.VSImageLibrary.Nothing376 });377 foreach (ListViewItem listViewItem in variableListView.Items) {378 var variable = (KeyValuePair<string, object>)listViewItem.Tag;379 bool serializable = IsSerializable(variable);380 if (serializable) {381 listViewItem.ImageIndex = variable.Value == null ? 2 : 1;382 } else listViewItem.ImageIndex = 0;383 }384 364 } 385 365 … … 394 374 }; 395 375 string toolTipText = string.Join(Environment.NewLine, lines); 376 if (!SafeVariableNameRegex.IsMatch(variable.Key)) 377 toolTipText = "Caution: Identifier is no valid C# identifier!" + Environment.NewLine + toolTipText; 396 378 if (!serializable) 397 379 toolTipText = "Caution: Type is not serializable!" + Environment.NewLine + toolTipText; … … 399 381 } 400 382 401 private string GenerateNewVariableName(string defaultName = "enter_name") { 383 private string GenerateNewVariableName(string defaultName = DefaultVariableName, bool generateValidIdentifier = true) { 384 if (generateValidIdentifier && !SafeVariableNameRegex.IsMatch(defaultName)) 385 defaultName = DefaultVariableName; 402 386 if (Content.ContainsKey(defaultName)) { 403 387 int i = 1; 388 string formatString = generateValidIdentifier ? "{0}{1}" : "{0} ({1})"; 404 389 string newName; 405 390 do { 406 newName = defaultName + i++;391 newName = string.Format(formatString, defaultName, i++); 407 392 } while (Content.ContainsKey(newName)); 408 393 return newName; -
trunk/sources/HeuristicLab.Scripting/3.3/CSharpScript.cs
r11135 r11436 42 42 // use 'vars.Clear()' to remove all variables 43 43 // use 'foreach (KeyValuePair<string, object> v in vars) { ... }' to iterate over all variables 44 // use 'variables' to work with IEnumerable<T> extension methods on the script's variable store 44 45 45 46 using System; -
trunk/sources/HeuristicLab.Scripting/3.3/CSharpScriptBase.cs
r10857 r11436 27 27 namespace HeuristicLab.Scripting { 28 28 public abstract class CSharpScriptBase { 29 protected Variables variables; 29 30 protected dynamic vars; 30 31 … … 41 42 42 43 internal void Execute(VariableStore variableStore) { 43 var s = new Variables(variableStore);44 variables = vars = new Variables(variableStore); 44 45 Main(); 45 46 }
Note: See TracChangeset
for help on using the changeset viewer.