AcceptFileDrop anywhere

Early on in my apps development I made it so files could be dropped into the Window area and this worked fine. As I’ve added containers, controls, etc. only very specific areas in my Window now accept the files being dropped, but I still want it to be handled anywhere, regardless of what control my mouse is over when I drop the file.

Is there something I need to do in order to make the window event handler trigger regardless?

1 Like

Each control has a drop capability so that could be interfering with your Window drop. In the Window open you called AcceptFileDrop( types ). So long as none of your controls call AcceptFileDrop or AcceptPictureDrop and don’t implement DropObject event on the controls. The events should propagate up to the window.

My main window is effectively completely covered by a Canvas (a custom grid) which leaves no space on the window. My windows DropObject event is called when a file is dropped, because the canvas doesn’t call AcceptFileDrop and doesn’t implement the DropObject event.

It is also worth implementing the App.DocumentOpened event and configuring FileTypesets to define your application with a role of Edit or View for the required types so that you can drop files on the Application icon in Finder or Explorer.

That what I expected. The Window is the only thing w/ an AcceptFileDrop or a DropObject event. None of my controls (explicitly) handle DropObject.

I started noticing this after I started creating DesktopContainer objects and organizing my controls within those (e.g. a sidebar container). Do containers do something implicitly maybe?

I’ve just tried to reproduce this and can’t get it to go wrong. Are all of your objects API 2? For example DesktopWindows with DesktopContainers etc. I’m just guessing that if a Container is mixed with a DesktopWindow perhaps something goes wrong?

As far as I can tell, yes (relatively new Xojo user). And all the controls within them are API 2. I have no doubt that the err is mine, I just don’t know how I can track down the issue.

The only other thing I can think of is the DesktopImageView I added covering most of the app area at startup when no data is loaded.

And… yep. If I set DesktopImageView.Visible = False then everything works as expected. But I also do not explicitly accept and drops (or handle the DropObject event) on that control. Is this a bug or a “feature” of DesktopImageView maybe?

If it behaves different than other controls and you can’t find documentation for the ‘feature’, then is a bug. Can you create an Issue (bug report) and upload a sample project that shows this?

That would be it. Could you use a Canvas control instead. That way you can still show a picture (using the backdrop property or simple drawpicture in its paint event). and FileDrops will cascade. Worth a bug report / feature request anyway.

1 Like

Yep. Did just that and it’s all back to working again.