コード例 #1
0
        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))
                    {
                        // prevent dragging text into readonly section
                        return;
                    }

                    //TODO2 drag/drop - all this:
                    //if (e.Data.GetDataPresent(typeof(Selection)))
                    //{
                    //    Selection sel = (Selection)e.Data.GetData(typeof(Selection));
                    //    if (sel.ContainsPosition(textArea.Caret.Position))
                    //    {
                    //        return;
                    //    }

                    //    if (GetDragDropEffect(e) == DragDropEffects.Move)
                    //    {
                    //        if (SelectionManager.SelectionIsReadOnly(textArea.Document, sel))
                    //        {
                    //            // prevent dragging text out of readonly section
                    //            return;
                    //        }

                    //        int len = sel.Length;
                    //        textArea.Document.Remove(sel.StartOffset, len);

                    //        if (sel.StartOffset < 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
        protected void OnDragDrop(object sender, DragEventArgs e)
        {
            Point p = textArea.PointToClient(new Point(e.X, e.Y));

            if (e.Data.GetDataPresent(typeof(string)))
            {
                bool two = false;
                textArea.BeginUpdate();
                try {
                    int offset = textArea.Caret.Offset;
                    if (textArea.TextEditorProperties.UseCustomLine &&
                        textArea.Document.CustomLineManager.IsReadOnly(textArea.Caret.Line, false))
                    {
                        // prevent dragging text into readonly section
                        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 (textArea.TextEditorProperties.UseCustomLine &&
                                textArea.Document.CustomLineManager.IsReadOnly(sel, false))
                            {
                                // prevent dragging text out of readonly section
                                return;
                            }
                            int len = sel.Length;
                            textArea.Document.Remove(sel.Offset, len);
                            if (sel.Offset < offset)
                            {
                                offset -= len;
                            }
                        }
                        two = true;
                    }
                    textArea.SelectionManager.ClearSelection();
                    InsertString(offset, (string)e.Data.GetData(typeof(string)));
                    if (two)
                    {
                        textArea.Document.UndoStack.CombineLast(2);
                    }
                    textArea.Document.UpdateQueue.Clear();
                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
                } finally {
                    textArea.EndUpdate();
                }
            }
        }
コード例 #3
0
        protected void OnDragOver(object sender, DragEventArgs e)
        {
            if (!textArea.Focused)
            {
                textArea.Focus();
            }

            Point p = textArea.PointToClient(new Point(e.X, e.Y));

            if (textArea.TextView.DrawingPosition.Contains(p.X, p.Y))
            {
                TextLocation realmousepos = textArea.TextView.GetLogicalPosition(p.X - textArea.TextView.DrawingPosition.X,
                                                                                 p.Y - textArea.TextView.DrawingPosition.Y);
                int lineNr = Math.Min(textArea.Document.TotalNumberOfLines - 1, Math.Max(0, realmousepos.Y));

                textArea.Caret.Position = new TextLocation(realmousepos.X, lineNr);
                textArea.SetDesiredColumn();
                if (e.Data.GetDataPresent(typeof(string)) && !textArea.IsReadOnly(textArea.Caret.Offset))
                {
                    e.Effect = GetDragDropEffect(e);
                }
                else
                {
                    e.Effect = DragDropEffects.Link;                     // for Drag & Drop file
                }
            }
            else if (e.Effect != DragDropEffects.Link)
            {
                e.Effect = DragDropEffects.None;
            }
        }
コード例 #4
0
        protected void OnDragOver(object sender, DragEventArgs e)
        {
            if (!textArea.Focused)
            {
                textArea.Focus();
            }

            var p = textArea.PointToClient(new Point(e.X, e.Y));

            if (textArea.TextView.DrawingPosition.Contains(p.X, p.Y))
            {
                var realmousepos = textArea.TextView.GetLogicalPosition(
                    p.X - textArea.TextView.DrawingPosition.X,
                    p.Y - textArea.TextView.DrawingPosition.Y);
                var lineNr = Math.Min(textArea.Document.TotalNumberOfLines - 1, Math.Max(val1: 0, realmousepos.Y));

                textArea.Caret.Position = new TextLocation(realmousepos.X, lineNr);
                textArea.SetDesiredColumn();
                if (IsSupportedData(e.Data) && !textArea.IsReadOnly(textArea.Caret.Offset))
                {
                    e.Effect = GetDragDropEffect(e);
                }
                else
                {
                    e.Effect = DragDropEffects.None;
                }
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
コード例 #5
0
        protected void OnDragDrop(object sender, DragEventArgs e)
        {
            Point p = textArea.PointToClient(new Point(e.X, e.Y));

            if (textArea.EnableCutOrPaste == false)
            {
                return;
            }
            if (e.Data.GetDataPresent(typeof(string)))
            {
                bool two = false;
                textArea.BeginUpdate();
                try {
                    int offset = textArea.Caret.Offset;
                    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)
                        {
                            int len = sel.Length;
                            textArea.Document.Remove(sel.Offset, len);
                            if (sel.Offset < offset)
                            {
                                offset -= len;
                            }
                        }
                        two = true;
                    }
                    textArea.SelectionManager.ClearSelection();
                    InsertString(offset, (string)e.Data.GetData(typeof(string)));
                    if (two)
                    {
                        textArea.Document.UndoStack.UndoLast(2);
                    }
                    textArea.Document.UpdateQueue.Clear();
                    textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
                } finally {
                    textArea.EndUpdate();
                }
            }
        }
コード例 #6
0
        private void templateEditor_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode));

            ICSharpCode.TextEditor.TextArea textArea = (ICSharpCode.TextEditor.TextArea)sender;
            try
            {
                Hashtable idPack = node.Tag as Hashtable;
                switch (idPack["Type"] as string)
                {
                case "promptgroup":
                    return;

                case "prompt":
                    break;
                }

                //Build the variable to insert here
                Prompt prompt = idPack["Data"] as Prompt;

                Point p = textArea.PointToClient(new Point(e.X, e.Y));
                textArea.BeginUpdate();
                textArea.Document.UndoStack.StartUndoGroup();

                int offset = textArea.Caret.Offset;
                if (e.Data.GetDataPresent(typeof(DefaultSelection)))
                {
                    ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection));
                    if (sel.ContainsPosition(textArea.Caret.Position))
                    {
                        return;
                    }
                    int len = sel.Length;
                    textArea.Document.Remove(sel.Offset, len);
                    if (sel.Offset < offset)
                    {
                        offset -= len;
                    }
                }
                insertIntoTemplateEditor(textArea, offset, prompt.VariableName);
            }
            finally
            {
                textArea.Document.UndoStack.EndUndoGroup();
                textArea.EndUpdate();
            }
        }
コード例 #7
0
 void ShowHiddenCursorIfMovedOrLeft()
 {
     textArea.ShowHiddenCursor(!textArea.Focused ||
                               !textArea.ClientRectangle.Contains(textArea.PointToClient(Cursor.Position)));
 }