예제 #1
0
        /// <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;
                }
            }
        }