TrFile_DragAndDrop (function reference)

By May 1, 2017 May 22nd, 2019 Online Help, Troi File Plug-in
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

switchesdetermine the behavior of the function
fileNamethe name of the file that contains the script to be triggered
scriptNamethe 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:

-AddDragAndDropHandlerthe plug-in starts accepting drag and drop. You can now drag files on the window
-StopDragAndDropthe 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
-CopyCursorwhile 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:

-AllowMailDropsthis will allow emails (from the OS X Mail.app) to be dragged to FileMaker
-ScrollDropZonewhen 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

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:

0no error
$$-50paramErrthere was an error with a parameter
$$-5600errInvalidWindowRefthe window could not be found
$$-4223errTooManyEventsyou have specified more than 3 D&D handlers

Other errors may be returned.

Originated in

Troi File Plug-in 4.6

Compatibility

FileMaker Pro 14 to 18

Considerations

You can now specify three separate drag destinations, by calling the function three times with the switch -AddDragAndDropHandler with the 3 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
– (Mac OS) the drop box highlight is only visible over a white background.
– (Mac OS) the link and copy cursor is visible only when moving the cursor.

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 ; Value : Position ( $pathList ; "¶" ; 1 ; 1 ) ] 
Set Field [ this::onepath ; Value : 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 Field [ gErrorCode ; 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 Field [ gErrorCode ; 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.

Related functionFunction badge

TrFile_GetFileAttribute

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 14 to 18 –> TrFile_DragAndDrop (filep4298) 2019-0522 16:36:30