Re: Document Types
Re: Document Types
- Subject: Re: Document Types
- From: Mark Munz <email@hidden>
- Date: Tue, 6 Apr 2004 13:19:57 -0600
On Apr 6, 2004, at 11:53 AM, Seth Willits wrote:
In a nutshell, my program should be able to open any text file. The
application will ship with a bunch of language files which will
contain default file extensions and such (need them for something else
anyway), and the users can change these files or add more, but I don't
want the user to have to define a file extension before they can use
the program.
For example, I just created a file "Untitled.bob" and SubEthaEdit can
open it wonderfully. In fact, it can open ANY file, just like BBEdit.
How do you do that? I would have figured that the old "????" would
have worked or even an empty string, but neither did.
Take a look at the TextEdit project (/Developer/Examples/AppKit) and
look at the properties associated with text files. The basics of it:
Extensions: txt text "*"
Mime Types: text/plain
OS Types: "****"
That pretty much picks up any text file. There is a little trickiness
with regards to all the encoding a text file can be in. TextEdit's code
is rather elaborate in determining the encoding if using the
"Automatic" option. I decided to default to MacRoman and let the user
change it if appropriate.
Another related question is, if I want to add a view to the open and
save dialogs for my documents, what method do I implement? Surely I
don't need to completely override the opening and saving of documents,
do I?
If you're application is NSDocument based, you'll need to subclass
NSDocumentController and setup your AccessoryView in:
- (int)runModalOpenPanel:(NSOpenPanel*)openPanel
forTypes:(NSArray*)extensions
[openPanel setAccessoryView:myOpenAccessoryView];
If you want to add an AccessoryView to the Save Panel, you'll need to
add this method to your NSDocument subclass:
- (BOOL)prepareSavePanel:(NSSavePanel*)savePanel
In here, you can call [savePanel setAccessoryView:
mySaveAccessoryView]; to set mySaveAccessoryView as the accessory view.
That's a quick summary. You can get different bits of how this works
from the TextEdit code, but TextEdit is not NSDocument-based, so you'll
have to likely adapt the code accordingly.
Mark Munz
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.