Add DragAndDrop Handler
This step implements drag and drop of files and folders onto a FileMaker window.
Add DragAndDrop Handler [ Select ; Result (error) ; FileName ; ScriptName ; FieldBounds ; Cursor type ; Allow Mail Drops ; Scroll the drop zone ]
|Select entire contents||replaces the contents of a field with the result. If not checked the result replaces the currently selected portion of the field|
|Result (error)||an error code|
|FileName||the name of the file that contains the script to be triggered|
|ScriptName||the name of the script to be triggered when files/folders are dropped on a window|
|FieldBounds||(optional) a rectangle on the layout where the drag is accepted. Dimensions (in pixels) are in this order: "left top right bottom", which is the same order as the FileMaker FieldBounds function returns|
|Cursor type||can be "Link Cursor" (default): while dragging show an arrow cursor with a small link symbol or "Copy Cursor": while dragging show arrow cursor with a small plus symbol|
|Allow Mail Drops||this will allow emails (from the macOS Mail.app) to be dragged to FileMaker Pro|
|Scroll the drop zone||when you use a drop zone for the drag destination and check this option, the position of the dropzone will scroll too when scrolling the FileMaker window|
Data type returned
The returned result is an error code. An error always starts with 2 dollars, followed by the error code. You should always check for errors. Returned error codes can be:
|$$-50||paramErr||there was an error with a parameter|
|$$-5600||errInvalidWindowRef||the window could not be found|
|$$-4223||errTooManyEvents||you have specified more than 3 D&D handlers|
Other errors may be returned.
Troi File Plug-in 9.0
FileMaker Pro 16 to 19
You can specify up to three separate drag destinations, by calling the step three times, each time specifying the rectangles you want as drop zones.
The FileMaker window that is in front when the Add DragAndDrop Handler step is run, will be activated as the destination of future drags.
When the plug-in detects a drag on the destination window, the specified script will be triggered. The (incoming) ScriptParameter of the triggered script will contain the list of files/folders that were dragged on the window.
You can drag one or more files and folders (or a mix of this) on the window. The trigger script should be expecting this and be capable to handle this, for example in a loop. Alternatively the script can only use the first file in the list.
See the switch "-PackageFolderAttr" in the function TrFile_GetFileAttribute: this can be used to determine if a result of the drag and drop action is a package.
– The plug-in is not aware of a change in the position of the custom fieldbounds, for example when scrolled. Check the Scroll the drop zone option to have the position of the drop zone automatically adjusted when scrolling the FileMaker window
– (macOS) the drop box highlight is only visible over a white background.
– (macOS) the link and copy cursor are visible only when moving the cursor.
To make drag and drop work you need a trigger script that handles the drag. You also need to start and stop the plug-in handling the drags. Here we create a (simplified) script that will put the path of the first file found in a field. See the example files for a more extensive script, handling more files and container fields.
– Create a script named “DragTriggerscript”:
Set Variable [ $pathList ; Value : Get ( ScriptParameter ) ] If [ Get ( FoundCount ) = 0 ] New Record/Request End If Set Variable [ $returnPos ; Position ( $pathList ; "¶" ; 1 ; 1 ) ] Set Field [ this::onepath ; If ( $returnPos > 0 ; Left ( $pathList ; $returnPos - 1 ) ; $pathList ) ] # here you can add actions you want to perform on this file
– Starting drag and drop can be done like this:
Add DragAndDrop Handler [ Select ; gErrorCode ; Get ( FileName ) ; "DragTriggerscript" ) ]
After this step has been executed the user can drag files on the window and the DragTriggerScript will be run.
– Stopping drag and drop can be done with this script step:
Stop DragAndDrop Handlers
Set Variable [ $containerFieldBounds ; FieldBounds ( Get ( FileName ) ; Get ( LayoutName ) ; Get ( ActiveFieldName ) ) ] Add DragAndDrop Handler[ Select ; gErrorCode ; Get ( FileName ) ; "DragTriggerscript" ; $containerFieldBounds ) ]
This will make the drag area around a container field.
Related script step
|Stop DragAndDrop Handlers|