/// <summary> /// Update the operation with details. /// </summary> /// <param name="oldBrowsingIndex">Index of the state before it's replaced.</param> /// <param name="newBrowsingIndex">Index of the state after it's replaced.</param> /// <param name="oldNode">The old node. Can be null if optional and replaced.</param> /// <param name="newChildState">The new state.</param> public virtual void Update(IWriteableBrowsingChildIndex oldBrowsingIndex, IWriteableBrowsingChildIndex newBrowsingIndex, Node oldNode, IWriteableNodeState newChildState) { Contract.RequireNotNull(oldBrowsingIndex, out IWriteableBrowsingChildIndex OldBrowsingIndex); Contract.RequireNotNull(newBrowsingIndex, out IWriteableBrowsingChildIndex NewBrowsingIndex); Contract.RequireNotNull(newChildState, out IWriteableNodeState NewChildState); this.OldBrowsingIndex = OldBrowsingIndex; this.NewBrowsingIndex = NewBrowsingIndex; OldNode = oldNode; this.NewChildState = NewChildState; }
/// <summary> /// Update the operation with details. /// </summary> /// <param name="oldBrowsingIndex">Index of the state before it's replaced.</param> /// <param name="newBrowsingIndex">Index of the state after it's replaced.</param> /// <param name="oldNode">The old node. Can be null if optional and replaced.</param> /// <param name="newChildState">The new state.</param> public virtual void Update(IWriteableBrowsingChildIndex oldBrowsingIndex, IWriteableBrowsingChildIndex newBrowsingIndex, INode oldNode, IWriteableNodeState newChildState) { Debug.Assert(oldBrowsingIndex != null); Debug.Assert(newBrowsingIndex != null); Debug.Assert(newChildState != null); OldBrowsingIndex = oldBrowsingIndex; NewBrowsingIndex = newBrowsingIndex; OldNode = oldNode; NewChildState = newChildState; }
private protected virtual void ReplaceState(IWriteableReplaceOperation operation, IWriteableInner <IWriteableBrowsingChildIndex> inner) { Contract.RequireNotNull(inner, out IWriteableInner <IWriteableBrowsingChildIndex> Inner); 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); IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex> AsOptionalInner = Inner as IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex>; if (AsOptionalInner != null) { IWriteableNodeState OldState = AsOptionalInner.ChildState; PruneStateChildren(OldState); if (AsOptionalInner.IsAssigned) { Stats.AssignedOptionalNodeCount--; } } Inner.Replace(operation); IWriteableBrowsingChildIndex OldBrowsingIndex = operation.OldBrowsingIndex; IWriteableBrowsingChildIndex NewBrowsingIndex = operation.NewBrowsingIndex; IWriteableNodeState ChildState = operation.NewChildState; if (AsOptionalInner != null) { if (AsOptionalInner.IsAssigned) { Stats.AssignedOptionalNodeCount++; } } else { Debug.Assert(Contains(OldBrowsingIndex)); IWriteableNodeState OldState = (IWriteableNodeState)StateTable[OldBrowsingIndex]; PruneStateChildren(OldState); } RemoveState(OldBrowsingIndex); AddState(NewBrowsingIndex, ChildState); BuildStateTable(Inner, null, NewBrowsingIndex, ChildState); }
/// <summary> /// Handler called every time a state is replaced in the controller. /// </summary> /// <param name="operation">Details of the operation performed.</param> private protected virtual void OnStateReplaced(IWriteableReplaceOperation operation) { IWriteableNodeState NewChildState = operation.NewChildState; Debug.Assert(NewChildState != null); Debug.Assert(StateViewTable.ContainsKey(NewChildState)); IWriteableBrowsingChildIndex OldBrowsingIndex = operation.OldBrowsingIndex; Debug.Assert(OldBrowsingIndex != null); Debug.Assert(NewChildState.ParentIndex != OldBrowsingIndex); IWriteableBrowsingChildIndex NewBrowsingIndex = operation.NewBrowsingIndex; Debug.Assert(NewBrowsingIndex != null); Debug.Assert(NewChildState.ParentIndex == NewBrowsingIndex); }
/// <summary> /// Update the operation with details. /// </summary> /// <param name="oldBrowsingIndex">Index of the state before it's replaced.</param> /// <param name="newBrowsingIndex">Index of the state after it's replaced.</param> /// <param name="oldNode">The old node. Can be null if optional and replaced.</param> /// <param name="newChildState">The new state.</param> public override void Update(IWriteableBrowsingChildIndex oldBrowsingIndex, IWriteableBrowsingChildIndex newBrowsingIndex, INode oldNode, IWriteableNodeState newChildState) { base.Update(oldBrowsingIndex, newBrowsingIndex, oldNode, newChildState); int i; for (i = 0; i < CycleIndexList.Count; i++) { IFocusInsertionChildNodeIndex NodeIndex = CycleIndexList[i]; if (NodeIndex.Node == oldNode) { OldCyclePosition = i; break; } } Debug.Assert(OldCyclePosition < CycleIndexList.Count); Debug.Assert(NewCyclePosition < CycleIndexList.Count); }
/// <summary> /// Replace an existing node with a new one. /// </summary> /// <param name="inner">The inner where the node is replaced.</param> /// <param name="replaceIndex">Index for the replace operation.</param> /// <param name="nodeIndex">Index of the replacing node upon return.</param> public void Replace(IWriteableInner inner, IWriteableInsertionChildIndex replaceIndex, out IWriteableBrowsingChildIndex nodeIndex) { Contract.RequireNotNull(inner, out IWriteableInner Inner); Contract.RequireNotNull(replaceIndex, out IWriteableInsertionChildIndex ReplaceIndex); 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); IndexToPositionAndNode(ReplaceIndex, out int BlockIndex, out int Index, out bool ClearNode, out Node NewNode); Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoReplace(operation); Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoReplace(operation); IWriteableReplaceOperation Operation = CreateReplaceOperation(Inner.Owner.Node, Inner.PropertyName, BlockIndex, Index, ClearNode, NewNode, HandlerRedo, HandlerUndo, isNested: false); Operation.Redo(); SetLastOperation(Operation); CheckInvariant(); nodeIndex = Operation.NewBrowsingIndex; }