protected void OnDragDrop(object sender, DragEventArgs e)
        {
            Point p = textArea.PointToClient(new Point(e.X, e.Y));

            if (e.Data.GetDataPresent(typeof(string)))
            {
                textArea.BeginUpdate();
                textArea.Document.UndoStack.StartUndoGroup();
                try {
                    int offset = textArea.Caret.Offset;
                    if (textArea.IsReadOnly(offset))
                    {
                        return;
                    }
                    if (e.Data.GetDataPresent(typeof(DefaultSelection)))
                    {
                        ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection));
                        if (sel.ContainsPosition(textArea.Caret.Position))
                        {
                            return;
                        }
                        if (GetDragDropEffect(e) == DragDropEffects.Move)
                        {
                            if (SelectionManager.SelectionIsReadOnly(textArea.Document, sel))
                            {
                                return;
                            }
                            int len = sel.Length;
                            textArea.Document.Remove(sel.Offset, len);
                            if (sel.Offset < offset)
                            {
                                offset -= len;
                            }
                        }
                    }
                    textArea.SelectionManager.ClearSelection();
                    InsertString(offset, (string)e.Data.GetData(typeof(string)));
                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
                } finally {
                    textArea.Document.UndoStack.EndUndoGroup();
                    textArea.EndUpdate();
                }
            }
        }
Пример #2
0
 public void Paste(object sender, EventArgs e)
 {
     if (!textArea.EnableCutOrPaste)
     {
         return;
     }
     for (int i = 0;; i++)
     {
         try {
             IDataObject data = Clipboard.GetDataObject();
             if (data == null)
             {
                 return;
             }
             bool fullLine = data.GetDataPresent(LineSelectedType);
             if (data.GetDataPresent(DataFormats.UnicodeText))
             {
                 string text = (string)data.GetData(DataFormats.UnicodeText);
                 if (text.Length > 0)
                 {
                     textArea.Document.UndoStack.StartUndoGroup();
                     try {
                         if (textArea.SelectionManager.HasSomethingSelected)
                         {
                             textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition;
                             textArea.SelectionManager.RemoveSelectedText();
                         }
                         if (fullLine)
                         {
                             int col = textArea.Caret.Column;
                             textArea.Caret.Column = 0;
                             if (!textArea.IsReadOnly(textArea.Caret.Offset))
                             {
                                 textArea.InsertString(text);
                             }
                             textArea.Caret.Column = col;
                         }
                         else
                         {
                             textArea.InsertString(text);
                         }
                     } finally {
                         textArea.Document.UndoStack.EndUndoGroup();
                     }
                 }
             }
             return;
         } catch (ExternalException) {
             if (i > 5)
             {
                 throw;
             }
         }
     }
 }