Locking an NSDocument
Locking an NSDocument
- Subject: Locking an NSDocument
- From: Kyle Sluder <email@hidden>
- Date: Fri, 09 Sep 2011 15:05:57 -0700
Hi all,
If you adopt the new +autosavesInPlace feature on Lion, documents that
haven't been opened in a while will get a "Locked" message in the
titlebar, which the user can override by clicking and choosing
"Unlock," or by attempting to make a change to the document and
choosing "Unlock" from the resulting sheet.
I'm trying to force a document to open as locked. The use case is for
upgrading documents from our previous file format. In the past, if the
user tried to open an old file, we'd upgrade the document, place the
new version alongside the old version, and open the new version. We
can't do that in the new sandboxing world. So we thought we would open
the old version Locked, and if the user tried to make a change we'd
present a sheet saying the document was locked because it was in an
older file format; the sheet would contain a "Duplicate and Upgrade"
button.
Unfortunately, it doesn't look like there's any public API to force a
document to be locked. The closest I've come is -[NSDocument
checkAutosavingSafetyAndReturnError:], but it doesn't seem to be
called at all the times I'd expect it to be called (for example, a new
document), and returning NO doesn't put the Locked text in the
titlebar; it just prohibits the user from making any changes without
duplicating. Likewise, returning YES from -isInViewingMode just makes
it impossible to make any changes to the document.
We already support the notion of "read-only documents" in this
application, and it would be a shame to reimplement something similar
to NSDocument's concept of locked documents, especially if the two
fight with each other. Is there any way to hook into the "locked
documents" machinery?
Thanks,
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden