private void CutOrDelete(IDataObject dataObject, out bool isDeleted)
        {
            isDeleted = false;

            IFocusNodeState State       = StateView.State;
            IFocusListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusListInner;

            Debug.Assert(ParentInner != null);

            int OldNodeCount   = ParentInner.Count;
            int SelectionCount = EndIndex - StartIndex;

            if (SelectionCount < ParentInner.StateList.Count || !NodeHelper.IsCollectionNeverEmpty(State.Node, PropertyName))
            {
                if (dataObject != null)
                {
                    List <Node> NodeList = new List <Node>();
                    for (int i = StartIndex; i < EndIndex; i++)
                    {
                        NodeList.Add(ParentInner.StateList[i].Node);
                    }

                    ClipboardHelper.WriteNodeList(dataObject, NodeList);
                }

                FocusController Controller = StateView.ControllerView.Controller;
                Controller.RemoveNodeRange(ParentInner, -1, StartIndex, EndIndex);

                Debug.Assert(ParentInner.Count == OldNodeCount - SelectionCount);

                StateView.ControllerView.ClearSelection();
                isDeleted = true;
            }
        }
        /// <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>
        /// 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;
            IFocusListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusListInner;

            Debug.Assert(ParentInner != null);

            List <Node> NodeList = new List <Node>();

            for (int i = StartIndex; i < EndIndex; i++)
            {
                NodeList.Add(ParentInner.StateList[i].Node);
            }

            ClipboardHelper.WriteNodeList(dataObject, NodeList);
        }
Beispiel #4
0
        /// <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);
            }
        }
Beispiel #6
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;
                }
            }
        }