/// <summary> /// Inserts a new node in a list. /// </summary> /// <param name="operation">Details of the operation performed.</param> public virtual void Insert(WriteableInsertNodeOperation operation) { int InsertionIndex = operation.Index; Debug.Assert(InsertionIndex >= 0 && InsertionIndex <= StateList.Count); Node ParentNode = Owner.Node; Node Node = operation.Node; NodeTreeHelperList.InsertIntoList(ParentNode, PropertyName, InsertionIndex, Node); IWriteableBrowsingListNodeIndex BrowsingIndex = CreateBrowsingNodeIndex(Node, InsertionIndex); IWriteablePlaceholderNodeState ChildState = (IWriteablePlaceholderNodeState)CreateNodeState(BrowsingIndex); InsertInStateList(InsertionIndex, ChildState); operation.Update(BrowsingIndex, ChildState); while (++InsertionIndex < StateList.Count) { IWriteablePlaceholderNodeState State = (IWriteablePlaceholderNodeState)StateList[InsertionIndex]; IWriteableBrowsingListNodeIndex NodeIndex = State.ParentIndex as IWriteableBrowsingListNodeIndex; Debug.Assert(NodeIndex != null); Debug.Assert(NodeIndex.Index == InsertionIndex - 1); NodeIndex.MoveUp(); } }
/// <summary> /// Moves a node around in a list or block list. In a block list, the node stays in same block. /// </summary> /// <param name="operation">Details of the operation performed.</param> public virtual void Move(IWriteableMoveNodeOperation operation) { Debug.Assert(operation != null); int MoveIndex = operation.Index; int Direction = operation.Direction; Debug.Assert(MoveIndex >= 0 && MoveIndex < StateList.Count); Debug.Assert(MoveIndex + operation.Direction >= 0 && MoveIndex + operation.Direction < StateList.Count); IWriteableBrowsingListNodeIndex MovedNodeIndex = StateList[MoveIndex].ParentIndex as IWriteableBrowsingListNodeIndex; Debug.Assert(MovedNodeIndex != null); INode ParentNode = Owner.Node; MoveInStateList(MoveIndex, Direction); NodeTreeHelperList.MoveNode(ParentNode, PropertyName, MoveIndex, Direction); operation.Update(StateList[MoveIndex + Direction]); if (Direction > 0) { for (int i = MoveIndex; i < MoveIndex + Direction; i++) { IWriteableBrowsingListNodeIndex ChildNodeIndex = StateList[i].ParentIndex as IWriteableBrowsingListNodeIndex; Debug.Assert(ChildNodeIndex != null); ChildNodeIndex.MoveDown(); MovedNodeIndex.MoveUp(); } } else if (Direction < 0) { for (int i = MoveIndex; i > MoveIndex + Direction; i--) { IWriteableBrowsingListNodeIndex ChildNodeIndex = StateList[i].ParentIndex as IWriteableBrowsingListNodeIndex; Debug.Assert(ChildNodeIndex != null); ChildNodeIndex.MoveUp(); MovedNodeIndex.MoveDown(); } } }