Professional Web Applications Themes

Cocoa: Saving doent to another doent type using "Save As...." - Mac Programming

I have a Cocoa doent-based application in which I use separate subclasses of a single parent subclass to implement read and save operations for different types of file. I would like to be able, after reading in a doent from one file type, to write it out to a file of another type. I gather I could do this by overriding saveDoentAs in my superclass and using an auxiliary view to provide a popup menu with the possible save types - then creating a copy of the doent with the appropriate doent subclass and using its write method. This seems ...

  1. #1

    Default Cocoa: Saving doent to another doent type using "Save As...."

    I have a Cocoa doent-based application in which I use separate
    subclasses of a single parent subclass to implement read and save
    operations for different types of file. I would like to be able,
    after reading in a doent from one file type, to write it out to a
    file of another type.

    I gather I could do this by overriding saveDoentAs in my superclass
    and using an auxiliary view to provide a popup menu with the possible
    save types - then creating a copy of the doent with the appropriate
    doent subclass and using its write method.

    This seems surprisingly bersome, and would require the parent
    doent class to know about the subclasses to properly fill the popup
    menu. Is there any 'built-in' functionality to do this in Cocoa that
    I am missing? I was encouraged to use subclasses for different file
    types by the Info.plist entries for doent types. So far it has
    worked well, but this issue of cross-format saving does not seem to be
    so simple...

    Thanks for any suggestions -

    ER
    Eric Guest

  2. #2

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    Eric Raas <com> wrote:
     

    The doent architecture does this right out of the box. There is a
    Save As dialog and it lists your doent types. m.

    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

  3. #3

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    In article <1g5nddc.bn3oc4nsrdwsN%com>,
    com (matt neuburg) wrote:
     
    >
    > The doent architecture does this right out of the box. There is a
    > Save As dialog and it lists your doent types. m.[/ref]

    Speaking of which, does the doent architecture support "export-only"
    formats? The feature you mention works fine when I have a bunch of
    doent types for my class that have CFBundleTypeRole set to Editor,
    but am I right to understand that I have to implement the "file type"
    popup myself if I have just one "Editor" type, but a bunch of file
    formats I can export?

    Just
    Just Guest

  4. #4

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    Just <nl> wrote:
     
    > >
    > > The doent architecture does this right out of the box. There is a
    > > Save As dialog and it lists your doent types. m.[/ref]
    >
    > Speaking of which, does the doent architecture support "export-only"
    > formats? The feature you mention works fine when I have a bunch of
    > doent types for my class that have CFBundleTypeRole set to Editor,
    > but am I right to understand that I have to implement the "file type"
    > popup myself if I have just one "Editor" type, but a bunch of file
    > formats I can export?[/ref]

    RTFM. ...Doentation/Cocoa/Conceptual/Doents/Tasks/FAQ.html

    m.

    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

  5. #5

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."


    >
    > The doent architecture does this right out of the box. There is a
    > Save As dialog and it lists your doent types. m.[/ref]

    That's what I expected, but am not getting the dialog box. Perhaps
    only the types for which the application is designated an 'editor' in
    the Info.plist file are displayed... will have to check this when I
    get back to the source tomorrow. Thanks.
    Eric Guest

  6. #6

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    In article <1g5nt4y.ss2mbsw9hvzoN%com>,
    com (matt neuburg) wrote:
     
    >
    > RTFM. ...Doentation/Cocoa/Conceptual/Doents/Tasks/FAQ.html[/ref]

    Thanks, I didn't know that doent existed.

    Just
    Just Guest

  7. #7

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    In article <google.com>,
    com (Eric Raas) wrote:
     
    > >
    > > The doent architecture does this right out of the box. There is a
    > > Save As dialog and it lists your doent types. m.[/ref]
    >
    > That's what I expected, but am not getting the dialog box. Perhaps
    > only the types for which the application is designated an 'editor' in
    > the Info.plist file are displayed... will have to check this when I
    > get back to the source tomorrow. Thanks.[/ref]

    Yes, you only get the popup if the number of "editor" types > 1. Look
    for NportableAs for export-only types.

    Just
    Just Guest

  8. #8

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    > > > I have a Cocoa doent-based application in which I use separate 
    > >
    > > The doent architecture does this right out of the box. There is a
    > > Save As dialog and it lists your doent types. m.[/ref]
    >
    > That's what I expected, but am not getting the dialog box. Perhaps
    > only the types for which the application is designated an 'editor' in
    > the Info.plist file are displayed... will have to check this when I
    > get back to the source tomorrow. Thanks.[/ref]

    Hmm. I definitely don't get a list of file types in my "Save As..."
    dialog, although I am getting it "for free" as part of my doc-based
    app.

    - for each doent type the app is designated "editor" in the
    info.plist file
    - each doc type (corresponding to file types) is a subclass of a
    parent doent
    class (itself a subclass of NSDoent) - these are associated
    with file extensions
    in the info.plist file
    - the type-specific subclasses *only* implement readFromFile:ofType:
    and
    writeWithBackupToFile:ofType:saveOperation: for the appropriate
    file type

    Is it necessary to implement any of the methods like isNativeType, or
    perhaps the use of writeWithBackupToFile:ofType:saveOperation instead
    of writeToFile:ofType creates a problem...

    The only things indicated in the info.plist file are that some types
    are editors, and what the doent class to use is. Not sure if there
    are other keys needed. I read FAQ suggested in a previous post and
    although it contains a lot of useful info, it does not seem to explain
    my lack of "Save As..." type selection.

    Thanks again,

    ER
    Eric Guest

  9. #9

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    Eric Raas <com> wrote:
     
    > >
    > > That's what I expected, but am not getting the dialog box. Perhaps only
    > > the types for which the application is designated an 'editor' in the
    > > Info.plist file are displayed... will have to check this when I get
    > > back to the source tomorrow. Thanks.[/ref]
    >
    > Hmm. I definitely don't get a list of file types in my "Save As..."
    > dialog, although I am getting it "for free" as part of my doc-based app.
    >
    > - for each doent type the app is designated "editor" in the info.plist
    > file - each doc type (corresponding to file types) is a subclass of a
    > parent doent class (itself a subclass of NSDoent) - these are
    > associated with file extensions in the info.plist file - the type-specific
    > subclasses *only* implement readFromFile:ofType: and
    > writeWithBackupToFile:ofType:saveOperation: for the appropriate file type
    >
    > Is it necessary to implement any of the methods like isNativeType, or
    > perhaps the use of writeWithBackupToFile:ofType:saveOperation instead of
    > writeToFile:ofType creates a problem...[/ref]

    No - the Save As dialog isn't going to yze your code! Your code has
    nothing to do with the problem at hand. Of course, you will need code to
    enable the type of doent to be written, but that's another story.
     

    I don't quite know why you need to look in the info.plist - that is
    where the framework looks, but you should be working from the
    corresponding target info window. The info.plist is generated for you
    automatically. However, here is what the relevant portion of my
    info.plist looks like. These two types show up in the Save As dialog, in
    a popup menu.

    <key>CFBundleDoentTypes</key>
    <array>
    <dict>
    <key>CFBundleTypeExtensions</key>
    <array>
    <string>digestoreDigest</string>
    </array>
    <key>CFBundleTypeIconFile</key>
    <string>stomachIcon2</string>
    <key>CFBundleTypeName</key>
    <string>Digest</string>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>NSDoentClass</key>
    <string>digestDoent</string>
    </dict>
    <dict>
    <key>CFBundleTypeExtensions</key>
    <array>
    <string>digestoreXML</string>
    </array>
    <key>CFBundleTypeIconFile</key>
    <string>stomachIcon2</string>
    <key>CFBundleTypeName</key>
    <string>DigestXML</string>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>NSDoentClass</key>
    <string>digestDoent</string>
    </dict>
    </array>




    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

  10. #10

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    In article <google.com>,
    com (Eric Raas) wrote:
     

    It sounds like you have a different NSDoent class for each doent
    type. You will only get the popup if you map multiple "editor" doc types
    to the _same_ NSDoent subclass.

    Just
    Just Guest

  11. #11

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."


    > It sounds like you have a different NSDoent class for each doent
    > type. You will only get the popup if you map multiple "editor" doc types
    > to the _same_ NSDoent subclass.
    >[/ref]

    At the time, this subclassing scheme seemed like a nice way to
    organize the code needed for different types of files - sounds like it
    breaks the "Save As" support though... will try putting all in one
    subclass.

    thanks - ER
    Eric Guest

  12. #12

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    In article <google.com>,
    com (Eric Raas) wrote:
     
    > > It sounds like you have a different NSDoent class for each doent
    > > type. You will only get the popup if you map multiple "editor" doc types
    > > to the _same_ NSDoent subclass.
    > >[/ref]
    >
    > At the time, this subclassing scheme seemed like a nice way to
    > organize the code needed for different types of files - sounds like it
    > breaks the "Save As" support though... will try putting all in one
    > subclass.[/ref]

    You could also use your classes as a class cluster: instantiation goes
    through an (abstract) base class, but you instantiate a specific
    concrete subclass based on the doent type. However, this doesn't seem
    to make much sense: you have _one_ doent type with different file
    formats; the doent model should still be the same for all file
    formats, no? Perhaps you need different classes for reading and writing
    the various formats, yet have one NSDoent subclass to manage
    everything.

    Just
    Just Guest

  13. #13

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    Just <nl> wrote:
     

    Yes, I was just going to suggest that the OP read "Design Patterns". m.

    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

  14. #14

    Default Re: Cocoa: Saving doent to another doent type using "Save As...."

    > > 
    >
    > You could also use your classes as a class cluster: instantiation goes
    > through an (abstract) base class, but you instantiate a specific
    > concrete subclass based on the doent type. However, this doesn't seem
    > to make much sense: you have _one_ doent type with different file
    > formats; the doent model should still be the same for all file
    > formats, no? Perhaps you need different classes for reading and writing
    > the various formats, yet have one NSDoent subclass to manage
    > everything.
    >[/ref]

    The doent model is indeed the same for all formats, so I will
    probably ditch the subclassing. There is not really much to gain
    except that the framework figures out which subclass to use for
    different file types. I could do the same thing in a single class
    with a switch statement or something and retain more control over how
    things behave.

    Another weird situation that arises (because my design was flawed) is
    that it was possible to edit doents loaded from "viewer" types.
    Since I was keeping track of change counts, the framework was nicely
    giving a warning sheet when I closed a dirty doent. However the
    behaviour on saving was then weird - without further prompts it would
    overwrite the original file with an "editor" file type... one
    solution would be to force the user to "Save As" an editor type before
    allowing edits.

    Probably this *is* a good time to review the Design Patterns book, as
    other poster mentioned.

    ER
    Eric Guest

Similar Threads

  1. Can I catch "Doent Properties" editing events?
    By RamonHerrera@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 4
    Last Post: March 4th, 11:47 PM
  2. Is "Adobe Distiller Parameters" doent really superseded?
    By Gene_Wirchenko@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 0
    Last Post: September 19th, 09:25 PM
  3. Doent info reports "phantom" gradient object
    By Doug_Katz@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 17
    Last Post: June 21st, 06:56 PM
  4. Back to... doent "appearance (8.5X11)" vs artboard size...
    By michael_affeld@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 17
    Last Post: February 9th, 04:15 PM

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