Example #1
0
            // Token: 0x060085B9 RID: 34233 RVA: 0x0024A67C File Offset: 0x0024887C
            private void SourceDoDragDrop(ITextSelection selection, IDataObject dataObject)
            {
                DragDropEffects dragDropEffects = DragDropEffects.Copy;

                if (!this._textEditor.IsReadOnly)
                {
                    dragDropEffects |= DragDropEffects.Move;
                }
                DragDropEffects dragDropEffects2 = DragDropEffects.None;

                try
                {
                    dragDropEffects2 = DragDrop.DoDragDrop(this._textEditor.UiScope, dataObject, dragDropEffects);
                }
                catch (COMException ex) when(ex.HResult == -2147418113)
                {
                }
                if (!this._textEditor.IsReadOnly && dragDropEffects2 == DragDropEffects.Move && this._dragSourceTextRange != null && !this._dragSourceTextRange.IsEmpty)
                {
                    using (selection.DeclareChangeBlock())
                    {
                        this._dragSourceTextRange.Text = string.Empty;
                    }
                }
                this._dragSourceTextRange = null;
                if (!this._textEditor.IsReadOnly)
                {
                    BindingExpressionBase bindingExpressionBase = BindingOperations.GetBindingExpressionBase(this._textEditor.UiScope, TextBox.TextProperty);
                    if (bindingExpressionBase != null)
                    {
                        bindingExpressionBase.UpdateSource();
                        bindingExpressionBase.UpdateTarget();
                    }
                }
            }
Example #2
0
            // Token: 0x060085BF RID: 34239 RVA: 0x0024AB9C File Offset: 0x00248D9C
            internal void TargetOnDrop(DragEventArgs e)
            {
                if (!this.AllowDragDrop(e))
                {
                    return;
                }
                ITextSelection selection = this._textEditor.Selection;

                Invariant.Assert(selection != null);
                if (e.Data == null || e.AllowedEffects == DragDropEffects.None)
                {
                    e.Effects = DragDropEffects.None;
                    return;
                }
                if ((e.KeyStates & DragDropKeyStates.ControlKey) != DragDropKeyStates.None)
                {
                    e.Effects = DragDropEffects.Copy;
                }
                else if (e.Effects != DragDropEffects.Copy)
                {
                    e.Effects = DragDropEffects.Move;
                }
                if (!this._textEditor.TextView.Validate(e.GetPosition(this._textEditor.TextView.RenderScope)))
                {
                    e.Effects = DragDropEffects.None;
                    return;
                }
                ITextPointer dropPosition = this.GetDropPosition(this._textEditor.TextView.RenderScope, e.GetPosition(this._textEditor.TextView.RenderScope));

                if (dropPosition != null)
                {
                    if (this._dragSourceTextRange != null && this._dragSourceTextRange.Start.TextContainer == selection.Start.TextContainer && !selection.IsEmpty && this.IsSelectionContainsDropPosition(selection, dropPosition))
                    {
                        selection.SetCaretToPosition(dropPosition, LogicalDirection.Backward, false, true);
                        e.Effects = DragDropEffects.None;
                        e.Handled = true;
                    }
                    else
                    {
                        using (selection.DeclareChangeBlock())
                        {
                            if ((e.Effects & DragDropEffects.Move) != DragDropEffects.None && this._dragSourceTextRange != null && this._dragSourceTextRange.Start.TextContainer == selection.Start.TextContainer)
                            {
                                this._dragSourceTextRange.Text = string.Empty;
                            }
                            selection.SetCaretToPosition(dropPosition, LogicalDirection.Backward, false, true);
                            e.Handled = TextEditorCopyPaste._DoPaste(this._textEditor, e.Data, true);
                        }
                    }
                    if (e.Handled)
                    {
                        this.Win32SetForegroundWindow();
                        this._textEditor.UiScope.Focus();
                        return;
                    }
                    e.Effects = DragDropEffects.None;
                }
            }
            /// <summary>
            /// DragEnd event handler from DragDrop behavior.
            /// </summary>
            private void SourceDoDragDrop(ITextSelection selection, IDataObject dataObject)
            {
                // Run OLE drag-drop process. It will eat all user input until the drop
                DragDropEffects allowedDragDropEffects = DragDropEffects.Copy;

                if (!_textEditor.IsReadOnly)
                {
                    allowedDragDropEffects |= DragDropEffects.Move;
                }

                DragDropEffects resultingDragDropEffects = DragDrop.DoDragDrop( //
                    _textEditor.UiScope,                                        // dragSource,
                    dataObject,                                                 //
                    allowedDragDropEffects);

                // Remove source selection
                if (!_textEditor.IsReadOnly &&                          //
                    resultingDragDropEffects == DragDropEffects.Move && //
                    _dragSourceTextRange != null &&
                    !_dragSourceTextRange.IsEmpty)
                {
                    // Normally we delete the source selection from OnDrop event,
                    // unless source and target TextBoxes are different.
                    // In this case the source selection is still not empty,
                    // which means that target was in a different TextBox.
                    // So we still need to delete the selected content in the source one.
                    // This will create an undo unit different from a dropping one,
                    // which is ok, because it will be in different TextBox's undo stack.
                    using (selection.DeclareChangeBlock())
                    {
                        // This is end of Move - we need to delete source content
                        _dragSourceTextRange.Text = String.Empty;
                    }
                }

                // Clean up the text range.
                _dragSourceTextRange = null;

                // Check the data binding expression and update the source and target if the drag source
                // has the binding expression. Without this, data binding is broken after complete the
                // drag-drop operation because Drop() paste the object then set the focus to the target.
                // The losting focus invoke the data binding expression's Update(), but the source isn't
                // updated yet before complete DoDragDrop.
                if (!_textEditor.IsReadOnly)
                {
                    BindingExpressionBase bindingExpression = BindingOperations.GetBindingExpressionBase(
                        _textEditor.UiScope, TextBox.TextProperty);
                    if (bindingExpression != null)
                    {
                        bindingExpression.UpdateSource();
                        bindingExpression.UpdateTarget();
                    }
                }
            }
            /// <summary>
            /// Called from an event reporting that the drop happened.
            /// </summary>
            internal void TargetOnDrop(DragEventArgs e)
            {
                //

                if (!AllowDragDrop(e))
                {
                    return;
                }

                ITextSelection selection = _textEditor.Selection;

                Invariant.Assert(selection != null);

                if (e.Data == null || e.AllowedEffects == DragDropEffects.None)
                {
                    e.Effects = DragDropEffects.None;
                    return;
                }

                if ((int)(e.KeyStates & DragDropKeyStates.ControlKey) != 0)
                {
                    e.Effects = DragDropEffects.Copy;
                }
                else if (e.Effects != DragDropEffects.Copy)
                {
                    e.Effects = DragDropEffects.Move;
                }

                // Force a layout update on the content so the GetTextPositionFromPoint
                // call following can succeed.
                if (!_textEditor.TextView.Validate(e.GetPosition(_textEditor.TextView.RenderScope)))
                {
                    e.Effects = DragDropEffects.None;
                    return;
                }

                // Get the text position from the text target point.
                ITextPointer dropPosition = GetDropPosition(_textEditor.TextView.RenderScope as Visual, e.GetPosition(_textEditor.TextView.RenderScope));

                if (dropPosition != null)
                {
                    if (_dragSourceTextRange != null && _dragSourceTextRange.Start.TextContainer == selection.Start.TextContainer &&
                        !selection.IsEmpty && IsSelectionContainsDropPosition(selection, dropPosition))
                    {
                        // When we drop inside of selected area, we
                        // should not select dropped content,
                        // otherwise it looks for end user as if
                        // nothing happened.

                        // Set caret to this position.
                        selection.SetCaretToPosition(dropPosition, LogicalDirection.Backward, /*allowStopAtLineEnd:*/ false, /*allowStopNearSpace:*/ true);

                        // Indicate the resulting effect of an action
                        // Note that dropResult may stay equal to DragDropResult.Drop
                        e.Effects = DragDropEffects.None;

                        // Mark the event as handled
                        e.Handled = true;
                    }
                    else
                    {
                        using (selection.DeclareChangeBlock())
                        {
                            // For MaxLength filter work correctly in case
                            // when we dragdrop within the same TextContainer,
                            // we need to delete dragged content first -
                            // before dropping when filtering will occur.
                            // Note, that this will duplicate operation on
                            // source side, but it will be void deletion action
                            if ((e.Effects & DragDropEffects.Move) != 0 && //
                                _dragSourceTextRange != null && _dragSourceTextRange.Start.TextContainer == selection.Start.TextContainer)
                            {
                                _dragSourceTextRange.Text = String.Empty;
                            }

                            // When we drop outside of selection,
                            // we should ignore current selection and
                            // move ip into dropping point.
                            selection.SetCaretToPosition(dropPosition, LogicalDirection.Backward, /*allowStopAtLineEnd:*/ false, /*allowStopNearSpace:*/ true);

                            // _DoPaste raises a public event -- could raise recoverable exception.
                            e.Handled = TextEditorCopyPaste._DoPaste(_textEditor, e.Data, /*isDragDrop:*/ true);
                            //
                        }
                    }

                    if (e.Handled)
                    {
                        // Set the drop target as the foreground window.
                        Win32SetForegroundWindow();

                        // Set the focus into the drop target.
                        _textEditor.UiScope.Focus();
                    }
                    else
                    {
                        // When a target did not handle a drop event, we must
                        // prevent from deleting a content on source end -
                        // otherwise we'll have data loss
                        e.Effects = DragDropEffects.None;
                    }
                }
            }
            /// <summary>
            /// DragEnd event handler from DragDrop behavior.
            /// </summary>
            private void SourceDoDragDrop(ITextSelection selection, IDataObject dataObject)
            {
                // Run OLE drag-drop process. It will eat all user input until the drop
                DragDropEffects allowedDragDropEffects = DragDropEffects.Copy;

                if (!_textEditor.IsReadOnly)
                {
                    allowedDragDropEffects |= DragDropEffects.Move;
                }

                DragDropEffects resultingDragDropEffects = DragDropEffects.None;

                try
                {
                    resultingDragDropEffects = DragDrop.DoDragDrop( //
                        _textEditor.UiScope,                        // dragSource,
                        dataObject,                                 //
                        allowedDragDropEffects);
                }
                // DDVSO 685894:
                // Ole32's DoDragDrop can return E_UNEXCEPTED, which comes to us as a COMException,
                // if something unexpected happened during the drag and drop operation,
                // e.g. the application receiving the drop failed. In this case we should
                // not fail, we should catch the exception and act as if the drop wasn't allowed.
                catch (COMException ex) when(ex.HResult == NativeMethods.E_UNEXPECTED)
                {
                }

                // Remove source selection
                if (!_textEditor.IsReadOnly &&                          //
                    resultingDragDropEffects == DragDropEffects.Move && //
                    _dragSourceTextRange != null &&
                    !_dragSourceTextRange.IsEmpty)
                {
                    // Normally we delete the source selection from OnDrop event,
                    // unless source and target TextBoxes are different.
                    // In this case the source selection is still not empty,
                    // which means that target was in a different TextBox.
                    // So we still need to delete the selected content in the source one.
                    // This will create an undo unit different from a dropping one,
                    // which is ok, because it will be in different TextBox's undo stack.
                    using (selection.DeclareChangeBlock())
                    {
                        // This is end of Move - we need to delete source content
                        _dragSourceTextRange.Text = String.Empty;
                    }
                }

                // Clean up the text range.
                _dragSourceTextRange = null;

                // Check the data binding expression and update the source and target if the drag source
                // has the binding expression. Without this, data binding is broken after complete the
                // drag-drop operation because Drop() paste the object then set the focus to the target.
                // The losting focus invoke the data binding expression's Update(), but the source isn't
                // updated yet before complete DoDragDrop.
                if (!_textEditor.IsReadOnly)
                {
                    BindingExpressionBase bindingExpression = BindingOperations.GetBindingExpressionBase(
                        _textEditor.UiScope, TextBox.TextProperty);
                    if (bindingExpression != null)
                    {
                        bindingExpression.UpdateSource();
                        bindingExpression.UpdateTarget();
                    }
                }
            }
Example #6
0
            /// <summary>
            /// DragEnd event handler from DragDrop behavior.
            /// </summary>
            private void SourceDoDragDrop(ITextSelection selection, IDataObject dataObject)
            {
                // Run OLE drag-drop process. It will eat all user input until the drop
                DragDropEffects allowedDragDropEffects = DragDropEffects.Copy;
                if (!_textEditor.IsReadOnly)
                {
                    allowedDragDropEffects |= DragDropEffects.Move;
                }

                DragDropEffects resultingDragDropEffects = DragDrop.DoDragDrop( //
                    _textEditor.UiScope, // dragSource, 
                    dataObject, //
                    allowedDragDropEffects);

                // Remove source selection 
                if (!_textEditor.IsReadOnly && //
                    resultingDragDropEffects == DragDropEffects.Move && //
                    _dragSourceTextRange != null &&
                    !_dragSourceTextRange.IsEmpty)
                {
                    // Normally we delete the source selection from OnDrop event,
                    // unless source and target TextBoxes are different.
                    // In this case the source selection is still not empty,
                    // which means that target was in a different TextBox.
                    // So we still need to delete the selected content in the source one.
                    // This will create an undo unit different from a dropping one,
                    // which is ok, because it will be in different TextBox's undo stack.
                    using (selection.DeclareChangeBlock())
                    {
                        // This is end of Move - we need to delete source content
                        _dragSourceTextRange.Text = String.Empty;
                    }
                }

                // Clean up the text range.
                _dragSourceTextRange = null;

                // Check the data binding expression and update the source and target if the drag source
                // has the binding expression. Without this, data binding is broken after complete the 
                // drag-drop operation because Drop() paste the object then set the focus to the target.
                // The losting focus invoke the data binding expression's Update(), but the source isn't
                // updated yet before complete DoDragDrop.
                if (!_textEditor.IsReadOnly)
                {
                    BindingExpressionBase bindingExpression = BindingOperations.GetBindingExpressionBase(
                        _textEditor.UiScope, TextBox.TextProperty);
                    if (bindingExpression != null)
                    {
                        bindingExpression.UpdateSource();
                        bindingExpression.UpdateTarget();
                    }
                }
            }