/// <summary> /// Checks if an existing block can have its replication status changed. /// </summary> /// <param name="inner">Inner to use to change the replication status upon return.</param> /// <param name="blockIndex">Index of the block that can be changed upon return.</param> /// <param name="replication">The current replication status upon return.</param> /// <returns>True if an existing block can have its replication status changed at the focus.</returns> public virtual bool IsReplicationModifiable(out IFocusBlockListInner inner, out int blockIndex, out ReplicationStatus replication) { inner = null; blockIndex = -1; replication = ReplicationStatus.Normal; bool IsModifiable = false; IFocusNodeState State = Focus.CellView.StateView.State; // Search recursively for a collection parent, up to 3 levels up. for (int i = 0; i < 3 && State != null; i++) { if (State is IFocusPatternState AsPatternState) { IFocusBlockState ParentBlock = AsPatternState.ParentBlockState; IFocusBlockListInner BlockListInner = ParentBlock.ParentInner as IFocusBlockListInner; Debug.Assert(BlockListInner != null); inner = BlockListInner; blockIndex = inner.BlockStateList.IndexOf(ParentBlock); replication = ParentBlock.ChildBlock.Replication; IsModifiable = true; break; } else if (State is IFocusSourceState AsSourceState) { IFocusBlockState ParentBlock = AsSourceState.ParentBlockState; IFocusBlockListInner BlockListInner = ParentBlock.ParentInner as IFocusBlockListInner; Debug.Assert(BlockListInner != null); inner = BlockListInner; blockIndex = inner.BlockStateList.IndexOf(ParentBlock); replication = ParentBlock.ChildBlock.Replication; IsModifiable = true; break; } else if (State.ParentInner is IFocusBlockListInner AsBlockListInner) { inner = AsBlockListInner; IFocusBrowsingExistingBlockNodeIndex ParentIndex = State.ParentIndex as IFocusBrowsingExistingBlockNodeIndex; Debug.Assert(ParentIndex != null); blockIndex = ParentIndex.BlockIndex; replication = inner.BlockStateList[blockIndex].ChildBlock.Replication; IsModifiable = true; break; } State = State.ParentState; } return(IsModifiable); }
/// <summary> /// Checks if an existing block at the focus can be moved up or down. /// </summary> /// <param name="direction">Direction of the move, relative to the current position of the item.</param> /// <param name="inner">Inner to use to move the block upon return.</param> /// <param name="blockIndex">Index of the block to move upon return.</param> /// <returns>True if an item can be moved at the focus.</returns> public virtual bool IsBlockMoveable(int direction, out IFocusBlockListInner inner, out int blockIndex) { inner = null; blockIndex = -1; bool IsBlockMoveable = false; IFocusNodeState State = Focus.CellView.StateView.State; if (Focus.CellView.Frame is IFocusInsertFrame AsInsertFrame) { IsBlockMoveable = false; } else { IsBlockMoveable = false; // Search recursively for a collection parent, up to 3 levels up. for (int i = 0; i < 3 && State != null; i++) { if (State.ParentInner is IFocusBlockListInner AsBlockListInner) { inner = AsBlockListInner; IFocusBrowsingExistingBlockNodeIndex ParentIndex = State.ParentIndex as IFocusBrowsingExistingBlockNodeIndex; Debug.Assert(ParentIndex != null); blockIndex = ParentIndex.BlockIndex; if (Controller.IsBlockMoveable(inner, blockIndex, direction)) { IsBlockMoveable = true; } break; } State = State.ParentState; } } return(IsBlockMoveable); }