/// <summary> /// Inserts non existant command node before specified command with all its children. /// Calls CommandInserted event /// </summary> public Command InsertCommandNodeBefore(TreeNode <Command> commandNode, Command commandAfter) { Debug.Assert(!Commands.GetAllNodes().Select(n => n.value).Contains(commandNode.value), "Source Command should not exist on script"); Debug.Assert(Commands.GetAllNodes().Select(n => n.value).Contains(commandAfter), "Destination Command should exist on script"); var nodeAfter = Commands.GetNodeFromValue(commandAfter); var indexAfter = nodeAfter.parent.IndexOf(commandAfter); foreach (var node in commandNode.GetAllNodes()) { m_CommandGuidMap.AddGuidToMapAndGenerateUniqueIfNeeded(node.value); } var nodeToAddCommand = nodeAfter.parent; nodeToAddCommand.Join(commandNode); Commands.MoveBefore(commandNode.value, commandAfter); CommandInsertedInScript?.Invoke(this, nodeAfter.parent.value, commandNode.value, GetIndex(commandNode.value)); m_IsDirty = true; CheckCommandGuidConsistency(); return(commandNode.value); }
/// <summary> /// Insert single non existant command to specific location. /// </summary> public Command InsertCommand(Command command, int position, Command parentCommand = null) { Debug.Assert(!Commands.GetAllNodes().Select(n => n.value).Contains(command), "Command should not exist on script"); var treeNodeToInsert = (parentCommand == null) ? Commands : Commands.GetNodeFromValue(parentCommand); treeNodeToInsert.Insert(position, command); m_CommandGuidMap.AddGuidToMapAndGenerateUniqueIfNeeded(command); m_IsDirty = true; CommandInsertedInScript?.Invoke(this, parentCommand, command, position); CheckCommandGuidConsistency(); return(command); }
/// <summary> /// Moves an existing command from script to other place. /// Calls Removed and Inserted command events. /// </summary> public void MoveCommandBefore(Command source, Command before) { Debug.Assert(Commands.GetAllNodes().Select(n => n.value).Contains(source), "Source Command should exist on script"); Debug.Assert(Commands.GetAllNodes().Select(n => n.value).Contains(before), "Destination Command should exist on script"); var oldIndex = GetIndex(source); var sourceParentCommand = Commands.GetNodeFromValue(source).parent.value; var destParentCommand = Commands.GetNodeFromValue(before).parent.value; Commands.MoveBefore(source, before); CommandRemovedFromScript?.Invoke(this, sourceParentCommand, oldIndex); CommandInsertedInScript?.Invoke(this, destParentCommand, source, GetIndex(source)); m_IsDirty = true; CheckCommandGuidConsistency(); }
private void InvokeCommandInsertedInScript(Script script, Command parentCommand, Command command, int index) { CommandInsertedInScript?.Invoke(script, parentCommand, command, index); }