Posted 15 years ago by painetraine
Avatar
I am trying to implement drag/drop of files into the editor but when I handle the DragEnter and check for

(drgevent.Data.GetDataPresent(DataFormats.FileDrop)), it finds it to be true and I set Effect = DragDropEffects.Copy but the copy cursor never shows and I am never able to drop a file or anything else onto the editor control.

Is there any way to do this?

Here is my DragEnter code:

protected override void OnDragEnter(DragEventArgs drgevent)
{
if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
{
drgevent.Effect = DragDropEffects.Copy;
}
else
base.OnDragEnter (drgevent);
}


I inheirt the SyntaxEditor into my own control and I have tried handling it in the inherited control as well as the event on the form and it still never shows a copy cursor even though the effect is set to Copy.

Any ideas???

Thanks

Comments (9)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes we have full support for drag/drop however since there is a ton of complicated code needed to do so, we had to make a custom way of doing so. Our internal drag/drop code handles all the view focus setting, caret moving, and other background code needed to make it work.

In the sample app, take a look at MainForm.editor_CustomDataObjectText because that shows an example of how to handle file drag/drop. Also in the docs, read the "Custom DataObject Support" topic. That explains how it all works.


Actipro Software Support

Posted 15 years ago by byperman - Sint-Niklaas, Belgium
Avatar
private void editor_CustomDataObjectText(object sender, ActiproSoftware.SyntaxEditor.CustomDataObjectTextEventArgs e)
        {
            if (e.DataObject.GetDataPresent(DataFormats.Text))
            {
                Token t = editor.Document.Tokens.GetTokenAtOffset(editor.Document.CurrentView.Selection.StartOffset);
                if (t.Key == "StartTagAttributeValueDefaultToken")
                    t.Text = e.DataObject.GetData(DataFormats.Text);
            }
        }
Is anything like this (which doesn't work because the tokens are readonly) possible?
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You could do that if you're attempting to replace an attribute name with the drag/drop value. However instead of setting Token.Text, do a Document.UndoableInsert by replacing the offset range of the Token. You'd also have to set the e.Text to null.

But by doing this you are only allowing a copy and not a move.

[ 10-22-2004: Message edited by: Actipro Software Support ]


Actipro Software Support

Posted 15 years ago by byperman - Sint-Niklaas, Belgium
Avatar
I now use
        private void editor_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                Token t = editor.Document.Tokens.GetTokenAtOffset(editor.Document.CurrentView.Selection.StartOffset);
                if (t.Key == "StartTagAttributeStringValueDefaultToken")
                {
                    editor.Document.UndoableInsert(DocumentModificationType.Replace, t.StartOffset, t.Length, e.Data.GetData(DataFormats.Text).ToString());
                }
            } 
        }
One can really see it happening (first insertion of the data (by your code), then replacing (by my code)), but that doesn't really matter.

Thanks a lot!
Posted 15 years ago by byperman - Sint-Niklaas, Belgium
Avatar
Is it correct that the dragdrop-event isn't fired anymore as of version 2.5?

Allowdrop is true, but the events don't seem to be fired anymore.
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Just looked and that does appear to be correct. I can add them back in for you however as I said, the potential for really messing things up when you have custom code exists.

Consider when you drag/drop between two views. When you drop from one view to another if you drop before the offset of the dragged text, we have a lot of internal code that registers this sort of thing and ends up sliding over offset range to drag out. This has to happen because the insertion of the drop text happens before the cut out of the drag text. Make sense?

When you write custom Drag event handlers, you end up potentially missing all our code or having our internal code not work as intended. That's why we had to come up with the custom IDataObject support event.

However in your situation it seems like you want to work with regular text, for which the custom IDataObject event will not fire, right?

I would really prefer it if we can think of a better way, perhaps even another event or something that lets you do what you want to do since working with the .NET drag/drop events directly could definitely provide bad results in certain scenarios. I'm open to all suggestions.


Actipro Software Support

Posted 15 years ago by byperman - Sint-Niklaas, Belgium
Avatar
Quote:
<font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Actipro Software Support:
However in your situation it seems like you want to work with regular text, for which the custom IDataObject event will not fire, right?<HR>

That's correct.

I'll try to alter my code and work with the customIdataobject first, if it doesn't work out right, i'll get in touch.

Thanks,
Brecht
Posted 15 years ago by byperman - Sint-Niklaas, Belgium
Avatar
The editor_CustomDataObjectText is of no use to me, because it seems to me it's called upon all drag-dropevents.

What i did, with the previous version, is an undo and then an undoableinsert, using the current location of the caret to find the correct token to replace.
I do need an event that tells me when the actual drop happens.

Brecht
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'm going to reply to the email you sent on this matter.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.