private void treeListView_ModelDropped(object sender, ModelDropEventArgs e) { var targetNode = e.TargetModel as HierarchyNode; var sourceNode = e.SourceModels[0] as HierarchyNode; if (targetNode.Script != null && sourceNode.Script != null) { if (e.DropTargetLocation == DropTargetLocation.AboveItem) { ScriptManager.MoveScriptBefore(sourceNode.Script.GetIndex(ScriptManager), targetNode.Script.GetIndex(ScriptManager)); } if (e.DropTargetLocation == DropTargetLocation.BelowItem) { ScriptManager.MoveScriptAfter(sourceNode.Script.GetIndex(ScriptManager), targetNode.Script.GetIndex(ScriptManager)); } } if (targetNode.Command != null && sourceNode.Command != null) { var targetScript = ScriptManager.GetScriptFromCommand(targetNode.Command); var sourceScript = ScriptManager.GetScriptFromCommand(sourceNode.Command); if (e.DropTargetLocation == DropTargetLocation.AboveItem) { ScriptManager.MoveCommandBefore(sourceNode.Command, targetNode.Command, sourceScript.GetIndex(ScriptManager), targetScript.GetIndex(ScriptManager)); } if (e.DropTargetLocation == DropTargetLocation.BelowItem) { ScriptManager.MoveCommandAfter(sourceNode.Command, targetNode.Command, sourceScript.GetIndex(ScriptManager), targetScript.GetIndex(ScriptManager)); } if (e.DropTargetLocation == DropTargetLocation.Item && targetNode.Command.CanBeNested) { var node = sourceScript.Commands.GetNodeFromValue(sourceNode.Command); sourceScript.RemoveCommand(sourceNode.Command); targetScript.AddCommandNode(node, targetNode.Command); } } if (targetNode.Script != null && sourceNode.Command != null) { var sourceScript = ScriptManager.GetScriptFromCommand(sourceNode.Command); var node = sourceScript.Commands.GetNodeFromValue(sourceNode.Command); sourceScript.RemoveCommand(sourceNode.Command); targetNode.Script.AddCommandNode(node); } }