/// <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> /// 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); }