DragAndDropContainer::performExternalDragDropOfFiles usage

Hello. I'm having a bit of trouble implementing an external drag and drop. I've called the function in MouseDrag(), but it's not working as expected. The little hand symbol comes up, and the following call produces true for the first pixel of drag movement, then false for the rest. Am I going about it all wrong, or is it an issue with me using Linux (I don't have a Windows machine to test on at the minute)? My Component inherits DragAndDropContainer.

 

Cheers

 


void Draggy::mouseDrag (const MouseEvent &event)
{
    
    StringArray sArray;
    sArray.add("~/Desktop/HMA.txt");
    
    bool res = DragAndDropContainer::performExternalDragDropOfFiles(sArray, false);
    
    if (res == true)
    {
        DBG("TRURUR");
    }
    else
    {
        DBG("FALSE");
    }
    
    
}

You should only call it once, not for every mouse-move. (I think this is explained in the comments for that method)

Sorry Jules, couldn't see it anywhere in the comments or docs.

I really don't understand the drag and drop at all...

I've changed it from mouseDrag to mouseDown so it only calls once. 
shouldDropFilesWhenDraggedExternally() is being called when I drag out of the JUCE window, but nothing is actually dragged - no icon change etc. I've tried passing the file I want to drag and drop in multiple different places, but non seem to work.

void Draggy::mouseDown (const MouseEvent &event)
{
    StringArray sArray;
    sArray.add("~/Desktop/HMA.txt");
    
    startDragging ("THE FILE", this);
    
    DBG("Stared Dragging");
    
    bool res = DragAndDropContainer::performExternalDragDropOfFiles(sArray, true);
    
}


bool Draggy::shouldDropFilesWhenDraggedExternally    
    (    
        const DragAndDropTarget::SourceDetails &     sourceDetails,
        StringArray &files,
        bool &canMoveFiles 
    )
{        
    
    if (files.size() == 0)
    {
        DBG("No files passed");
    }
    else
    {
        for (int i=0; i<files.size(); i++)
        {
            DBG(files[i]);
        }
    }
    files.add("~/Desktop/HMA.txt");
    DBG("Passed Outside");
        
    
    return true;        
                
}

Ah, well maybe it's a linux thing - I've not really tested it in earnest on there. TBH I never call it directly, I generally use the flag in DragAndDropContainer::startDragging that automatically does a drag to external windows. Have you tried the drag + drop page of the juce demo in your OS? 

Cheers Jules. Yeah I've tried the drag and drop in the demo, it doesn't do an external drop, and I've tried every possibility in my own code. It's probably a linux thing - I'm using Lubuntu, with loads of random packages. Something is probably conflicting. I'll try the same thing on Windows as soon as I get my Windows machine back up and running.

 

Cheers

Yeah, this could be something that isn't yet implemented on linux, I can't remember offhand.. Will try to take a look when I get a moment.

Hi,
nearly 10 years later… I am able to drag drop from app → desktop on my mac, but not on linux. Is this implemented on linux? If not are there any plans to do so?

Best,

equinox

Ah sorry, I was using wayland and not X11. Now after becoming aware of it and changing my ubuntu to X11 things are working again…
Problem is also mentioned here: Drag'n drop on wayland (but the other way around, so from e.g. nautilus → juce-app)
Also a good time for me to give a vote for Wayland support :smile:

I’m having a hell of a time getting external drag and drop to work on a Mac. I’m just wondering - the code you posted above - is this what you got working? I’ve tried every variation I can come up with and no matter what, the performExternalDragDropOfFiles function immediately returns false as soon as it’s called. Thank you in advance if you have any pointers!

Welp… I feel like I didn’t change anything with my code and now it’s working. I’ll take the win haha.