having problems with carbon file dialog box please help me...

Discussion in 'Mac Programming' started by itayKinnrot, Oct 15, 2007.

  1. itayKinnrot macrumors newbie

    Joined:
    Oct 15, 2007
    #1
    hi,
    i'm trying to open a file dialog box with defualt path on the begining (which i or the user will choose...)
    i'm having problem with this function :
    ////code:
    switch (callBackSelector) // 2

    {
    case kNavCBStart:
    status = NavCustomControl(MyDialogRef,

    kNavCtlSetLocation,

    &fileN);
    1. fileN is from the type AEDesc but i'm having problems with it
    Thank you very much
    itay
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  3. itayKinnrot thread starter macrumors newbie

    Joined:
    Oct 15, 2007
    #3
    Thanks, i already tried it - i need full example with this code

    i'm having problems with the Desc i think - it's just not working
    Thank you
     
  4. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #4
    Show the code you are using to create the AEDesc then, otherwise we have no clue what it is you are doing, or doing wrong as the case may be.

    Are you using an FSSpec or FSRef in the AEDesc? Is the path a folder (directory, *blech*)?

    It is virtually impossible to fix your problem when you haven't fully explained what you are doing.
     
  5. itayKinnrot thread starter macrumors newbie

    Joined:
    Oct 15, 2007
    #5
    here is the code -- Thanks...

    OSStatus PathToFSSpec(const char *path, FSSpec spec)
    {
    OSStatus err;
    FSRef ref;
    if ((err = FSPathMakeRef((const UInt8*)path, &ref, NULL)) != noErr) {
    return(err);
    }
    // FSRef -> FSSpec
    if ((err = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, &spec,
    NULL)) != noErr) {
    return(err);
    }
    return(noErr);
    }

    in the event handler function:
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++

    pathname = malloc(200*sizeof(char));
    strcpy(pathname,"/Users/");


    FSSpec spec;
    err = PathToFSSpec(pathname, spec);


    AEDesc desc;
    err = AECreateDesc(typeFSS, &spec, sizeof(FSSpec),&desc);





    switch (callBackSelector) // 2
    {
    case kNavCBStart:
    status = NavCustomControl(MyDialogRef,
    kNavCtlSetLocation,
    &desc);
     
  6. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #6
    Since you are already using Carbon you might as well use FindFolder() to locate the Users folder. Despite what certain Mac OS X Developers may say, using literal paths is a Bad Idea™. For one thing the name of the Users folder may be localized on non-English systems, or it may be in a mounted network volume at a different path than local Users.

    So FindFolder is the best choice here. In fact we can use a "modern" variant that returns a FSRef which we can convert down to an FSSpec:

    FSFindFolder(
    short vRefNum,
    OSType folderType,
    Boolean createFolder,
    FSRef * foundRef)

    To find the Users folder you just use:

    Code:
    FSRef   theUsersFolderRef;
    OSStatus   result;
    
    result = FSFindFolder(
      kOnAppropriateDisk,
      kUsersFolderType,
      FALSE,
      &theUsersFolderRef);
    Then you can convert that to an FSSpec:

    Code:
    FSSpec theUsersFolderSpec;
    
    FSGetCatalogInfo(theUsersFolderRef,
    0,
    NULL,
    NULL,
    &theUsersFolderSpec,
    NULL);
     

Share This Page