KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Drag and Drop - Determining if a disk file is being dropped
PRODUCT: 4D | VERSION: 12.2 | PLATFORM: Mac & Win
Published On: June 3, 2011

If the goal is to support Drag and Drop of a disk file of type TBD (To Be Determined) the technique needed crosses a couple of themes within 4D documentation, Drag and Drop and Pasteboard. So how does one tell when the commands from one theme are to be used and the commands from the other is to be used?

In the Drag and Drop documentation in the Commands of the Pasteboard Theme topic it states:

"If the drag and drop operation involves the moving of heterogenous data or documents between two 4D applications or a 4D application and a third-party application, the commands of the “Pasteboard” theme will provide you with the tools needed."

In the Pasteboard documentation it states:

"4D uses two data pasteboards: one for copied (or cut) data, which is the actual clipboard that was already present in previous versions, and the other for data being dragged and dropped."

Below is a code snippet that demonstrats how to integrate the commands from both themes to be able to detect and then handle a disk file of unknown type being dropped onto a 4D Dropable object.

C_POINTER($srcObject_P)
C_LONGINT($srcElement_L;$srcProcess_L;$Ndx)

DRAG AND DROP PROPERTIES($srcObject_P;$srcElement_L;$srcProcess_L)
If (Not(Nil($srcObject)))


Else
   ARRAY TEXT($4Dsignatures;0)
   ARRAY TEXT($nativeTypes;0)
   ARRAY TEXT($ormatNames;0)

   GET PASTEBOARD DATA TYPE($4Dsignatures;$nativeTypes;$formatNames)
   If (Find in array($4Dsignatures;"com.4d.private.file.url")>0)
        //
        // Handle 4D signature for a file pathname
        //

       ARRAY TEXT($filesArray;0)
       C_TEXT($filePath_T)
       $Ndx:=1
       Repeat
          $filePath_T:=Get file from pasteboard($Ndx)
          If ($filePath_T#"")
             APPEND TO ARRAY($filesArray;$filePath_T)
             $Ndx:=$Ndx+1
          End if
       Until ($filePath_T="")

       If (Size of array($filesArray)>0)
           //
           // Test external file pathnames for processing
           //

       End if
   Else
    //
    // Handle other 4D signatures
   
//
   End if
End if


The array $filesArray will contain an absolute path to the file. Using this path you can then determine what type of file was dropped and what to do with it.