Exemplo n.º 1
0
        private void CutOrDelete(IDataObject dataObject, out bool isDeleted)
        {
            isDeleted = false;

            string Content = NodeTreeHelper.GetString(StateView.State.Node, PropertyName);

            Debug.Assert(Content != null);
            Debug.Assert(Start <= End);
            Debug.Assert(End <= Content.Length);

            if (Start < End)
            {
                if (dataObject != null)
                {
                    dataObject.SetData(typeof(string), Content.Substring(Start, End - Start));
                }

                Content = Content.Substring(0, Start) + Content.Substring(End);

                IFocusController Controller = StateView.ControllerView.Controller;
                int OldCaretPosition        = StateView.ControllerView.CaretPosition;
                int NewCaretPosition        = Start;
                Controller.ChangeTextAndCaretPosition(StateView.State.ParentIndex, PropertyName, Content, OldCaretPosition, NewCaretPosition, true);

                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;
                }
            }
        }
Exemplo n.º 3
0
        private void CutOrDelete(IDataObject dataObject, out bool isDeleted)
        {
            isDeleted = false;

            IFocusNodeState State = StateView.State;

            if (State.ParentInner is IFocusCollectionInner AsCollectionInner && State.ParentIndex is IFocusBrowsingCollectionNodeIndex AsCollectionNodeIndex)
            {
                IFocusController Controller = StateView.ControllerView.Controller;
                INode            ParentNode = State.ParentInner.Owner.Node;

                Controller.Remove(AsCollectionInner, AsCollectionNodeIndex);

                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;

            if (ClipboardHelper.TryReadInt(out int NewValue) && NewValue >= 0)
            {
                int OldValue = NodeTreeHelper.GetEnumValueAndRange(StateView.State.Node, PropertyName, out int Min, out int Max);
                if (OldValue != NewValue && NewValue >= Min && NewValue <= Max)
                {
                    IFocusController Controller = StateView.ControllerView.Controller;
                    Controller.ChangeDiscreteValue(StateView.State.ParentIndex, PropertyName, NewValue);

                    isChanged = true;
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Replaces the selection with the content of the clipboard.
        /// </summary>
        public override void Paste(out bool isChanged)
        {
            isChanged = false;

            if (ClipboardHelper.TryReadText(out string Text) && Text.Length > 0)
            {
                string Content = NodeTreeHelper.GetString(StateView.State.Node, PropertyName);
                Debug.Assert(Content != null);
                Debug.Assert(Start <= End);
                Debug.Assert(End <= Content.Length);

                Content = Content.Substring(0, Start) + Text + Content.Substring(End);

                IFocusController Controller = StateView.ControllerView.Controller;
                int OldCaretPosition        = StateView.ControllerView.CaretPosition;
                int NewCaretPosition        = Start + Text.Length;
                Controller.ChangeTextAndCaretPosition(StateView.State.ParentIndex, PropertyName, Content, OldCaretPosition, NewCaretPosition, false);

                StateView.ControllerView.ClearSelection();
                isChanged = true;
            }
        }
Exemplo n.º 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;

            if (ClipboardHelper.TryReadNode(out INode Node))
            {
                IFocusNodeState State = StateView.State;
                if ((State.ParentInner != null && State.ParentInner.InterfaceType.IsAssignableFrom(Node.GetType())) || (State.ParentInner == null && Node.GetType() == State.Node.GetType()))
                {
                    if (State.ParentIndex is IFocusBrowsingInsertableIndex AsInsertableIndex)
                    {
                        IFocusController Controller = StateView.ControllerView.Controller;
                        INode            ParentNode = State.ParentInner.Owner.Node;

                        IFocusInsertionChildIndex ReplaceIndex = (IFocusInsertionChildIndex)AsInsertableIndex.ToInsertionIndex(ParentNode, Node);
                        Controller.Replace(State.ParentInner, ReplaceIndex, out IWriteableBrowsingChildIndex NewIndex);

                        isChanged = 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;
            }
        }
Exemplo n.º 8
0
        /// <summary></summary>
        protected virtual void PasteNode(INode node, out bool isChanged)
        {
            isChanged = false;

            IFocusControllerView ControllerView = StateView.ControllerView;

            if (ControllerView.Focus is IFocusTextFocus AsTextFocus)
            {
                IFocusNodeState State = AsTextFocus.CellView.StateView.State;
                if (State.Node.GetType().IsAssignableFrom(node.GetType()))
                {
                    if (State.ParentIndex is IFocusBrowsingInsertableIndex AsInsertableIndex)
                    {
                        IFocusController Controller = StateView.ControllerView.Controller;
                        INode            ParentNode = State.ParentInner.Owner.Node;

                        IFocusInsertionChildIndex ReplaceIndex = (IFocusInsertionChildIndex)AsInsertableIndex.ToInsertionIndex(ParentNode, node);
                        Controller.Replace(State.ParentInner, ReplaceIndex, out IWriteableBrowsingChildIndex NewIndex);

                        isChanged = 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(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.GetBlockType(BlockList[0], out Type ChildInterfaceType, out Type ChildItemType);
                    IsAssignable = ParentInner.InterfaceType.IsAssignableFrom(ChildInterfaceType);
                }

                if (IsAssignable)
                {
                    List <IWriteableInsertionBlockNodeIndex> IndexList = new List <IWriteableInsertionBlockNodeIndex>();
                    IFocusController 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++)
                        {
                            INode NewNode = NewBlock.NodeList[j] as INode;
                            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;
                }
            }
        }