Professional Web Applications Themes

how to use NavCreateChooseFolderDialog - Mac Programming

I have figured out how to basically use and run this dialog, as shown below, but I don't know how to use the reply that I get back to create an fsspec for a new file in the directory that is returned. I really don't understand how the reply actually specifies a directory. In the debugger, the reply is virtualy blank (mostly 0s) except for the "selection" parameter which is a AEDesc type. I has some indecipherable longs and pointers in it. How do I use this to make a new file in the directory that has been chosen? In ...

  1. #1

    Default how to use NavCreateChooseFolderDialog

    I have figured out how to basically use and run this dialog, as shown
    below, but I don't know how to use the reply that I get back to create an
    fsspec for a new file in the directory that is returned. I really don't
    understand how the reply actually specifies a directory. In the debugger,
    the reply is virtualy blank (mostly 0s) except for the "selection"
    parameter which is a AEDesc type. I has some indecipherable longs and
    pointers in it.

    How do I use this to make a new file in the directory that has been
    chosen? In the past, I have saved files in one of two ways. One, I use
    the Nav services to specify the new file which creates the fsspec for me,
    and two, I automatically save a file without nav services (which I need to
    be able to do in my app) by using FSpCreate, FSpOpenDF, etc. In the
    latter case I always generate an FSSpec that matches the app's directory,
    because I don't know what else to do. I would like to use ChooseFolder to
    pick a folder for the automatic creation of saved files.

    Any help appreciated. Thanks.

    Here's what I've got so far:

    NavDialogCreationOptions inOptions;
    NavEventUPP myEventUPP = NewNavEventUPP(HandleNavEvent);
    NavDialogRef outDialog;
    NavReplyRecord outReply;
    OSStatus status;

    status = NavGetDefaultDialogCreationOptions(&inOptions);

    status = NavCreateChooseFolderDialog(&inOptions, myEventUPP, NULL,
    NULL, &outDialog);
    status = NavDialogRun(outDialog);
    status = NavDialogGetReply(outDialog, &outReply);
    NavDialogDispose(outDialog);

    __________________________________________________ ______________________
    Keith Wiley unm.edu
    http://www.unm.edu/~keithw http://www.mp3.com/KeithWiley

    "Yet mark his perfect self-contentment, and hence learn his lesson,
    that to be self-contented is to be vile and ignorant, and that to
    aspire is better than to be blindly and impotently happy."
    -- Edwin A. Abbott, Flatland
    __________________________________________________ ______________________
    Keith Guest

  2. #2

    Default Re: how to use NavCreateChooseFolderDialog

    In article <cs.unm.edu>,
    Keith Wiley <unm.edu> wrote:
     

    There is no shortage of sample code on this topic. A quick search reveals
    <http://developer.apple.com/samplecode/Sample_Code/Printing/AppUsingSheets/NavSer
    vicesHandling.c.htm> as helpful.

    hth

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  3. #3

    Default Re: how to use NavCreateChooseFolderDialog

    On Thu, 18 Dec 2003, Miro Jurisic wrote:
     

    Okay. I'm almost there at this point. I can successfully get the folder
    and build the necessary FSSpec and save the file. Unforunately, the file
    appears at the same level as the folder, not inside the folder. I think
    the reason is that when I use AECoerceDesc, I am unintentionally
    requesting the parent of the item that was select when what I really want
    to do is select the item itself as a folder. I have no idea how to do
    this. I looked various other parameters for AECoerceDesc and I can't see
    any way to convert the selection to a folder directly, only it's parent.

    Here's what I've got:

    FSSpec myAppSpec;

    NavDialogCreationOptions inOptions;
    NavEventUPP myEventUPP = NewNavEventUPP(HandleNavEvent);
    NavDialogRef outDialog;
    NavReplyRecord outReply;
    OSStatus status;
    OSErr err;

    status = NavGetDefaultDialogCreationOptions(&inOptions);

    status = NavCreateChooseFolderDialog(&inOptions, myEventUPP, NULL,
    NULL, &outDialog);
    status = NavDialogRun(outDialog);
    status = NavDialogGetReply(outDialog, &outReply);
    NavDialogDispose(outDialog);

    AEDesc actualDesc;
    err = AECoerceDesc(&outReply.selection, typeFSRef, &actualDesc);

    FSRef fileRefParent;
    err = AEGetDescData(&actualDesc, &fileRefParent, sizeof(FSRef));

    AEDisposeDesc(&actualDesc);

    err = FSGetCatalogInfo(&fileRefParent, kFSCatInfoNone, NULL, NULL,
    &myAppSpec, NULL);

    __________________________________________________ ______________________
    Keith Wiley unm.edu
    http://www.unm.edu/~keithw http://www.mp3.com/KeithWiley

    "Yet mark his perfect self-contentment, and hence learn his lesson,
    that to be self-contented is to be vile and ignorant, and that to
    aspire is better than to be blindly and impotently happy."
    -- Edwin A. Abbott, Flatland
    __________________________________________________ ______________________
    Keith Guest

  4. #4

    Default Re: how to use NavCreateChooseFolderDialog

    In article <cs.unm.edu>,
    Keith Wiley <unm.edu> wrote:
     
    >
    > Okay. I'm almost there at this point. I can successfully get the folder
    > and build the necessary FSSpec and save the file. Unforunately, the file
    > appears at the same level as the folder, not inside the folder. I think
    > the reason is that when I use AECoerceDesc, I am unintentionally
    > requesting the parent of the item that was select when what I really want
    > to do is select the item itself as a folder. I have no idea how to do
    > this. I looked various other parameters for AECoerceDesc and I can't see
    > any way to convert the selection to a folder directly, only it's parent.[/ref]

    That's because you are confused about how FSSpecs work. Despite what you may
    have seen anywhere else, including some Apple's code, the only proper FSSpec for
    a folder is one that has the folder name in the name field, and the dir ID of
    the folder's parent in the dirID field (and, obviously, the volume refnum in the
    vRefNum field).

    Therefore, if you have a valid folder FSSpec, the correct way to get the FSSpec
    of a file in that folder is _not_ to copy the file name into the name field,
    because then you end up with a sibling of the folder, not its child. The correct
    way is to get PBCatInfo for the folder, to get its own dirID, and then call
    FSMakeFSSpec with that dirID and the desired file name.

    Of course, this is _all_ wrong on a different level. You shoul call the new
    FSRef APIs to get an FSRef to the file from the folder FSRef, and only convert
    to an FSSpec as the very last step, and only if you really have to. This will
    allow you to handle long filenames.

    hth

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  5. #5

    Default Re: how to use NavCreateChooseFolderDialog

    In article <cs.unm.edu>,
    Keith Wiley <unm.edu> wrote:
     

    Then you should carry around the FSRef/name pair until the time you call
    FSCreateFileUnicode. For all practical purposes, FSRefs are inadequate for what
    most aps needs; you really need to use a FSRef/name pair in general.

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  6. #6

    Default Re: how to use NavCreateChooseFolderDialog

    In article <cs.unm.edu>,
    Keith Wiley <unm.edu> wrote:
     

    Yes, that's what I meant. Thanks.

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  7. #7

    Default Re: how to use NavCreateChooseFolderDialog

    On Fri, 19 Dec 2003, Miro Jurisic wrote:
     

    You say above "FSRef to the file". What if there is no file yet? What if
    I am asking the user to select a folder so I can create a new file in that
    folder. Then there is no file to get yet. I haven't created it yet, if
    you see my meaning.

    __________________________________________________ ______________________
    Keith Wiley unm.edu
    http://www.unm.edu/~keithw http://www.mp3.com/KeithWiley

    "Yet mark his perfect self-contentment, and hence learn his lesson,
    that to be self-contented is to be vile and ignorant, and that to
    aspire is better than to be blindly and impotently happy."
    -- Edwin A. Abbott, Flatland
    __________________________________________________ ______________________
    Keith Guest

  8. #8

    Default Re: how to use NavCreateChooseFolderDialog

    On Fri, 19 Dec 2003, Miro Jurisic wrote:
     

    A search for "PBCatInfo" on dev.apple reviews 0 hits. What is it?

    __________________________________________________ ______________________
    Keith Wiley unm.edu
    http://www.unm.edu/~keithw http://www.mp3.com/KeithWiley

    "Yet mark his perfect self-contentment, and hence learn his lesson,
    that to be self-contented is to be vile and ignorant, and that to
    aspire is better than to be blindly and impotently happy."
    -- Edwin A. Abbott, Flatland
    __________________________________________________ ______________________
    Keith Guest

  9. #9

    Default Re: how to use NavCreateChooseFolderDialog

    I found some stuff in the File Manager Ref. I think you meant
    PBGetCatInfoSync, which does appear to return the dir Id of a specified
    dir. I'll have to give a go and see if it works.

    __________________________________________________ ______________________
    Keith Wiley unm.edu
    http://www.unm.edu/~keithw http://www.mp3.com/KeithWiley

    "Yet mark his perfect self-contentment, and hence learn his lesson,
    that to be self-contented is to be vile and ignorant, and that to
    aspire is better than to be blindly and impotently happy."
    -- Edwin A. Abbott, Flatland
    __________________________________________________ ______________________
    Keith Guest

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139