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 a field that you can use to display the folder path in.
Add Code To Field Script
If the user clicks on a system folder and drags over the field then the dragData["files"] property will return the path to the folder the user is dragging. The code 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 will accept a drop.
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 to look right to the user. 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).
Code
on dragEnter
if there is a folder the dragData["files"] then
## set the acceptdrop to true -- pre-2.9
set the dragaction to copy -- 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
Now when you drag a folder onto the field a drop will be allowed...
and the path to the folder will be displayed.
0 Comments
Add your comment