private protected virtual void UndoSplitBlock(IWriteableOperation operation) { WriteableSplitBlockOperation SplitBlockOperation = (WriteableSplitBlockOperation)operation; WriteableMergeBlocksOperation MergeBlocksOperation = SplitBlockOperation.ToMergeBlocksOperation(); ExecuteMergeBlocks(MergeBlocksOperation); }
private protected virtual void ExecuteSplitBlock(WriteableSplitBlockOperation operation) { Node ParentNode = operation.ParentNode; string PropertyName = operation.PropertyName; IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> Inner = GetInner(ParentNode, PropertyName) as IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex>; IWriteableBlockState OldBlockState = (IWriteableBlockState)Inner.BlockStateList[operation.BlockIndex]; Debug.Assert(operation.Index < OldBlockState.StateList.Count); int OldNodeCount = OldBlockState.StateList.Count; Inner.SplitBlock(operation); Stats.BlockCount++; IWriteableBlockState NewBlockState = operation.BlockState; Debug.Assert(OldBlockState.StateList.Count + NewBlockState.StateList.Count == OldNodeCount); Debug.Assert(NewBlockState.StateList.Count > 0); IReadOnlyBrowsingPatternIndex PatternIndex = NewBlockState.PatternIndex; IReadOnlyPatternState PatternState = NewBlockState.PatternState; AddState(PatternIndex, PatternState); Stats.PlaceholderNodeCount++; IReadOnlyBrowsingSourceIndex SourceIndex = NewBlockState.SourceIndex; IReadOnlySourceState SourceState = NewBlockState.SourceState; AddState(SourceIndex, SourceState); Stats.PlaceholderNodeCount++; NotifyBlockSplit(operation); }
/// <summary> /// Handler called every time a block split in the controller. /// </summary> /// <param name="operation">Details of the operation performed.</param> private protected virtual void OnBlockSplit(WriteableSplitBlockOperation operation) { Debug.Assert(!operation.IsNested); IWriteableBlockState BlockState = operation.BlockState; Debug.Assert(BlockState != null); Debug.Assert(BlockStateViewTable.ContainsKey(BlockState)); }
/// <summary> /// Splits a block in two at the given index. /// </summary> /// <param name="inner">The inner where the block is split.</param> /// <param name="nodeIndex">Index of the last node to stay in the old block.</param> public virtual void SplitBlock(IWriteableBlockListInner inner, IWriteableBrowsingExistingBlockNodeIndex nodeIndex) { Contract.RequireNotNull(inner, out IWriteableBlockListInner Inner); Contract.RequireNotNull(nodeIndex, out IWriteableBrowsingExistingBlockNodeIndex NodeIndex); Debug.Assert(Inner.IsSplittable(NodeIndex)); IWriteableBlockState BlockState = (IWriteableBlockState)Inner.BlockStateList[NodeIndex.BlockIndex]; ReplicationStatus Replication = BlockState.ChildBlock.Replication; Pattern NewPatternNode = NodeHelper.CreateSimplePattern(BlockState.ChildBlock.ReplicationPattern.Text); Identifier NewSourceNode = NodeHelper.CreateSimpleIdentifier(BlockState.ChildBlock.SourceIdentifier.Text); IBlock NewBlock = NodeTreeHelperBlockList.CreateBlock(Inner.Owner.Node, Inner.PropertyName, Replication, NewPatternNode, NewSourceNode); Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoSplitBlock(operation); Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoSplitBlock(operation); WriteableSplitBlockOperation Operation = CreateSplitBlockOperation(Inner.Owner.Node, Inner.PropertyName, NodeIndex.BlockIndex, NodeIndex.Index, NewBlock, HandlerRedo, HandlerUndo, isNested: false); Operation.Redo(); SetLastOperation(Operation); CheckInvariant(); }
private protected virtual void RedoSplitBlock(IWriteableOperation operation) { WriteableSplitBlockOperation SplitBlockOperation = (WriteableSplitBlockOperation)operation; ExecuteSplitBlock(SplitBlockOperation); }
private protected virtual void NotifyBlockSplit(WriteableSplitBlockOperation operation) { BlockSplitHandler?.Invoke(operation); }
/// <summary> /// Splits a block in two at the given index. /// </summary> /// <param name="operation">Details of the operation performed.</param> public virtual void SplitBlock(WriteableSplitBlockOperation operation) { int SplitBlockIndex = operation.BlockIndex; Debug.Assert(SplitBlockIndex >= 0 && SplitBlockIndex < BlockStateList.Count); int SplitIndex = operation.Index; Debug.Assert(SplitIndex > 0); IWriteableBlockState BlockState = (IWriteableBlockState)BlockStateList[SplitBlockIndex]; Debug.Assert(SplitIndex < BlockState.StateList.Count); IBlock NewBlock = operation.NewBlock; Debug.Assert(NewBlock != null); NodeTreeHelperBlockList.SplitBlock(Owner.Node, PropertyName, SplitBlockIndex, SplitIndex, NewBlock); NodeTreeHelperBlockList.GetChildNode(NewBlock, 0, out Node NewBlockFirstNode); IWriteableBrowsingNewBlockNodeIndex NewBlockIndex = CreateNewBlockNodeIndex(NewBlockFirstNode, SplitBlockIndex); IWriteableBlockState NewBlockState = (IWriteableBlockState)CreateBlockState(NewBlockIndex, NewBlock); ((IWriteableBlockState <IWriteableInner <IWriteableBrowsingChildIndex> >)NewBlockState).InitBlockState(); InsertInBlockStateList(NewBlockIndex.BlockIndex, NewBlockState); for (int i = 0; i < SplitIndex; i++) { IWriteablePlaceholderNodeState State = (IWriteablePlaceholderNodeState)BlockState.StateList[0]; IWriteableBrowsingExistingBlockNodeIndex ChildNodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex; Debug.Assert(ChildNodeIndex != null); BlockState.Remove(ChildNodeIndex, 0); NewBlockState.Insert(ChildNodeIndex, i, State); } operation.Update(NewBlockState); for (int i = 0; i < BlockState.StateList.Count; i++) { IWriteablePlaceholderNodeState State = (IWriteablePlaceholderNodeState)BlockState.StateList[i]; IWriteableBrowsingExistingBlockNodeIndex ChildNodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex; Debug.Assert(ChildNodeIndex != null); ChildNodeIndex.MoveBlockUp(); for (int j = 0; j < SplitIndex; j++) { ChildNodeIndex.MoveDown(); } } for (int i = SplitBlockIndex + 2; i < BlockStateList.Count; i++) { foreach (IWriteablePlaceholderNodeState State in BlockStateList[i].StateList) { IWriteableBrowsingExistingBlockNodeIndex ChildNodeIndex = State.ParentIndex as IWriteableBrowsingExistingBlockNodeIndex; Debug.Assert(ChildNodeIndex != null); ChildNodeIndex.MoveBlockUp(); } } }