[FIX][VM] macintosh AppleEvents open document logic

John M McIntosh johnmci at smalltalkconsulting.com
Fri Aug 11 00:09:10 UTC 2000


Attached is a chunk of code that fixes a number of problems in the macintosh
VM open document logic via AppleEvents. If we are to have STch and SOBJ and
STim files then of course a user can select a bunch of them at any time and
open them.


This has interesting issues:

1) If Squeak is already running, and you open one file then it replaces the
short image name and changes the working directory to point to the file in
question. Mmmm.

2) If Squeak is already running, and you open two or more files then you
crash into the command line environment with a message saying you can only
open one squeak file at a time. (Not good)

3) If Squeak isn't running, then opening a changes file makes Squeak attempt
to read it in as a 'SOBJ' Squeak Object file. Which doesn't work.


However the attached code fixes all the funny behavior, I think.

Bug yet to fix. If you have a file call foo.changes and double click on it,
then it wants to look for Squeak.image, which it can't find.


PS Yes I'll roll this all into a full mac VM change set in a day or two.


PS Looking for that browser plugin? Well testing is afoot...
--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================
Custom Macintosh programming & various Smalltalk dialects
PGP Key: DSS/Diff/46FC3BE6
Fingerprint=B22F 7D67 92B7 5D52 72D7  E94A EE69 2D21 46FC 3BE6
===========================================================================


pascal OSErr HandleOpenDocEvent(const AEDescList *aevt, AEDescList *reply,
UInt32 refCon) {
    /* User double-clicked an image file. Record the path to the VM's
directory,
       then set the default directory to the folder containing the image and
       record the image name. Fail if mullitple image files were selected.
*/

    OSErr        err;
    AEDesc        fileList = {'NULL', NULL};
    long        numFiles, size;
    DescType    type;
    AEKeyword    keyword;
    FSSpec        fileSpec;
    WDPBRec        pb;
    FInfo        finderInformation;
    
    reply; refCon;  /* reference args to avoid compiler warnings */

    /* record path to VM's home folder */
    PathToWorkingDir(vmPath, VMPATH_SIZE);

    /* copy document list */
    err = AEGetKeyDesc(aevt, keyDirectObject, typeAEList, &fileList);
    if (err) return errAEEventNotHandled;;

    /* count list elements */
    err = AECountItems( &fileList, &numFiles);
    if (err) goto done;
    
    if (shortImageName[0] != 0) {
        goto done;
    }

    /* get image name */
    err = AEGetNthPtr(&fileList, 1, typeFSS,
                      &keyword, &type, (Ptr) &fileSpec, sizeof(fileSpec),
&size);
    if (err) goto done;
    
    err = FSpGetFInfo(&fileSpec,&finderInformation);
    if (err) goto done;
        
    CopyPascalStringToC(fileSpec.name,shortImageName);

    if (!(IsImageName(shortImageName) || finderInformation.fdType == 'STim')
|| finderInformation.fdType == 'STch') {
        /* record the document name, but run the default image in VM
directory */
        if (finderInformation.fdType == 'SOBJ')
            StoreFullPathForLocalNameInto(shortImageName, documentName,
DOCUMENT_NAME_SIZE);
        strcpy(shortImageName, "squeak.image");
        StoreFullPathForLocalNameInto(shortImageName, imageName,
IMAGE_NAME_SIZE);
    }
    /* make the image or document directory the working directory */
    pb.ioNamePtr = NULL;
    pb.ioVRefNum = fileSpec.vRefNum;
    pb.ioWDDirID = fileSpec.parID;
    PBHSetVolSync(&pb);

done:
    AEDisposeDesc(&fileList);
    return err;
}





More information about the Squeak-dev mailing list