Skip to main content

TrFile_DragAndDrop (function reference)

Troi File Plug-in > Functions reference > TrFile_DragAndDrop
Troi File Plug-in for FileMaker Pro

TrFile_DragAndDrop

This function implements drag and drop of files and folders onto a FileMaker window.

SyntaxFunction badge

TrFile_DragAndDrop ( switches ; fileName ; scriptName ; { fieldBounds } )

Parameters

switches determine the behavior of the function
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

Switches

switches can be one of this:

-AddDragAndDropHandler the plug-in starts accepting drag and drop. You can now drag files on the window
-StopDragAndDrop the plug-in no longer accepts drag and drop

You can also add one of these switches

-LinkCursor (default) while dragging show an arrow cursor with a small link symbol
-CopyCursor while dragging show arrow cursor with a small plus symbol

These 2 switches only change how the cursor looks. In the triggered script you need to implement any action you want to perform on the dragged items.

You can also add:

-AllowMailDrops this will allow emails (from the macOS Mail.app) to be dragged to FileMaker
-ScrollDropZone when you use a drop zone for the drag destination and add this switch, the position of the dropzone will scroll too when scrolling the FileMaker window
-BringToFront brings the FileMaker application to the front before triggering the trigger script.
-AllowFilePromiseDrops this will allow file promises (files or images that don’t exist yet) to be dragged to FileMaker

Returned Result

Data type returned

Error code

Result

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:

0 no error
$$-50 paramErr there was an error with a parameter
$$-5600 errInvalidWindowRef the window could not be found
$$-4223 errTooManyEvents you have specified more than 6 D&D handlers

Other errors may be returned.

Originated in

Troi File Plug-in 4.6

Compatibility

FileMaker Pro 16 to FileMaker Pro 2023

Considerations

You can now specify six separate drag destinations, by calling the function six times with the switch -AddDragAndDropHandler with the 6 rectangles you want as drop zones.

The FileMaker window that is in front when the “-AddDragAndDropHandler” switch is executed, 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.

KNOWN ISSUES
– The plug-in is not aware if the position of the custom fieldbounds is changed, for example when scrolled. Use the -ScrollDropZone switch to have the position of the dropzone 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 is visible only when moving the cursor.

v13.1 changed the maximum number of drop zones from 3 to 6.
Starting with v13.1 you can selectively stop handlers in the same file and/or with the same script name. You can specify it like this:
TrFile_DragAndDrop( “-StopDragAndDrop” ; fileName ; { scriptName } ).

v15.0 added the switch “-AllowFilePromiseDrops”. When you add this switch you can drop file promises or images for example from a web application (like Safari or Photos) to the drop zone. You can also drag custom types from a web application, like a zip file.

Example

To make drag and drop work you need a trigger script that handles the drag. Also you need to start and stop the plug-in handling the drags. We here create a (simplified) script that will put the path of 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:

Set Variable [ $ErrorCode ; TrFile_DragAndDrop ( "-AddDragAndDropHandler" ; 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 like this:

Set Variable [ $ErrorCode ; TrFile_DragAndDrop ( "-StopDragAndDrop" ; "" ; "" ) ]

Example 2

Set Variable [ $containerFieldBounds ; FieldBounds ( Get ( FileName ) ; Get ( LayoutName ) ; 
			Get ( ActiveFieldName ) ) ]
Set Variable [ $result ; TrFile_DragAndDrop ( "-AddDragAndDropHandler" ; Get ( FileName ) ; 
			"DragTriggerscript" ; $containerFieldBounds ) ]

This will make the drag area around a container field. It works in FileMaker 10 and later. In previous versions of FileMaker you need to correct for the status area on the left. See the scripts in the example file DragAndDrop for this.

Used in example file

DragAndDrop.fmp12

Related functionsFunction badge

TrFile_GetFileAttribute
TrFile_StartDragSource

Related script stepScript step badge

Add DragAndDrop Handler

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 16 to 2023 –> TrFile_DragAndDrop (filep4298) 2023-0601 15:17:15