How to defer NSDocument:writeToFile:ofType ?
How to defer NSDocument:writeToFile:ofType ?
- Subject: How to defer NSDocument:writeToFile:ofType ?
- From: Manfred Lippert <email@hidden>
- Date: Fri, 25 Jan 2002 19:19:57 +0100
Hi,
I have a "Multiple Document" based application. Now I have a very specific
need: I want to display a sheet to ask for some text (think of a password)
before the document actually will be saved.
For this purpose I tried to "defer" the writeToFile:ofType method. My
version of this method stores the parameters (filename and type), begins the
sheet ([NSApp beginSheet ...]) and returns NO, because sheets are
asynchronously running. After the sheet is finished, I tried to call [super
writeToFile:ofType] with the same parameters I got in the original call to
finish/redo the write operation.
Bad thing - it doesn't work. :-(
Two problems:
- It always "beeps" because my writeToFile method returns NO. But I cannot
return YES, because if NSApplication tries to save my document in a case of
"Quit" it will think it is saved correctly and will quit my application
before the sheet is handled.
- The deferred [super writeToFile:ofType] call doesn't write anything. No
file is created. If I do not defer it, it works.
I made the same thing with the readFromFile method and there it works
(Window opens, sheet is shown, after the sheet the document loads and shows
its contents in the window). But I could not begin the sheet directly in the
readFromFile method, but it works if I begin it in an overridden version of
"showWindows". Don't know if this is "perfect" but it works, and I always
have only one window per document.
So: A deferred "readFromFile" is working great here, but I cannot defer
"writeToFile".
Any ideas how this can be done?
Mani