SC, Image Files and MPI

Click on an image to open a fullsized version in another window.

Defining the FavoriteFlavors UserProp
Defining the FavoriteFlavors UserProp 505 by 286

Drag and Drop 1

We are going to add the ability to drag files from the finder onto our list field to add them to the list.
The first script we write will just add the ability to add one file, we will deal with multiple files and folders later.
Before we do that we have to tell SuperCard we will be using Drag and Drop and that we want to accept file drops from the finder.
We add this to our project script:

on openProject
set the allowDND to true
set the allowFavorites to true
end openProject

allowDND is a shorter form of allowDragAndDrop
allowFavorites is a shorter form of allowFavoriteFlavors (UK spellers watch the Us)
After typing this script the first time, type openProject in the mesagebox and hit return.
We need to make sure our imagelist field has it's allowDrop set to true, use the Property Inspector.
We need also to define a favoriteflavors upserprop for our field and set it to 'hfs " note the space.
In MPI use the UserProp Module. If you are using the RTE hover over the field with the browse tool and hold down shift-alt-command.

We are ready to script our field for mouseDrops. We will take it slowly testing as we go.
Start with this script:
on mouseDrop

put the dragFlavors
end mouseDrop

Try dragging a file from the finder onto your field.
It should put 'hfs ,furl" in the messageBox
Change the put to answer and keeping SuperCard in the foreground, drag 2 files from the finder to your field, you should get an answer of
hfs ,furl
hfs ,furl
the 'hfs ' flavor is the one we want, as it conrtains the path to the file.
try this script in your filelist field:
on mouseDrop

put line 1 of the dragFlavors into tdragFlavors
get dragData(1, "hfs " )
--we are just getting the first file dragged at the moment, if you drag
--two or more files we only find out about the first one

put it
--we then return true to let SuperCard know we don't want it to process the drop
return true
end mouseDrop

We can now adapt the script from the Add File... button to add the file name to the field and the filepath to the userprop.
But first we need to check if the file is an image file. Remember we used a function to do this in our Add Folder... button.
We are going to try a slightly different way of testing fro image file this time. I found the appleScript Method seem to take far too long when called from a mouseDrop, I am not sure why.
Luckily the dragData contains information about the file type
dragData("hfs ",type)

returns the file type and creator eg" JPEG,prvw "for a jpeg file .
But some files in os X don't have a file type or creator, so in this case we can check for an extension.
In the field mouseDrop script, I am going to get the file type and pass it and the file path to my function for checking:
function AltIsGraphicFile pfileType,pFilePath

if COMMA&pfileType&COMMA is in "GIFf,JPEG,8BPS,JPEG,BMPf,jp2 ,PDF ,PICT,PNTG,qtif,.SGI,TPIC,TIFF,pct"
then return true
--I put a comma on each side of the pFileType so that it will only return true if the filetype is equal to aone of my fileTypes in the list
--probably not too important here, but more important below

set the itemDel to "."
put last item of pfilePath
if COMMA&last item of pfilePath&COMMA is in "psd,gif,jpg,bmp,jp2,pdf,pict,pntg,qtif,sgi,tga,tiff"
then return true
return false
end AltIsGraphicFile

My field script now looks like this:
on mouseDrop

put line 1 of the dragFlavors into tdragFlavors
put dragData(1, "hfs " ) into tFilePath
put item 1 of dragData(1, "hfs ",type ) into tFileType
--now we have the file type and path we can pass this to our function
--returning true will bail out of the handler and let
--SuperCard know we don't want to do anything else with the drop

if not AltIsGraphicFile( tFileType,tFilePath) then return true
--so if it is an image we process it
--adding it's name to the field and the path to the fileds userprop

set the itemDel to colon
put last item of tFilePath into tFileName
if the number of lines in cd fld "imagelist" = 0
put tfileName into cd fld "imageList"
set the uImagePaths of cd fld "imageList" to tFilePath
put CR&tfileName after cd fld "imageList"
set the uImagePaths of cd fld "imageList" to the uImagePaths of cd fld "imageList"&CR&tFilePath
end if
return true
end mouseDrop

This just deals with one file dragged from the finder to the field, we will work out how to deal with multiple drops and folders next.