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); FocusController 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> /// Creates and initializes a new instance of a <see cref="FocusControllerView"/> object. /// </summary> /// <param name="controller">The controller on which the view is attached.</param> /// <param name="templateSet">The template set used to describe the view.</param> public static FocusControllerView Create(FocusController controller, IFocusTemplateSet templateSet) { FocusControllerView View = new FocusControllerView(controller, templateSet); View.Init(); return(View); }
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> /// Creates and initializes a new instance of a <see cref="FocusController"/> object. /// </summary> /// <param name="nodeIndex">Index of the root of the node tree.</param> public static FocusController Create(IFocusRootNodeIndex nodeIndex) { FocusController Controller = new FocusController(); Controller.SetRoot(nodeIndex); Controller.SetCycleManagerList(); Controller.SetInitialized(); return(Controller); }
/// <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 = (IFocusBlockState)ParentInner.BlockStateList[BlockIndex]; Debug.Assert(StartIndex < BlockState.StateList.Count); Debug.Assert(EndIndex <= BlockState.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; 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> /// 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) { FocusController Controller = StateView.ControllerView.Controller; Controller.ChangeDiscreteValue(StateView.State.ParentIndex, PropertyName, NewValue); isChanged = true; } } }
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) { FocusController Controller = StateView.ControllerView.Controller; Node ParentNode = State.ParentInner.Owner.Node; Controller.Remove(AsCollectionInner, AsCollectionNodeIndex); isDeleted = true; } }
/// <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); FocusController 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; } }
/// <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 Node Node)) { IFocusNodeState State = StateView.State; if ((State.ParentInner != null && State.ParentInner.InterfaceType.IsAssignableFrom(Type.FromGetType(Node))) || (State.ParentInner == null && Type.FromGetType(Node) == Type.FromGetType(State.Node))) { if (State.ParentIndex is IFocusBrowsingInsertableIndex AsInsertableIndex) { FocusController Controller = StateView.ControllerView.Controller; Node ParentNode = State.ParentInner.Owner.Node; IFocusInsertionChildIndex ReplaceIndex = (IFocusInsertionChildIndex)AsInsertableIndex.ToInsertionIndex(ParentNode, Node); Controller.Replace(State.ParentInner, ReplaceIndex, out IWriteableBrowsingChildIndex NewIndex); isChanged = true; } } } }
/// <summary></summary> protected virtual void PasteNode(Node node, out bool isChanged) { isChanged = false; FocusControllerView ControllerView = StateView.ControllerView; if (ControllerView.Focus is IFocusTextFocus AsTextFocus) { IFocusNodeState State = AsTextFocus.CellView.StateView.State; if (Type.FromGetType(State.Node).IsAssignableFrom(Type.FromGetType(node))) { if (State.ParentIndex is IFocusBrowsingInsertableIndex AsInsertableIndex) { FocusController Controller = StateView.ControllerView.Controller; Node 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.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; } } }
/// <summary> /// Initializes a new instance of the <see cref="FocusControllerView"/> class. /// </summary> /// <param name="controller">The controller on which the view is attached.</param> /// <param name="templateSet">The template set used to describe the view.</param> private protected FocusControllerView(FocusController controller, IFocusTemplateSet templateSet) : base(controller, templateSet) { }