Changing filetype/extension of saved document?
Changing filetype/extension of saved document?
- Subject: Changing filetype/extension of saved document?
- From: Matt Gemmell <email@hidden>
- Date: Mon, 16 Jun 2003 18:12:39 +0100
Hi all,
Just for the hell of it, I'm working on a little Stickies-like
document-based app. One of the things I wanted to try out was having
each document's icon reflect the background colour of the "note" which
it contains. There are six possible background colours at the moment,
as with Stickies itself.
I've created six corresponding document types for my app, with six
file-extensions (.greenNote, .blueNote, etc). All six types have their
Document Class set to the same NSDocument subclass (since their content
is identical). When the user changes the background colour of a note, I
use -[NSDocument setFileType:] to change the filetype appropriately.
This works fine for new documents (i.e. documents which have not been
saved). It does not work for documents which have already been saved.
I've tried composing a new filename/path with the appropriate new
file-extension, and calling -[NSDocument setFileName:] and -[NSWindow
setRepresentedFilename:] with that new path. When I then try to save
these changes, I get a sheet saying that "the location of the file
could not be determined", and offering to let me specify where to save,
which is awkward at best.
I'm aware that this practice of having multiple document types for
identical files is dubious, and that changing the file-extension of a
document based on the user changing its background colour is even more
dubious, but this project is a learning exercise and I'd really like to
implement the functionality properly. If there's a "better" way to have
different icons based on the content of a file, I'd really love to hear
more about it.
If no such better way exists, can anyone offer any advice as to how I
can seamlessly change the filetype/extension of an open document, such
that when the user next saves it, it is silently saved with that new
extension? I'm aware I'll probably have to take care of manually
removing the old file in this situation, and of the potential dangers
involved. Thanks for any response!
Cheers,
-Matt
--
Matt Gemmell
Scotland Software
http://www.scotlandsoftware.com/
_______________________________________________
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.