Skip to main content

TrFile_StartDragSource (function reference)

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

TrFile_StartDragSource

Begins a source for drag and drop. Allows you to click and drag the (binary) contents of a container field as a file out of FileMaker into other applications.

SyntaxFunction badge

TrFile_StartDragSource( switches ; sourceBinaryData { ; filename } )

Parameters

switches modifies the behavior of the function
sourceBinaryData a container field you want to drag out of FileMaker
fileName (optional) the file name to use for the dropped file.

Switches

Switches can be empty or one or more of the following:

-HighlightDragSource show the (current) rectangle of the DragSource (macOS only)

Returned Result

Data type returned

Error code

Result

The returned result is an error code. Returned error codes can be:

0 no error the drag was started
$$-50 paramErr the source is empty

Other errors may be returned.

Originated in

Troi File Plug-in 15.0

Compatibility

FileMaker Pro 16 to FileMaker Pro 2023

Considerations

This will begin the drag and drop action. You don’t need to stop it as the OS system will stop it when the user has dragged the file to the destination or canceled the action.
You add this function to a tooltip calculation to enable it on the layout.
For debugging you can also add this switch: “-HighlightDragSource”, which will show the (current) rectangle of the DragSource (macOS only).

Files stored as reference that cannot be found will create a text file: fileReference.txt. This will contain the filename and the (broken) path to the file.

Example

In layout mode add a container to the layout. In the Inspector go to the Position tab. Add a tooltip calculation similar to this:

// Enable dragSource with the TrFile_StartDragSource function:
Let(
[
switches         = this::gDragSrc_Switches;
sourceBinaryData = Self; // Self is a container field here. You can also specify a 
                         // global variable or field name (like this::thumbnail).

proposedFilename = "" ; // optional!
tooltipMessage   = "Click and DRAG IT OUT!";
scriptToTriggerAfterDrag = "DS_DidDragAndDrop_Trigger" ; // optional! 
sourceIsEmpty = sourceBinaryData = "";
errorCode = If(sourceIsEmpty ; 
               0 // do nothing
            ; // Else
              TrFile_StartDragSource( switches ; sourceBinaryData ; 
                                                 proposedFilename ; scriptToTriggerAfterDrag ) 
);
tooltipMessage = If( errorCode <> 0 ; 
                    "ERROR enabling StartDragSource function of Troi File Plug-in. Error code = " 
                    & errorCode 
                 ; // Else
                    tooltipMessage )
] ;

If( not sourceIsEmpty ; tooltipMessage)
)

You can also add this (optional) trigger script “DS_DidDragAndDrop_Trigger” that will be triggered after a successful drag and drop:

# This script is called after a successful drag from the DragSource container has occurred. 
# This trigger is optional, you can add your own handling of the result.
# In this example we log it in a text field.

If [ PatternCount ( this::gDragSrc_Switches ; "-BeepAfterSuccessfulDrag" ) ] 
	Beep
End If

Set Variable [ $ScriptName; Get(ScriptName) ]
Set Variable [ $FileName; GetValue( Get(ScriptParameter); 1 ) ] 

If [ 0 ]
   Show Custom Dialog [ "Scriptname triggered: " & $Scriptname & 
                                    "¶File Dragged out: " & $FileName; “OK” ]
End If

Set Variable [ $Tab; Value:Char ( 9 ) ]
Set Field [ this::gDragSrc_CompletedDragsLog; this::gDragSrc_CompletedDragsLog & 
			If( this::gDragSrc_CompletedDragsLog <> ""; "¶" ) &
			Get(CurrentTimestamp) & $Tab & $ScriptName & $Tab & $FileName ]
Exit Script [ Result: 0 ]

Related functionsFunction badge

TrFile_CreateFile
TrFile_DragAndDrop

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 16 to 2023 –> TrFile_StartDragSource (filep4330) 2023-0601 16:08:01