/// <summary> /// Replaces the selection with the content of the clipboard. /// </summary> /// <param name="isChanged">True if something was replaced or added.</param> public override void Paste(out bool isChanged) { isChanged = false; IFocusNodeState State = StateView.State; IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner; Debug.Assert(ParentInner != null); Debug.Assert(BlockIndex >= 0 && BlockIndex < ParentInner.BlockStateList.Count); IFocusBlockState BlockState = ParentInner.BlockStateList[BlockIndex]; Debug.Assert(StartIndex < BlockState.StateList.Count); Debug.Assert(EndIndex <= BlockState.StateList.Count); Debug.Assert(StartIndex <= EndIndex); IList <INode> NodeList = null; if (ClipboardHelper.TryReadNodeList(out NodeList)) { } else if (ClipboardHelper.TryReadNode(out INode Node)) { NodeList = new List <INode>() { Node }; } if (NodeList != null) { if (NodeList.Count == 0 || ParentInner.InterfaceType.IsAssignableFrom(NodeList[0].GetType())) { List <IWriteableInsertionCollectionNodeIndex> IndexList = new List <IWriteableInsertionCollectionNodeIndex>(); IFocusController Controller = StateView.ControllerView.Controller; int OldNodeCount = ParentInner.Count; int SelectionCount = EndIndex - StartIndex; int InsertionNodeIndex = EndIndex; for (int i = 0; i < NodeList.Count; i++) { INode NewNode = NodeList[i] as INode; IFocusInsertionExistingBlockNodeIndex InsertedIndex = CreateExistingBlockNodeIndex(ParentInner.Owner.Node, PropertyName, NewNode, BlockIndex, StartIndex + i); IndexList.Add(InsertedIndex); } Controller.ReplaceNodeRange(ParentInner, BlockIndex, StartIndex, EndIndex, IndexList); Debug.Assert(ParentInner.Count == OldNodeCount + NodeList.Count - SelectionCount); StateView.ControllerView.ClearSelection(); isChanged = NodeList.Count > 0 || SelectionCount > 0; } } }
/// <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> /// Copy the selection in the clipboard. /// </summary> /// <param name="dataObject">The clipboard data object that can already contain other custom formats.</param> public override void Copy(IDataObject dataObject) { IFocusNodeState State = StateView.State; IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner; Debug.Assert(ParentInner != null); Debug.Assert(BlockIndex >= 0 && BlockIndex < ParentInner.BlockStateList.Count); IFocusBlockState BlockState = (IFocusBlockState)ParentInner.BlockStateList[BlockIndex]; List <Node> NodeList = new List <Node>(); for (int i = StartIndex; i < EndIndex; i++) { NodeList.Add(BlockState.StateList[i].Node); } ClipboardHelper.WriteNodeList(dataObject, NodeList); }
/// <summary> /// Adds the selection to the clipboard. /// </summary> /// <param name="dataObject">The clipboard data object that can already contain other custom formats.</param> public override void Copy(IDataObject dataObject) { IFocusNodeState State = StateView.State; IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner; Debug.Assert(ParentInner != null); Debug.Assert(StartIndex <= EndIndex); List <IBlock> BlockList = new List <IBlock>(); for (int i = StartIndex; i < EndIndex; i++) { IFocusBlockState BlockState = (IFocusBlockState)ParentInner.BlockStateList[i]; BlockList.Add(BlockState.ChildBlock); } ClipboardHelper.WriteBlockList(dataObject, BlockList); }
private protected virtual void ExtendSelectionBlockList(IFocusBlockListSelection selection) { string PropertyName = selection.PropertyName; IFocusNodeState State = selection.StateView.State; IFocusBlockListInner BlockListInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner; Debug.Assert(BlockListInner != null); Debug.Assert(selection.StartIndex <= selection.EndIndex); int SelectedCount = selection.EndIndex - selection.StartIndex + 1; if (SelectedCount < BlockListInner.BlockStateList.Count) { selection.Update(0, BlockListInner.BlockStateList.Count - 1); } else { SelectNode(selection.StateView.State); } }
/// <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); }
/// <summary> /// Gets the frame that creates cells associated to states in the inner. /// This overload uses selectors to choose the correct frame. /// </summary> /// <param name="inner">The inner.</param> /// <param name="selectorStack">A list of selectors to choose the correct frame.</param> public virtual IFocusFrame InnerToFrame(IFocusInner <IFocusBrowsingChildIndex> inner, IList <IFocusFrameSelectorList> selectorStack) { IFocusNodeState Owner = inner.Owner; Type OwnerType = Owner.Node.GetType(); Type InterfaceType = NodeTreeHelper.NodeTypeToInterfaceType(OwnerType); IFocusNodeTemplate Template = (IFocusNodeTemplate)NodeTypeToTemplate(InterfaceType); IFocusFrame Frame = Template.PropertyToFrame(inner.PropertyName, selectorStack); if (Frame is IFocusBlockListFrame AsBlockListFrame) { IFocusBlockListInner <IFocusBrowsingBlockNodeIndex> BlockListInner = inner as IFocusBlockListInner <IFocusBrowsingBlockNodeIndex>; Debug.Assert(BlockListInner != null); Type BlockType = NodeTreeHelperBlockList.BlockListBlockType(Owner.Node, BlockListInner.PropertyName); IFocusBlockTemplate BlockTemplate = (IFocusBlockTemplate)BlockTypeToTemplate(BlockType); Frame = (IFocusFrame)BlockTemplate.GetPlaceholderFrame(); } return(Frame); }
private void CutOrDelete(IDataObject dataObject, out bool isDeleted) { isDeleted = false; IFocusNodeState State = StateView.State; IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner; Debug.Assert(ParentInner != null); Debug.Assert(BlockIndex >= 0 && BlockIndex < ParentInner.BlockStateList.Count); IFocusBlockState BlockState = (IFocusBlockState)ParentInner.BlockStateList[BlockIndex]; int OldNodeCount = ParentInner.Count; int SelectionCount = EndIndex - StartIndex; if (SelectionCount < BlockState.StateList.Count || ParentInner.BlockStateList.Count > 1 || !NodeHelper.IsCollectionNeverEmpty(State.Node, PropertyName)) { if (dataObject != null) { List <Node> NodeList = new List <Node>(); for (int i = StartIndex; i < EndIndex; i++) { NodeList.Add(BlockState.StateList[i].Node); } ClipboardHelper.WriteNodeList(dataObject, NodeList); } FocusController Controller = StateView.ControllerView.Controller; Controller.RemoveNodeRange(ParentInner, BlockIndex, StartIndex, EndIndex); Debug.Assert(ParentInner.Count == OldNodeCount - SelectionCount); StateView.ControllerView.ClearSelection(); isDeleted = true; } }
private void CutOrDelete(IDataObject dataObject, out bool isDeleted) { isDeleted = false; IFocusNodeState State = StateView.State; IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner; Debug.Assert(ParentInner != null); Debug.Assert(StartIndex <= EndIndex); int OldBlockCount = ParentInner.BlockStateList.Count; int SelectionCount = EndIndex - StartIndex; if (SelectionCount < ParentInner.BlockStateList.Count || !NodeHelper.IsCollectionNeverEmpty(State.Node, PropertyName)) { if (dataObject != null) { List <IBlock> BlockList = new List <IBlock>(); for (int i = StartIndex; i < EndIndex; i++) { IFocusBlockState BlockState = ParentInner.BlockStateList[i]; BlockList.Add(BlockState.ChildBlock); } ClipboardHelper.WriteBlockList(dataObject, BlockList); } IFocusController Controller = StateView.ControllerView.Controller; Controller.RemoveBlockRange(ParentInner, StartIndex, EndIndex); Debug.Assert(ParentInner.BlockStateList.Count == OldBlockCount - SelectionCount); StateView.ControllerView.ClearSelection(); isDeleted = true; } }
/// <summary> /// Initializes a new instance of the <see cref="FocusBlockState{IInner}"/> class. /// </summary> /// <param name="parentInner">Inner containing the block state.</param> /// <param name="newBlockIndex">Index that was used to create the block state.</param> /// <param name="childBlock">The block.</param> public FocusBlockState(IFocusBlockListInner parentInner, IFocusBrowsingNewBlockNodeIndex newBlockIndex, IBlock childBlock) : base(parentInner, newBlockIndex, childBlock) { }
/// <summary> /// Replaces the selection with the content of the clipboard. /// </summary> /// <param name="isChanged">True if something was replaced or added.</param> public override void Paste(out bool isChanged) { isChanged = false; IFocusNodeState State = StateView.State; IFocusBlockListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusBlockListInner; Debug.Assert(ParentInner != null); Debug.Assert(StartIndex <= EndIndex); int OldBlockCount = ParentInner.BlockStateList.Count; int SelectionCount = EndIndex - StartIndex; if (ClipboardHelper.TryReadBlockList(out IList <IBlock> BlockList)) { bool IsAssignable = true; if (BlockList.Count > 0) { NodeTreeHelperBlockList.GetBlockItemType(BlockList[0], out Type ChildItemType); // IsAssignable = ParentInner.InterfaceType.IsAssignableFrom(ChildInterfaceType); IsAssignable = ParentInner.InterfaceType.IsAssignableFrom(ChildItemType); } if (IsAssignable) { List <IWriteableInsertionBlockNodeIndex> IndexList = new List <IWriteableInsertionBlockNodeIndex>(); FocusController Controller = StateView.ControllerView.Controller; int InsertionBlockIndex = StartIndex; for (int i = 0; i < BlockList.Count; i++) { IBlock NewBlock = BlockList[i]; for (int j = 0; j < NewBlock.NodeList.Count; j++) { Node NewNode = NewBlock.NodeList[j] as Node; IFocusInsertionBlockNodeIndex InsertedIndex; if (j == 0) { InsertedIndex = CreateNewBlockNodeIndex(ParentInner.Owner.Node, PropertyName, NewNode, InsertionBlockIndex, NewBlock.ReplicationPattern, NewBlock.SourceIdentifier); } else { InsertedIndex = CreateExistingBlockNodeIndex(ParentInner.Owner.Node, PropertyName, NewNode, InsertionBlockIndex, j); } Debug.Assert(InsertedIndex != null); IndexList.Add(InsertedIndex); } InsertionBlockIndex++; } Controller.ReplaceBlockRange(ParentInner, StartIndex, EndIndex, IndexList); Debug.Assert(ParentInner.BlockStateList.Count == OldBlockCount + BlockList.Count - SelectionCount); StateView.ControllerView.ClearSelection(); isChanged = BlockList.Count > 0 || SelectionCount > 0; } } }