DragAndDropContainer::performExternalDragDropOfFiles usage


#1

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");
    }
    
    
}

#2

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


#3

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;        
                
}

#4

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? 


#5

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


#6

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.