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;
            IFocusListInner ParentInner = State.PropertyToInner(PropertyName) as IFocusListInner;

            Debug.Assert(ParentInner != null);

            Debug.Assert(StartIndex < ParentInner.StateList.Count);
            Debug.Assert(EndIndex <= ParentInner.StateList.Count);
            Debug.Assert(StartIndex <= EndIndex);

            IList <Node> NodeList = null;

            if (ClipboardHelper.TryReadNodeList(out NodeList))
            {
            }
            else if (ClipboardHelper.TryReadNode(out Node Node))
            {
                NodeList = new List <Node>()
                {
                    Node
                };
            }

            if (NodeList != null)
            {
                if (NodeList.Count == 0 || ParentInner.InterfaceType.IsAssignableFrom(Type.FromGetType(NodeList[0])))
                {
                    List <IWriteableInsertionCollectionNodeIndex> IndexList = new List <IWriteableInsertionCollectionNodeIndex>();
                    FocusController Controller         = StateView.ControllerView.Controller;
                    int             OldNodeCount       = ParentInner.Count;
                    int             SelectionCount     = EndIndex - StartIndex;
                    int             InsertionNodeIndex = EndIndex;

                    for (int i = 0; i < NodeList.Count; i++)
                    {
                        Node NewNode = NodeList[i] as Node;
                        IFocusInsertionListNodeIndex InsertedIndex = CreateListNodeIndex(ParentInner.Owner.Node, PropertyName, NewNode, StartIndex + i);
                        IndexList.Add(InsertedIndex);
                    }

                    Controller.ReplaceNodeRange(ParentInner, -1, 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);
        }
        private protected virtual void ExtendSelectionNodeList(IFocusNodeListSelection selection)
        {
            string          PropertyName = selection.PropertyName;
            IFocusNodeState State        = selection.StateView.State;
            IFocusListInner ListInner    = State.PropertyToInner(PropertyName) as IFocusListInner;

            Debug.Assert(ListInner != null);
            Debug.Assert(selection.StartIndex <= selection.EndIndex);

            int SelectedCount = selection.EndIndex - selection.StartIndex + 1;

            if (SelectedCount < ListInner.StateList.Count)
            {
                selection.Update(0, ListInner.StateList.Count - 1);
            }
            else
            {
                SelectNode(selection.StateView.State);
            }
        }
Example #5
0
        /// <summary>
        /// Checks if an existing identifier at the focus can be split in two.
        /// </summary>
        /// <param name="inner">Inner to use to split the identifier upon return.</param>
        /// <param name="replaceIndex">Index of the identifier to replace upon return.</param>
        /// <param name="insertIndex">Index of the identifier to insert upon return.</param>
        /// <returns>True if an identifier can be split at the focus.</returns>
        public virtual bool IsIdentifierSplittable(out IFocusListInner inner, out IFocusInsertionListNodeIndex replaceIndex, out IFocusInsertionListNodeIndex insertIndex)
        {
            inner        = null;
            replaceIndex = null;
            insertIndex  = null;

            bool IsSplittable = false;

            IFocusNodeState IdentifierState = Focus.CellView.StateView.State;

            if (IdentifierState.Node is Identifier AsIdentifier)
            {
                IFocusNodeState ParentState = IdentifierState.ParentState;
                if (ParentState.Node is QualifiedName)
                {
                    string Text = AsIdentifier.Text;
                    Debug.Assert(CaretPosition >= 0 && CaretPosition <= Text.Length);

                    inner = IdentifierState.ParentInner as IFocusListInner;
                    Debug.Assert(inner != null);

                    IFocusBrowsingListNodeIndex CurrentIndex = IdentifierState.ParentIndex as IFocusBrowsingListNodeIndex;
                    Debug.Assert(CurrentIndex != null);

                    Identifier FirstPart  = NodeHelper.CreateSimpleIdentifier(Text.Substring(0, CaretPosition));
                    Identifier SecondPart = NodeHelper.CreateSimpleIdentifier(Text.Substring(CaretPosition));

                    replaceIndex = CurrentIndex.ToInsertionIndex(ParentState.Node, FirstPart) as IFocusInsertionListNodeIndex;
                    Debug.Assert(replaceIndex != null);

                    insertIndex = CurrentIndex.ToInsertionIndex(ParentState.Node, SecondPart) as IFocusInsertionListNodeIndex;
                    Debug.Assert(insertIndex != null);

                    insertIndex.MoveUp();

                    IsSplittable = true;
                }
            }

            return(IsSplittable);
        }