Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10577


Ignore:
Timestamp:
03/12/14 14:40:08 (10 years ago)
Author:
abeham
Message:

#2136:

  • Fixed drag-drop behavior in VariableStoreView
  • Added additional information to Script and changed setting name and description
Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs

    r10506 r10577  
    220220
    221221        if (items.Count > 0) {
    222           DataObject data = new DataObject();
     222          var data = new DataObject();
    223223          if (items.Count == 1) data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items[0]);
    224224          else data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items);
    225225          if (ReadOnly) {
    226             DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
     226            DoDragDrop(data, DragDropEffects.Copy);
    227227          } else {
    228             DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
     228            var result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    229229            if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
    230230              foreach (string item in items) Content.Remove(item);
     
    235235    }
    236236    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;
    246238    }
    247239    protected virtual void variableListView_DragOver(object sender, DragEventArgs e) {
     
    257249    protected virtual void variableListView_DragDrop(object sender, DragEventArgs e) {
    258250      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();
    288261      }
    289262    }
  • trunk/sources/HeuristicLab.Scripting/3.3/Script.cs

    r10566 r10577  
    4545    private const string ExecuteMethodName = "Execute";
    4646    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
    4849
    4950using System;
     
    5960  }
    6061
    61   // further classes and methods
     62  // implement further classes and methods
    6263
    6364}";
     
    117118        compileErrors = new CompilerErrorCollection(original.compileErrors);
    118119    }
    119 
    120     public Script()
    121       : base("Script", "A HeuristicLab script.") {
     120    public Script() {
     121      name = ItemName;
     122      description = ItemDescription;
    122123      code = CodeTemplate;
    123124      variableStore = new VariableStore();
     125    }
     126    public Script(string code)
     127      : this() {
     128      this.code = code;
    124129    }
    125130
Note: See TracChangeset for help on using the changeset viewer.