I needed a control for an application I am writing, very similar to one that was a common idiom in the NeXT world – a drag well for files. Drag a file icon to the well and drop it in, and the application receives the full path of the file; drag from the well, and the recipient gets the file path; drop to a Finder window, or the desktop, and you can create an alias, copy or move the original file.
There doesn’t seem to be a control of the nature in MacOS X, so I asked Google for a sample, then I asked Twitter. No luck. However, I did come across an old example from Andrew Stone, dating back quite a few years, probably to MacOS X 10.2 timeframe. I copied that sample, updated it for 10.6, and added some conveniences for my application.
Specific changes that I made were to add a types property, which is an array of strings of file extensions; if set, the file well only accepts files of those types. I also added a notification that is sent when the file is changed, although interested observers could also use KVO (Key Value Observing) on the file property – the notification is just more convenient.
I noticed that when dragging the cursor doesn’t change to indicate the operation type, which I should fix.
Sample project here.