App icon: drag and drop

I think this is a general question however I’m specifically interested in a Mac OS implementation.

I use drag and drop extensively with controls in a running application but I cannot figure out how to implement drag and drop functionality onto an application icon.

Specifically, I would like too be able to drop a folder onto an un-launched application icon and have the app open and and process the files therein.

With a control (or window) I simply create a filetypes group and implement acceptFileDrop and put code in the control’s DropObject event handler. Evidently it’s different with app drag and drop?

Can anyone provide direction?


In your file type group, drag a folder from the Finder right onto the editor and it will automatically set up a type for you.

1 Like

I don’t need to tell the app that it accepts drop items, as I would in a window or control?

Yes, read:

You have to add an App.Open Event and load the dropped file(s) from there.

Yes., I did read those.
Still, when I drop a folder on the icon nothing happens.

Will it not work with a director, processing all of the enclosed items?

You have to write code.

In the App.OpenDocument Event, you will get a reference for the dropped item(s).

Sub OpenDocument(item As FolderItem)
End Sub

Item will be the reference to go: if it is a Folder, open it and process its contents.
If you dropped one or more file(s), you have to deal with them.

COde to do that can be found and adapted from the DragItem entry in the LR.

Not the way you do regular drag and drop. In the file type, you will need to choose a “role” for your app. For a folder, that’s probably “view” or “alternate”.

Then in App.openDocument, you deal with the incoming folderitem.

Thanks @Greg_O_Lone.
This works when the application is running. What I would like, however, is for the app to launch and being processing the dropped item.

You mean you have code that deals with items drop in your Application’s Icon, butit oes not works when the application is not running ?

If so, let’s share it.

I was unaware of this feature. It will certainly help!

ok, so I just tried this in a simple app.

  1. Create a new desktop project
  2. Add a FileTypeGroup
  3. Drag a folder from the Finder and drop it on the FileTypeGroup
  4. In the macOS section at the bottom, change Role to View and Rank to Default.
  5. Right-Click on App and select Add to App > Event Handler.
  6. Select OpenDocument and click OK
  7. In the OpenDocument event, type the word “break”
  8. From the IDE menu, select Project > Run Paused

The IDE will build the app and put it on disk with the debugger waiting to connect. Drag and Drop a folder onto the App icon and it should break into the debugger on the OpenDocument event with the folderitem pointing at the folder.

1 Like