/// <summary> /// Handler called every time a block state is removed in the controller. /// </summary> /// <param name="blockState">The block state removed.</param> public virtual void OnBlockStateRemoved(IReadOnlyBlockState blockState) { Contract.RequireNotNull(blockState, out IReadOnlyBlockState BlockState); Debug.Assert(BlockStateViewTable.ContainsKey(BlockState)); BlockStateViewTable.Remove(BlockState); }
/// <summary> /// Handler called every time a block state is removed in the controller. /// </summary> /// <param name="blockState">The block state removed.</param> public virtual void OnBlockStateRemoved(IReadOnlyBlockState blockState) { Debug.Assert(blockState != null); Debug.Assert(BlockStateViewTable.ContainsKey(blockState)); BlockStateViewTable.Remove(blockState); }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlySourceState{IInner}"/> class. /// </summary> /// <param name="parentBlockState">The parent block state.</param> /// <param name="index">The index used to create the state.</param> public ReadOnlySourceState(IReadOnlyBlockState parentBlockState, IReadOnlyBrowsingSourceIndex index) : base(index) { Debug.Assert(parentBlockState != null); ParentBlockState = parentBlockState; }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyPatternState{IInner}"/> class. /// </summary> /// <param name="parentBlockState">The parent block state.</param> /// <param name="index">The index used to create the state.</param> public ReadOnlyPatternState(IReadOnlyBlockState parentBlockState, IReadOnlyBrowsingPatternIndex index) : base(index) { Debug.Assert(parentBlockState != null); ParentBlockState = parentBlockState; }
bool IDictionary <IReadOnlyBlockState, IReadOnlyBlockStateView> .TryGetValue(IReadOnlyBlockState key, out IReadOnlyBlockStateView value) { bool Result = TryGetValue((IFrameBlockState)key, out IFrameBlockStateView Value); value = Value; return(Result); }
/// <summary> /// Checks if a state is the child of another. This method returns true if <paramref name="parentState"/> and <paramref name="state"/> are the same. /// </summary> /// <param name="parentState">The parent state.</param> /// <param name="state">The state to check.</param> /// <param name="firstIndex">The first index in the chain leading from the parent to the child. Null if they are the same.</param> /// <returns>True if <paramref name="parentState"/> is <paramref name="state"/> or a parent; Otherwise, false.</returns> public virtual bool IsChildState(IReadOnlyNodeState parentState, IReadOnlyNodeState state, out IReadOnlyIndex firstIndex) { firstIndex = null; while (state != null) { if (state == parentState) { return(true); } if (state is IReadOnlyPatternState AsPatternState) { IReadOnlyBlockState BlockState = AsPatternState.ParentBlockState; Debug.Assert(BlockState.StateList.Count > 0); IReadOnlyPlaceholderNodeState FirstState = BlockState.StateList[0]; firstIndex = FirstState.ParentIndex; } else if (state is IReadOnlySourceState AsSourceState) { IReadOnlyBlockState BlockState = AsSourceState.ParentBlockState; Debug.Assert(BlockState.StateList.Count > 0); IReadOnlyPlaceholderNodeState FirstState = BlockState.StateList[0]; firstIndex = FirstState.ParentIndex; } else { firstIndex = state.ParentIndex; } state = state.ParentState; } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyBlockStateView"/> class. /// </summary> /// <param name="controllerView">The controller view to which this object belongs.</param> /// <param name="blockState">The block state.</param> public ReadOnlyBlockStateView(ReadOnlyControllerView controllerView, IReadOnlyBlockState blockState) { Contract.RequireNotNull(controllerView, out ReadOnlyControllerView ControllerView); Contract.RequireNotNull(blockState, out IReadOnlyBlockState BlockState); this.ControllerView = ControllerView; this.BlockState = BlockState; }
private protected virtual void InsertInBlockStateList(int blockIndex, IReadOnlyBlockState blockState) { Debug.Assert(blockIndex >= 0 && blockIndex <= BlockStateList.Count); _BlockStateList.Insert(blockIndex, blockState); NotifyBlockStateCreated(BlockStateList[blockIndex]); }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyBlockStateView"/> class. /// </summary> /// <param name="controllerView">The controller view to which this object belongs.</param> /// <param name="blockState">The block state.</param> public ReadOnlyBlockStateView(IReadOnlyControllerView controllerView, IReadOnlyBlockState blockState) { Debug.Assert(controllerView != null); Debug.Assert(blockState != null); ControllerView = controllerView; BlockState = blockState; }
/// <summary> /// Handler called every time a block state is created in the controller. /// </summary> /// <param name="blockState">The block state created.</param> public virtual void OnBlockStateCreated(IReadOnlyBlockState blockState) { Contract.RequireNotNull(blockState, out IReadOnlyBlockState BlockState); Debug.Assert(!BlockStateViewTable.ContainsKey(BlockState)); ReadOnlyBlockStateView BlockStateView = CreateBlockStateView(BlockState); BlockStateViewTable.Add(BlockState, BlockStateView); }
private protected virtual void MoveInBlockStateList(int blockIndex, int direction) { Debug.Assert(blockIndex >= 0 && blockIndex < BlockStateList.Count); Debug.Assert(blockIndex + direction >= 0 && blockIndex + direction < BlockStateList.Count); IReadOnlyBlockState BlockState = _BlockStateList[blockIndex]; _BlockStateList.RemoveAt(blockIndex); _BlockStateList.Insert(blockIndex + direction, BlockState); }
/// <summary> /// Gets the index of the node at the given position. /// </summary> /// <param name="blockIndex">Position of the block in the block list.</param> /// <param name="index">Position of the node in the block.</param> /// <returns>The index of the node at position <paramref name="blockIndex"/> and <paramref name="index"/>.</returns> public virtual IReadOnlyBrowsingExistingBlockNodeIndex IndexAt(int blockIndex, int index) { Debug.Assert(blockIndex >= 0 && blockIndex < BlockStateList.Count); IReadOnlyBlockState BlockState = BlockStateList[blockIndex]; Debug.Assert(index >= 0 && index < BlockState.StateList.Count); return((IReadOnlyBrowsingExistingBlockNodeIndex)BlockState.StateList[index].ParentIndex); }
/// <summary> /// Handler called every time a block state is created in the controller. /// </summary> /// <param name="blockState">The block state created.</param> public virtual void OnBlockStateCreated(IReadOnlyBlockState blockState) { Debug.Assert(blockState != null); Debug.Assert(!BlockStateViewTable.ContainsKey(blockState)); IReadOnlyBlockStateView BlockStateView = CreateBlockStateView(blockState); Debug.Assert(BlockStateView.ToString() != null); // For code coverage. BlockStateViewTable.Add(blockState, BlockStateView); }
private protected virtual ReadOnlyNodeStateDictionary BuildChildrenStateTable(ReadOnlyBrowseContext browseContext) { IReadOnlyNodeState State = browseContext.State; ReadOnlyInnerReadOnlyDictionary <string> InnerTable = State.InnerTable; ReadOnlyIndexCollectionReadOnlyList IndexCollectionList = browseContext.IndexCollectionList; ReadOnlyNodeStateDictionary ChildStateTable = CreateChildStateTable(); foreach (IReadOnlyIndexCollection <IReadOnlyBrowsingChildIndex> NodeIndexCollection in IndexCollectionList) { // List of indexes for this property (one for placeholder and optional node, several for lists and block lists) IReadOnlyList <IReadOnlyBrowsingChildIndex> NodeIndexList = NodeIndexCollection.NodeIndexList; string PropertyName = NodeIndexCollection.PropertyName; Debug.Assert(InnerTable.ContainsKey(PropertyName)); IReadOnlyInner <IReadOnlyBrowsingChildIndex> Inner = (IReadOnlyInner <IReadOnlyBrowsingChildIndex>)InnerTable[PropertyName]; for (int i = 0; i < NodeIndexList.Count; i++) { IReadOnlyBrowsingChildIndex ChildIndex = NodeIndexList[i]; // If the inner is that of a block list, and the index is for the first node in the block, add block-specific states if (Inner is IReadOnlyBlockListInner <IReadOnlyBrowsingBlockNodeIndex> AsBlockListInner && ChildIndex is IReadOnlyBrowsingNewBlockNodeIndex AsNewBlockIndex) { IReadOnlyBlockState BlockState = AsBlockListInner.InitNewBlock(AsNewBlockIndex); ((IReadOnlyBlockState <IReadOnlyInner <IReadOnlyBrowsingChildIndex> >)BlockState).InitBlockState(); Stats.BlockCount++; IReadOnlyBrowsingPatternIndex PatternIndex = BlockState.PatternIndex; IReadOnlyPatternState PatternState = BlockState.PatternState; AddState(PatternIndex, PatternState); Stats.PlaceholderNodeCount++; IReadOnlyBrowsingSourceIndex SourceIndex = BlockState.SourceIndex; IReadOnlySourceState SourceState = BlockState.SourceState; AddState(SourceIndex, SourceState); Stats.PlaceholderNodeCount++; ChildIndex = AsNewBlockIndex.ToExistingBlockIndex(); } IReadOnlyNodeState ChildState = BuildChildState(Inner, ChildIndex); ChildStateTable.Add(NodeIndexList[i], ChildState); } } return(ChildStateTable); }
/// <summary> /// Creates and initializes a new block state in the inner. /// </summary> /// <param name="newBlockIndex">Index of the new block state to create.</param> /// <returns>The created block state.</returns> public virtual IReadOnlyBlockState InitNewBlock(IReadOnlyBrowsingNewBlockNodeIndex newBlockIndex) { Debug.Assert(newBlockIndex.PropertyName == PropertyName); int BlockIndex = newBlockIndex.BlockIndex; Debug.Assert(BlockIndex == BlockStateList.Count); NodeTreeHelperBlockList.GetChildBlock(Owner.Node, PropertyName, BlockIndex, out IBlock ChildBlock); IReadOnlyBlockState BlockState = CreateBlockState(newBlockIndex, ChildBlock); InsertInBlockStateList(BlockIndex, BlockState); return(BlockState); }
/// <summary> /// Initializes a newly created state for a node in the inner. /// </summary> /// <param name="existingNodeIndex">Index of the node.</param> /// <returns>The created node state.</returns> private protected virtual IReadOnlyPlaceholderNodeState InitChildState(IReadOnlyBrowsingExistingBlockNodeIndex existingNodeIndex) { Debug.Assert(existingNodeIndex.PropertyName == PropertyName); int BlockIndex = existingNodeIndex.BlockIndex; int Index = existingNodeIndex.Index; Debug.Assert(BlockIndex < BlockStateList.Count); IReadOnlyPlaceholderNodeState State = CreateNodeState(existingNodeIndex); IReadOnlyBlockState CurrentBlock = BlockStateList[BlockIndex]; ((IReadOnlyBlockState <IReadOnlyInner <IReadOnlyBrowsingChildIndex> >)CurrentBlock).InitNodeState(State); return(State); }
/// <inheritdoc/> public override void CloneChildren(Node parentNode) { NodeTreeHelperBlockList.ClearChildBlockList(parentNode, PropertyName); // Clone and insert all blocks. This will clone all children recursively. for (int BlockIndex = 0; BlockIndex < BlockStateList.Count; BlockIndex++) { IReadOnlyBlockState BlockState = BlockStateList[BlockIndex]; ((IReadOnlyBlockState <IReadOnlyInner <IReadOnlyBrowsingChildIndex> >)BlockState).CloneBlock(parentNode, BlockIndex); } // Copy comments. IBlockList BlockList = NodeTreeHelperBlockList.GetBlockList(Owner.Node, PropertyName); IBlockList NewBlockList = NodeTreeHelperBlockList.GetBlockList(parentNode, PropertyName); NodeTreeHelper.CopyDocumentation(BlockList, NewBlockList, cloneCommentGuid: true); }
bool IReadOnlyBlockStateReadOnlyList.Contains(IReadOnlyBlockState value) { return(Contains((IFrameBlockState)value)); }
/// <summary> /// Creates a IxxxBlockStateView object. /// </summary> private protected override ReadOnlyBlockStateView CreateBlockStateView(IReadOnlyBlockState blockState) { ControllerTools.AssertNoOverride(this, Type.FromTypeof <WriteableControllerView>()); return(new WriteableBlockStateView(this, (IWriteableBlockState)blockState)); }
/// <summary> /// A block state has been attached. /// </summary> /// <param name="blockState">The attached block state.</param> public override void OnBlockStateAttached(IReadOnlyBlockState blockState) { BlockStateAttachedHandler((IFocusBlockState)blockState); }
/// <summary> /// A block state has been attached. /// </summary> /// <param name="blockState">The attached block state.</param> public override void OnBlockStateAttached(IReadOnlyBlockState blockState) { BlockStateAttachedHandler((IWriteableBlockState)blockState); }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyPatternState{IInner}"/> class. /// </summary> /// <param name="parentBlockState">The parent block state.</param> /// <param name="index">The index used to create the state.</param> public ReadOnlyPatternState(IReadOnlyBlockState parentBlockState, IReadOnlyBrowsingPatternIndex index) : base(index) { ParentBlockState = parentBlockState; }
bool ICollection <IReadOnlyBlockState> .Remove(IReadOnlyBlockState item) { return(Remove((IFocusBlockState)item)); }
bool ICollection <IReadOnlyBlockState> .Contains(IReadOnlyBlockState value) { return(Contains((IFocusBlockState)value)); }
void ICollection <IReadOnlyBlockState> .Add(IReadOnlyBlockState item) { Add((IFocusBlockState)item); }
void IList <IReadOnlyBlockState> .Insert(int index, IReadOnlyBlockState item) { Insert(index, (IFocusBlockState)item); }
int IList <IReadOnlyBlockState> .IndexOf(IReadOnlyBlockState value) { return(IndexOf((IFocusBlockState)value)); }
/// <summary> /// A block state has been attached. /// </summary> /// <param name="blockState">The attached block state.</param> public virtual void OnBlockStateAttached(IReadOnlyBlockState blockState) { BlockStateAttachedHandler(blockState); }
/// <summary> /// Creates a IxxxBlockStateView object. /// </summary> private protected virtual IReadOnlyBlockStateView CreateBlockStateView(IReadOnlyBlockState blockState) { ControllerTools.AssertNoOverride(this, typeof(ReadOnlyControllerView)); return(new ReadOnlyBlockStateView(this, blockState)); }
int IReadOnlyBlockStateReadOnlyList.IndexOf(IReadOnlyBlockState value) { return(IndexOf((IFrameBlockState)value)); }