private protected virtual void ExecuteReplaceWithCycle(IWriteableOperation operation) { IFocusReplaceWithCycleOperation ReplaceWithCycleOperation = (IFocusReplaceWithCycleOperation)operation; Node ParentNode = ReplaceWithCycleOperation.ParentNode; string PropertyName = ReplaceWithCycleOperation.PropertyName; IFocusInner <IFocusBrowsingChildIndex> Inner = GetInner(ParentNode, PropertyName) as IFocusInner <IFocusBrowsingChildIndex>; ReplaceState(ReplaceWithCycleOperation, Inner); IFocusCyclableNodeState NewState = StateTable[ReplaceWithCycleOperation.NewBrowsingIndex] as IFocusCyclableNodeState; Debug.Assert(NewState != null); NewState.RestoreCycleIndexList(ReplaceWithCycleOperation.CycleIndexList); NotifyStateReplaced(ReplaceWithCycleOperation); }
/// <summary> /// Replace an existing node with a new one, keeping its cycle. /// </summary> /// <param name="inner">The inner where the node is replaced.</param> /// <param name="cycleIndexList">Cycle of nodes that can replace the current node.</param> /// <param name="cyclePosition">New position in the cycle.</param> /// <param name="nodeIndex">Index of the replacing node upon return.</param> public virtual void Replace(IFocusInner inner, FocusInsertionChildNodeIndexList cycleIndexList, int cyclePosition, out IFocusBrowsingChildIndex nodeIndex) { Contract.RequireNotNull(cycleIndexList, out FocusInsertionChildNodeIndexList CycleIndexList); Debug.Assert(CycleIndexList.Count >= 2); Debug.Assert(cyclePosition >= 0 && cyclePosition < CycleIndexList.Count); IFocusInsertionChildNodeIndex ReplacementIndex = CycleIndexList[cyclePosition]; IndexToPositionAndNode(ReplacementIndex, out int BlockIndex, out int Index, out _, out Node Node); System.Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => ExecuteReplaceWithCycle(operation); System.Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoReplaceWithCycle(operation); IFocusReplaceWithCycleOperation Operation = CreateReplaceWithCycleOperation(inner.Owner.Node, inner.PropertyName, BlockIndex, Index, CycleIndexList, cyclePosition, HandlerRedo, HandlerUndo, isNested: false); ExecuteReplaceWithCycle(Operation); nodeIndex = Operation.NewBrowsingIndex; SetLastOperation(Operation); CheckInvariant(); }