FROM : James Bucanek
DATE : Tue Jun 20 19:40:53 2006
Martin Redington wrote on Tuesday, June 20, 2006:
>
>I have pretty much exactly the same problem as Lon and James.
>
>I would like to provide a default name for the document, and avoid
>the user having to see the Save Panel.
>
>In an ideal world, I would simply be able to call setFileName or
>setFileURL on the NSDocument, and then call saveDocument: to write it
>out.
>
<clip>
>
>So it would seem that according to the docs, this should do exactly
>what I want. I'm not keen to ditch the NSDocument framework, in order
>to get, what seems to me, to be a fairly simple variation.
>
>As it stands, when I call saveDocument: having set the fileName/URL
>(fileType) is correctly set as well, I get "The location of the
>document "DocumentName" cannot be determined", with Cancel and Save
>As options.
>
>I also get the disabled Save Menu that other people have reported.
>
>Any pointers on how to programmatically set the filename and save the
>file without user intervention would be great. Note that I would
>still like Save As, and Save to be operational.
I got around this problem with some, but not an overwhelming, hack of NSDocument. I think the fundamental problem is NSDocument's interpretation of fileName/setFileName:. In NSDocument's world, a file name set on a document means that the document *has* been saved to that file, not that it *should* or *will* be saved in that file. So manually setting the file name of a document sends NSDocument in to a tizzy, thinking that the document file is lost.
Looking back, I fixed the Save menu using validateMenuItem:
case MENU_SAVE_ITEM:
return ([self isDocumentEdited]);
I fixed the confusing Save dialog by overriding canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:. My replacement simply checks to see if the document has been edited and either puts up a modal sheet asking the user if they want to save their changes (no mention of a filename or where), or it just falls through and invokes the shouldClose selector with YES.
Finally, I overrode saveDocument to simply generate my internal filename and save the document. Do not call [super saveDocument:] to do the saving! NSDocument will get all confused with a file name for a document with no file.
I completely disable Save As... becuase it makes no logical sense to allow the user to specify a name for a file they can't name.
And for cosmetic reasons, I also override displayName so the window title is something other than the name of the actual file (which will make no sense to the user).
--
James Bucanek
DATE : Tue Jun 20 19:40:53 2006
Martin Redington wrote on Tuesday, June 20, 2006:
>
>I have pretty much exactly the same problem as Lon and James.
>
>I would like to provide a default name for the document, and avoid
>the user having to see the Save Panel.
>
>In an ideal world, I would simply be able to call setFileName or
>setFileURL on the NSDocument, and then call saveDocument: to write it
>out.
>
<clip>
>
>So it would seem that according to the docs, this should do exactly
>what I want. I'm not keen to ditch the NSDocument framework, in order
>to get, what seems to me, to be a fairly simple variation.
>
>As it stands, when I call saveDocument: having set the fileName/URL
>(fileType) is correctly set as well, I get "The location of the
>document "DocumentName" cannot be determined", with Cancel and Save
>As options.
>
>I also get the disabled Save Menu that other people have reported.
>
>Any pointers on how to programmatically set the filename and save the
>file without user intervention would be great. Note that I would
>still like Save As, and Save to be operational.
I got around this problem with some, but not an overwhelming, hack of NSDocument. I think the fundamental problem is NSDocument's interpretation of fileName/setFileName:. In NSDocument's world, a file name set on a document means that the document *has* been saved to that file, not that it *should* or *will* be saved in that file. So manually setting the file name of a document sends NSDocument in to a tizzy, thinking that the document file is lost.
Looking back, I fixed the Save menu using validateMenuItem:
case MENU_SAVE_ITEM:
return ([self isDocumentEdited]);
I fixed the confusing Save dialog by overriding canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:. My replacement simply checks to see if the document has been edited and either puts up a modal sheet asking the user if they want to save their changes (no mention of a filename or where), or it just falls through and invokes the shouldClose selector with YES.
Finally, I overrode saveDocument to simply generate my internal filename and save the document. Do not call [super saveDocument:] to do the saving! NSDocument will get all confused with a file name for a document with no file.
I completely disable Save As... becuase it makes no logical sense to allow the user to specify a name for a file they can't name.
And for cosmetic reasons, I also override displayName so the window title is something other than the name of the actual file (which will make no sense to the user).
--
James Bucanek
| Related mails | Author | Date |
|---|---|---|
| James Bucanek | Jun 2, 18:56 | |
| Lon Giese | Jun 2, 22:49 | |
| Erik Buck | Jun 3, 00:49 | |
| Martin Redington | Jun 20, 05:02 | |
| James Bucanek | Jun 20, 19:40 | |
| Erik Buck | Jun 23, 00:28 |






Cocoa mail archive

