How to detect end of an external DragAndDrop?


#1

Hi,
I’m using “performExternalDragDropOfFiles” and I’d like to run some code right after the user has dropped the file (ideally when it cas been copied). I thought about using the mouseUp() method to send a callback to run it, however mouseUp is called automatically each time that the mouse pointer enters a container ie. “drop candidate”. Does anybody know bow to tell between these fake mouseUps and the real last one? Or maybe somebody knows of a different way to run something at the end of the external DragAndDrop? I’m testing on win64 but it should work for both win and mac.
Thanks!

void mouseDrag(const MouseEvent& event) override {
dragging = true;
sendChangeMessage();
StringArray files;
if (file.existsAsFile()) {
files.add(file.getFullPathName());
DragAndDropContainer::performExternalDragDropOfFiles(files, false);
}
}

void mouseUp(const MouseEvent& event) override {
dragging = false;
sendChangeMessage();
}


#2

Hey! I think that you can use the FileDragAndDropTarget class, and it will be able to handle this for you.

Check out MDIDemo.cpp in the JUCE Demo for an example. You’ll just need to implement these two functions:

bool isInterestedInFileDrag (const StringArray&) override
{
    return true;
}

void filesDropped (const StringArray& filenames, int /* x */, int /* y */) override
{
    Array<File> files;

    for (int i = 0; i < filenames.size(); ++i)
        files.add (File (filenames[i]));

   // Your code here;

}`

Let me know if this helps.


#4

I see! I tried to recreate your bug using performExternalDragDropOfFiles but I would only get real mouseUp signals (only at the end of a dragging action). Would you mind sending me the buggy project or a sample project that recreates this?

A dirty but temporary fix: maybe try to check for isMouseButtonDownAnywhere() every time that you get a MouseUp? If both are true it means that it’s a fake mouseUp, I can’t think of something else at the moment.