/// <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> /// Removes a node from a list or block list. /// </summary> /// <param name="operation">Details of the operation performed.</param> public virtual void Remove(WriteableRemoveNodeOperation operation) { int RemoveIndex = operation.Index; Debug.Assert(RemoveIndex >= 0 && RemoveIndex < StateList.Count); IWriteablePlaceholderNodeState OldChildState = (IWriteablePlaceholderNodeState)StateList[RemoveIndex]; RemoveFromStateList(RemoveIndex); Node ParentNode = Owner.Node; NodeTreeHelperList.RemoveFromList(ParentNode, PropertyName, RemoveIndex); while (RemoveIndex < StateList.Count) { IWriteablePlaceholderNodeState State = (IWriteablePlaceholderNodeState)StateList[RemoveIndex]; IWriteableBrowsingListNodeIndex NodeIndex = State.ParentIndex as IWriteableBrowsingListNodeIndex; Debug.Assert(NodeIndex != null); Debug.Assert(NodeIndex.Index == RemoveIndex + 1); NodeIndex.MoveDown(); RemoveIndex++; } operation.Update(OldChildState); }
/// <summary> /// Replaces a node. /// </summary> /// <param name="operation">Details of the operation performed.</param> public virtual void Replace(IWriteableReplaceOperation operation) { Debug.Assert(operation != null); int Index = operation.Index; Debug.Assert(Index >= 0 && Index < StateList.Count); INode ParentNode = Owner.Node; IWriteableNodeState OldChildState = StateList[Index]; INode OldNode = OldChildState.Node; IWriteableBrowsingListNodeIndex OldBrowsingIndex = (IWriteableBrowsingListNodeIndex)OldChildState.ParentIndex; RemoveFromStateList(Index); NodeTreeHelperList.ReplaceNode(ParentNode, PropertyName, Index, operation.NewNode); IWriteableBrowsingListNodeIndex NewBrowsingIndex = CreateBrowsingNodeIndex(operation.NewNode, Index); IWriteablePlaceholderNodeState NewChildState = (IWriteablePlaceholderNodeState)CreateNodeState(NewBrowsingIndex); InsertInStateList(Index, NewChildState); operation.Update(OldBrowsingIndex, NewBrowsingIndex, OldNode, NewChildState); }
/// <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(); } } }
void IList <IWriteableBrowsingListNodeIndex> .Insert(int index, IWriteableBrowsingListNodeIndex item) { Insert(index, (ILayoutBrowsingListNodeIndex)item); }
int IList <IWriteableBrowsingListNodeIndex> .IndexOf(IWriteableBrowsingListNodeIndex value) { return(IndexOf((ILayoutBrowsingListNodeIndex)value)); }
bool ICollection <IWriteableBrowsingListNodeIndex> .Remove(IWriteableBrowsingListNodeIndex item) { return(Remove((ILayoutBrowsingListNodeIndex)item)); }
bool ICollection <IWriteableBrowsingListNodeIndex> .Contains(IWriteableBrowsingListNodeIndex value) { return(Contains((ILayoutBrowsingListNodeIndex)value)); }
void ICollection <IWriteableBrowsingListNodeIndex> .Add(IWriteableBrowsingListNodeIndex item) { Add((ILayoutBrowsingListNodeIndex)item); }
/// <summary> /// Split an identifier with replace and insert indexes. /// </summary> /// <param name="inner">The inner where the node is replaced.</param> /// <param name="replaceIndex">Index for the replace operation.</param> /// <param name="insertIndex">Index for the insert operation.</param> /// <param name="firstIndex">Index of the replacing node upon return.</param> /// <param name="secondIndex">Index of the inserted node upon return.</param> public virtual void SplitIdentifier(IWriteableListInner inner, IWriteableInsertionListNodeIndex replaceIndex, IWriteableInsertionListNodeIndex insertIndex, out IWriteableBrowsingListNodeIndex firstIndex, out IWriteableBrowsingListNodeIndex secondIndex) { Contract.RequireNotNull(inner, out IWriteableListInner Inner); Contract.RequireNotNull(replaceIndex, out IWriteableInsertionListNodeIndex ReplaceIndex); Contract.RequireNotNull(insertIndex, out IWriteableInsertionListNodeIndex InsertIndex); IWriteableNodeState Owner = Inner.Owner; IWriteableIndex ParentIndex = Owner.ParentIndex; Debug.Assert(Contains(ParentIndex)); Debug.Assert(IndexToState(ParentIndex) == Owner); WriteableInnerReadOnlyDictionary <string> InnerTable = Owner.InnerTable; Debug.Assert(InnerTable.ContainsKey(Inner.PropertyName)); Debug.Assert(InnerTable[Inner.PropertyName] == Inner); int Index = ReplaceIndex.Index; Debug.Assert(InsertIndex.Index == Index + 1); Node ReplacingNode = ReplaceIndex.Node; Node InsertedNode = InsertIndex.Node; Action <IWriteableOperation> HandlerRedoReplace = (IWriteableOperation operation) => RedoReplace(operation); Action <IWriteableOperation> HandlerUndoReplace = (IWriteableOperation operation) => UndoReplace(operation); IWriteableReplaceOperation ReplaceOperation = CreateReplaceOperation(Inner.Owner.Node, Inner.PropertyName, -1, Index, clearNode: false, ReplacingNode, HandlerRedoReplace, HandlerUndoReplace, isNested: true); Action <IWriteableOperation> HandlerRedoInsert = (IWriteableOperation operation) => RedoInsertNewNode(operation); Action <IWriteableOperation> HandlerUndoInsert = (IWriteableOperation operation) => UndoInsertNewNode(operation); WriteableInsertNodeOperation InsertOperation = CreateInsertNodeOperation(Inner.Owner.Node, Inner.PropertyName, -1, Index + 1, InsertedNode, HandlerRedoInsert, HandlerUndoInsert, isNested: true); ReplaceOperation.Redo(); InsertOperation.Redo(); Action <IWriteableOperation> HandlerRedoRefresh = (IWriteableOperation operation) => RedoRefresh(operation); Action <IWriteableOperation> HandlerUndoRefresh = (IWriteableOperation operation) => throw new NotImplementedException(); // Undo is not possible. WriteableGenericRefreshOperation RefreshOperation = CreateGenericRefreshOperation(RootState, HandlerRedoRefresh, HandlerUndoRefresh, isNested: false); RefreshOperation.Redo(); WriteableOperationList OperationList = CreateOperationList(); OperationList.Add(ReplaceOperation); OperationList.Add(InsertOperation); WriteableOperationReadOnlyList OperationReadOnlyList = OperationList.ToReadOnly(); WriteableOperationGroup OperationGroup = CreateOperationGroup(OperationReadOnlyList, RefreshOperation); SetLastOperation(OperationGroup); CheckInvariant(); firstIndex = ReplaceOperation.NewBrowsingIndex as IWriteableBrowsingListNodeIndex; Debug.Assert(firstIndex != null); secondIndex = InsertOperation.BrowsingIndex as IWriteableBrowsingListNodeIndex; Debug.Assert(secondIndex != null); }