document types with NSDocument framework
document types with NSDocument framework
- Subject: document types with NSDocument framework
- From: "Simson Garfinkel" <email@hidden>
- Date: Fri, 23 Nov 2001 20:06:48 -0500
I'm trying to figure out how to get the NSDocument frameowkr to allow me to
specify file types for saving and loading documents without having to create
my own Save and Load panels. I'm also trying to figure out how to get document
icons to be automatically set. This has been somewhat frustrating because the
NSDocument documentation doesn't agree with the include files, and none of
them completely agree with the ProjectBuilder Target->Application Settings
tab.
Help is appreciated!
Here are the specific questions that I have:
LOADING:
1. How do I specify the list of file types that my NSDocument subclass can
understand? The obvious way should be to subclass the +(NSArray *)readableTyes
method, but the NSDocument.h include file says:
//
-----------------------------------------------------------------------------
// Types API
//
-----------------------------------------------------------------------------
+ (NSArray *)readableTypes;
// Returns all types that the receiving document class can play the role
of Editor or Viewer for. This method cannot currently be overridden in any
meaningful way.
So the second obvious way to do it would be to set it in the Applicaiton
Settings section of Project Builder. The third way is to follow the document
in the NSDocument documentation and create a CustomInfo.plist file. The
documentation says "Developers must hand-craft this property list for the
current release. In future releases, Project Builder will assist in the
creation of this property list." That's the documentation from Apple's website
but it seems to be current.)
SAVING
2. How do I give the user of specifying multiple save types? The default
saveDocument: method doesn't seem to allow this.
The documentation says:
saveDocument:
- (IBAction)saveDocument:(id)sender
The action method invoked in the receiver as first responder when the user
chooses the Save menu command. The default implement saves the document in two
different ways, depending on whether the document has a file path and a
document type assigned. If path and type are assigned, it simply writes the
document under it's current file path and type after making a backup copy of
the previous file. If the document is new (no file path and type), it runs the
modal Save panel to get the file location under which to save the document. It
writes the document to this file, sets the document's file location and
document type (if a native type), and clears the document's edited status.
See Also: - fileNameFromRunningSavePanelForSaveOperation: - setFileName: -
setFileType: - updateChangeCount:
The problem here is the phrase " it runs the modal Save panel to get the file
location under which to save the document."
The "clean" way to do this, I think, would be to have an NSArray of
readableTypes (see above). That doesn't seem to work. Another way would be to
specify an Accessory View and then have a target of a pop-up that sets file
types. But the runModalSavePanel:withAccessoryView: method has been
depricated.
3. How do I get the saved document to have the proper file type and icon?
It turns out that the TextEdit demo does an Open panel with an aux view, but
it doesn't use the NSDocument arhcitecture; it implements it all. (It was
written before the NSDocument architecture and it hasn't been rewritten.)
The Sketch demo uses the NSDocument architecture and it has a Save panel that
allows the user to specify the file type, but I can't find where it is coming
from.
Any help is greatly appreciated. Thanks!