Esempio n. 1
0
 /// <summary>Moves this block to the specified insertion point on the target block.</summary>
 public ScriptBlock MoveTo(ScriptBlock target, InsertionPoint insertionPoint) {
    var sourceIndex = this.Index;
    var sourceParent = this.ParentBlock;
    var targetIndex = target.Index;
    var targetParent = target.ParentBlock;
    Remove();
    if (sourceParent == targetParent && targetParent != null) {
       // adjust for move in same parent
       if (targetIndex >= sourceIndex) targetIndex--;
    }
    switch (insertionPoint) {
       case InsertionPoint.Before:
          if (targetParent != null && targetIndex >= 0) {
             targetParent.Items.Insert(targetIndex, this);
             targetParent._raiseScriptChangedEvent();
          }
          break;
       case InsertionPoint.After:
          if (targetParent != null && targetIndex >= 0) {
             targetParent.Items.Insert(targetIndex + 1, this);
             targetParent._raiseScriptChangedEvent();
          }
          break;
       case InsertionPoint.Inside:
          target.Items.Add(this);
          target._raiseScriptChangedEvent();
          break;
    }
    return this;
 }