Dropping System Folders on Fields

This lesson demonstrates how to allow a user to drop a system folder onto a field. The folder path is then displayed in the field.

Create UI Elements

Create UI Elements

Create a field that you can use to display the folder path in.

Add revTalk To Field Script

Add revTalk To Field Script

If the user clicks and drags a system folder over the field then the dragData["files"] property will return the path to the folder the user is dragging. The revTalk to deal with this scenario is as follows.

1) Create a dragEnter handler that checks if the dragData["files"] is a folder. We don't want to accept files. If the property contains a folder path then the field tells the Revolution engine that it can accept the data being dragged by setting the dragAction property.

2) In the dragDrop handler assign the dragData["files"] property to the field. Since Revolution paths always use slash as a path delimiter it is a good idea to format the path so that it looks appropriate for the platform your program is running on. Two helper functions are included in this script that can convert from a Revolution path to a native path (3) and a native path to a Revolution path (4).

==========

Copy & Paste

==========

on dragEnter

if there is a folder the dragData["files"] then

## set the acceptdrop to true -- pre-Rev 2.9

set the dragaction to copy -- >= Rev 2.9

end if

end dragEnter

on dragDrop

## Display the folder path in platform native format

set the text of me to \

fileConvertRevPathToNative(the dragData["files"])

end dragDrop

## Converts Revolution path to native path

function fileConvertRevPathToNative pPath

if "Win" is in the platform then

replace slash with backslash in pPath

end if

return pPath

end fileConvertRevPathToNative

## Converts native path to Revolution path

function fileConvertNativePathToRev pPath

if "Win" is in the platform then

replace backslash with slash in pPath

end if

return pPath

end fileConvertNativePathToRev

Code in Action

Code in Action

Now when you drag a folder onto the field a drop will be allowed...

and the path to the folder will be displayed.

Additional Notes

You may also want to take into account situations where the user is dragging multiple files or folders. In this case the dragData["files"] will contain one file/folder path per line.

1 Comments

Barry Sumpter

for miltiple selections expand the field "field" to show miltiple lines. And add the following code line:

on dragEnter
set the acceptDrop to true

Add your comment

E-Mail me when someone replies to this comment