Drop onto a FileBrowserComponent

Hi Jules,

I've got a BrowserFileComponent  component on my interface and I would like a drop files into the FileTreeComponent but this looks very difficult to do.

 

When I drop items into it, I can see that TreeView::handleDrop is called:

void TreeView::handleDrop (const StringArray& files, const SourceDetails& dragSourceDetails)
{
    hideDragHighlight();

    InsertPoint insertPos (*this, files, dragSourceDetails);

    if (insertPos.item == nullptr)
        insertPos.item = rootItem;

    if (insertPos.item != nullptr)
    {
        if (files.size() > 0)
        {
            if (insertPos.item->isInterestedInFileDrag (files))
                insertPos.item->filesDropped (files, insertPos.insertIndex);
        }
        else
        {
            if (insertPos.item->isInterestedInDragSource (dragSourceDetails))
                insertPos.item->itemDropped (dragSourceDetails, insertPos.insertIndex);
        }
    }
}

but isInterestedInDragSource§isInterestedInFileDrag always return false.

 

If I want to change this return, no other change that overriding, is it?

I though that I could easily override FileBrowerComponent  and its child classes.

I first tried to overridde FileBrowerComponent but I don't manage to override the constructor as the FileBrowerComponent class inherites from FileFilter which is private...

So unless rewrite all thoses classes (FileBrowser, FileTreeComponent, FileTreeView, FileTreeItem,...), I can't see how to do that.

 

So my question is simply: Is there an easy way to drop items into the FileTreeComponent ?

 

Thanks

Yes, there's not really any way to do it with those existing classes - I didn't really design them to be extensible like that, they were just for displaying the file tree, not editing it. You'd probably need to write your own special file tree if you want it to support that kind of operation.

Well I finished by overriding mouseUp on my main component. I found the destination folder by calling getItemIdentifierString() on a fileTreeItem like this:

 
void     PresetManager::mouseUp(const MouseEvent& event)
{

   FileTreeComponent* pFileTreeComponent = static_cast<FileTreeComponent*>(mPresetBrowserComp->getDisplayComponent());

    if(pFileTreeComponent == nullptr || pFileTreeComponent->contains(event.getEventRelativeTo(pFileTreeComponent).getPosition()) == false)
    {
        WRITE_TO_CONSOLE("incorrect destination");
        return;
    }

    TreeViewItem* pFileTreeItem = pFileTreeComponent->getItemAt(event.getEventRelativeTo(pFileTreeComponent).y);

    if(pFileTreeItem == nullptr)
    {
        WRITE_TO_CONSOLE("pFileTreeItem null");
        return;
    }

    String destinationFileName = pFileTreeItem->getItemIdentifierString().fromFirstOccurrenceOf("//", false, true).upToFirstOccurrenceOf("/", false, true);

    File destinationFile = File(destinationFileName);

    if(destinationFile.exists() == false)
    {
        WRITE_TO_CONSOLE("itemFile does not exist");
        return;
    }

    ...

}

 

By the way, I noticed two little issues on the FileBrowserComponent.

1) When dragging multiple files from the FileBrowserComponent,  only the shadow of the first item is displayed

2) it generates several leaks. I assume some child component are not properly deteled.