Changeset 10577
- Timestamp:
- 03/12/14 14:40:08 (11 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs
r10506 r10577 220 220 221 221 if (items.Count > 0) { 222 DataObjectdata = new DataObject();222 var data = new DataObject(); 223 223 if (items.Count == 1) data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items[0]); 224 224 else data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items); 225 225 if (ReadOnly) { 226 DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);226 DoDragDrop(data, DragDropEffects.Copy); 227 227 } else { 228 DragDropEffectsresult = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);228 var result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move); 229 229 if ((result & DragDropEffects.Move) == DragDropEffects.Move) { 230 230 foreach (string item in items) Content.Remove(item); … … 235 235 } 236 236 protected virtual void variableListView_DragEnter(object sender, DragEventArgs e) { 237 validDragOperation = false; 238 if (!Locked && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is object)) { 239 validDragOperation = true; 240 } else if (!Locked && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) { 241 validDragOperation = true; 242 IEnumerable items = (IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 243 foreach (object item in items) 244 validDragOperation = validDragOperation && (item is object); 245 } 237 validDragOperation = !Locked && !ReadOnly && e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) != null; 246 238 } 247 239 protected virtual void variableListView_DragOver(object sender, DragEventArgs e) { … … 257 249 protected virtual void variableListView_DragDrop(object sender, DragEventArgs e) { 258 250 if (e.Effect != DragDropEffects.None) { 259 if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable) { 260 IEnumerable<object> items = ((IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat)).Cast<object>(); 261 if (e.Effect.HasFlag(DragDropEffects.Copy)) { 262 var cloner = new Cloner(); 263 var clonedItems = new List<object>(); 264 foreach (var item in items) { 265 var dc = item as IDeepCloneable; 266 clonedItems.Add(dc != null ? cloner.Clone(dc) : item); 267 } 268 items = clonedItems; 269 } 270 foreach (var item in items) { 271 string name = GenerateNewVariableName(); 272 Content.Add(name, item); 273 var listViewItem = variableListView.FindItemWithText(name); 274 listViewItem.BeginEdit(); 275 } 276 } else { 277 object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 278 if (e.Effect.HasFlag(DragDropEffects.Copy)) { 279 var cloner = new Cloner(); 280 var dc = item as IDeepCloneable; 281 if (dc != null) item = cloner.Clone(dc); 282 } 283 string name = GenerateNewVariableName(); 284 Content.Add(name, item); 285 var listViewItem = variableListView.FindItemWithText(name); 286 listViewItem.BeginEdit(); 287 } 251 object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 252 if (e.Effect.HasFlag(DragDropEffects.Copy)) { 253 var cloner = new Cloner(); 254 var dc = item as IDeepCloneable; 255 if (dc != null) item = cloner.Clone(dc); 256 } 257 string name = GenerateNewVariableName(); 258 Content.Add(name, item); 259 var listViewItem = variableListView.FindItemWithText(name); 260 listViewItem.BeginEdit(); 288 261 } 289 262 } -
trunk/sources/HeuristicLab.Scripting/3.3/Script.cs
r10566 r10577 45 45 private const string ExecuteMethodName = "Execute"; 46 46 private const string CodeTemplate = 47 @"// use 'vars' to access global variables in the variable store 47 @"// use 'vars' to access variables in the script's variable store 48 // vars has a Contains(string) method to check if a variable exists and implements IEnumerable 48 49 49 50 using System; … … 59 60 } 60 61 61 // further classes and methods62 // implement further classes and methods 62 63 63 64 }"; … … 117 118 compileErrors = new CompilerErrorCollection(original.compileErrors); 118 119 } 119 120 public Script()121 : base("Script", "A HeuristicLab script.") {120 public Script() { 121 name = ItemName; 122 description = ItemDescription; 122 123 code = CodeTemplate; 123 124 variableStore = new VariableStore(); 125 } 126 public Script(string code) 127 : this() { 128 this.code = code; 124 129 } 125 130
Note: See TracChangeset
for help on using the changeset viewer.