On Jul 23, 2012, at 10:51 AM, Markus Spoettl <[email protected]> wrote:

> On 7/23/12 6:22 PM, Kyle Sluder wrote:
>> I don't have my crazy autosave flowchart handy, but I *think* you should be
>> able to simply override -hasUnautosavedChanges to return YES if either super
>> returns YES or if your preferences file needs to be saved.
>> -autosaveWithImplicitCancellability:: is documented to check
>> -hasUnautosavedChanges, so I would assume that it is called unconditionally
>> at all places where AppKit wants to ensure the document is written to disk if
>> necessary.
>> 
>> Of course, this assumes you are returning YES from +autosavesInPlace.
> 

-autosaveWithImplicitCancellability: does check -hasUnautosavedChanges, but the 
quit procedure doesn't—it actually checks -isDocumentEdited. And when 
autosavesInPlace returns NO, overriding -isDocumentEdited to return YES will 
still result in the dirty dot in the close button, unless you go to great 
lengths to prevent the state from bubbling up to -[NSWindow setDocumentEdited:].

> If there would be a way to tell NSDocument to forgo asking whether to save a 
> document if -isDocumentEdited returned YES, and instead just save it, that 
> would be a solution. All I want is a silent save, when only preferences need 
> to be saved (since I'm using file wrappers it would be quick too because I'm 
> only replacing the wrapper for my preferences).
> 
> I don't see how I could do that. Is there a way?

You're talking about the "Do you want to save changes to this document" dialog 
when clicking the close button or quitting? The only way to bypass that is to 
override canCloseDocumentWithDelegate:… check for your special 
"-isDocumentEdited==YES, but don't show a panel" case, and invoke the 
shouldCloseSelector (after writing the preferences file) without calling super.


But really, if you and other developers feel there is a need for functionality 
to mark a document as needing saving, but without ever informing the user about 
it or giving them a chance to cancel it, then file an enhancement request for 
such an API.

-KP


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to