Drag & Drop - To the Finder
From REALbasicWiki
[edit] Background
This article applies only to Mac OS X (i.e. not for Windows and Linux)
Suppose your app wants to support dragging of files (or folders) to the Finder.
This is well documented in REALbasic's help: You simply create a new DragItem object, assign the FolderItem object of the file in question to it, and call its Drag method.
But what if the file you want to drag does not yet exist? This lets the user drag some object to the Finder and thus tell your app: "I want this object saved here, where I dropped it into this folder or onto the desktop".
In this case, read on:
[edit] Dragging "promised" files
If you need to be able to drag and drop stuff from your application to your OS file system (e.g. the Finder) in order to create a file and eventually to save data to it however the RB documentation is not clear on the subject. It says:
«Mac OS X supports the concept of dragging a file before it actually exists in the file system. It could be a new document that hasn’t been saved yet or a file that exists on a remote server or on the web. In these cases, the drag and drop gesture serves the purpose of specifying the location at which to save the new file. When the drag and drop operation is complete, it tells the source where it wants the files saved and the dragging source creates the files. This special type of file drag is called a promise because the drag operation contains a promise from the source to the destination that the source will create the specified files if the drag and drop is accepted.»
As an example let's say we have a listbox containing names and we want to be able to drag and drop one or several rows to the file system and get file(s) created with those names. To achieve that, place the following code in your listbox DragRow event:
dim di as dragItem
dim f as folderItem
// Create Drag Item
di = me.newDragItem(me.left, me.top, me.width, me.height)
// Create a file promise
di.MacData("phfs") = ""
// Drag
di.drag
// Get the result
if di.destination isa FolderItem then
// Cast destination (of type object) to a folderitem
f = FolderItem(di.Destination)
msgbox f.absolutePath // <- Replace this line with your file creation/handling code using f
end if
