We re-use the CommandBinding and InputBinding instances between multiple text areas, so this class is static.
Ejemplo n.º 1
0
        /// <summary>
        /// Creates a data object containing the selection's text.
        /// </summary>
        public virtual DataObject CreateDataObject(TextArea textArea)
        {
            DataObject data = new DataObject();

            // Ensure we use the appropriate newline sequence for the OS
            string text = TextUtilities.NormalizeNewLines(GetText(), Environment.NewLine);

            // Enable drag/drop to Word, Notepad++ and others
            if (EditingCommandHandler.ConfirmDataFormat(textArea, data, DataFormats.UnicodeText))
            {
                data.SetText(text);
            }

            // Enable drag/drop to SciTe:
            // We cannot use SetText, thus we need to use typeof(string).FullName as data format.
            // new DataObject(object) calls SetData(object), which in turn calls SetData(Type, data),
            // which then uses Type.FullName as format.
            // We immitate that behavior here as well:
            if (EditingCommandHandler.ConfirmDataFormat(textArea, data, typeof(string).FullName))
            {
                data.SetData(typeof(string).FullName, text);
            }

            // Also copy text in HTML format to clipboard - good for pasting text into Word
            // or to the SharpDevelop forums.
            if (EditingCommandHandler.ConfirmDataFormat(textArea, data, DataFormats.Html))
            {
                HtmlClipboard.SetHtml(data, CreateHtmlFragment(new HtmlOptions(textArea.Options)));
            }
            return(data);
        }
Ejemplo n.º 2
0
        private void textArea_Drop(object sender, DragEventArgs e)
        {
            try
            {
                DragDropEffects effect = GetEffect(e);
                e.Effects = effect;
                if (effect != DragDropEffects.None)
                {
                    int start = textArea.Caret.Offset;
                    if (mode == SelectionMode.Drag && textArea.Selection.Contains(start))
                    {
                        Debug.WriteLine("Drop: did not drop: drop target is inside selection");
                        e.Effects = DragDropEffects.None;
                    }
                    else
                    {
                        Debug.WriteLine("Drop: insert at " + start);

                        var pastingEventArgs = new DataObjectPastingEventArgs(e.Data, true, DataFormats.UnicodeText);
                        textArea.RaiseEvent(pastingEventArgs);
                        if (pastingEventArgs.CommandCancelled)
                        {
                            return;
                        }

                        string text = EditingCommandHandler.GetTextToPaste(pastingEventArgs, textArea);
                        if (text == null)
                        {
                            return;
                        }
                        bool rectangular = pastingEventArgs.DataObject.GetDataPresent(RectangleSelection.RectangularSelectionDataType);

                        // Mark the undo group with the currentDragDescriptor, if the drag
                        // is originating from the same control. This allows combining
                        // the undo groups when text is moved.
                        textArea.Document.UndoStack.StartUndoGroup(this.currentDragDescriptor);
                        try
                        {
                            if (rectangular && RectangleSelection.PerformRectangularPaste(textArea, textArea.Caret.Position, text, true))
                            {
                            }
                            else
                            {
                                textArea.Document.Insert(start, text);
                                textArea.Selection = Selection.Create(textArea, start, start + text.Length);
                            }
                        }
                        finally
                        {
                            textArea.Document.UndoStack.EndUndoGroup();
                        }
                    }
                    e.Handled = true;
                }
            }
            catch (Exception ex)
            {
                OnDragException(ex);
            }
        }
        /// <summary>
        /// Creates a new TextAreaDefaultInputHandler instance.
        /// </summary>
        public TextAreaDefaultInputHandler(TextArea textArea) : base(textArea)
        {
            this.NestedInputHandlers.Add(CaretNavigation = CaretNavigationCommandHandler.Create(textArea));
            this.NestedInputHandlers.Add(Editing         = EditingCommandHandler.Create(textArea));
            this.NestedInputHandlers.Add(MouseSelection  = new SelectionMouseHandler(textArea));

            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, ExecuteUndo, CanExecuteUndo));
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, ExecuteRedo, CanExecuteRedo));
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public override System.Windows.DataObject CreateDataObject(TextArea textArea)
        {
            var data = base.CreateDataObject(textArea);

            if (EditingCommandHandler.ConfirmDataFormat(textArea, data, RectangularSelectionDataType))
            {
                MemoryStream isRectangle = new MemoryStream(1);
                isRectangle.WriteByte(1);
                data.SetData(RectangularSelectionDataType, isRectangle, false);
            }
            return(data);
        }