On May 15, 2009, at 08:01, McLaughlin, Michael P. wrote:

In a Cocoa Document project (latest Xcode), I want to have only one document
open at a time.  I thought that I could do this by subclassing
NSDocumentController but I have been only partially successful.

...

There must be an easy way to do all of this. Could someone point me to a
code example somewhere?  Or a good description?

If you mean exactly what you say, then I'd suggest that trying to enforce your restriction by disabling menu items is doomed to failure. There are plenty of ways that a NSDocumentController method can be called to open a document that *don't* involve a menu or even an IBAction method.

A better approach would be for your NSDocument subclass instances to check, in initWithType: or one of the ReadFrom... methods, if a document already exists (via [NSDocumentController documents]), and simply return an error if so. [Actually, since NSDocumentController has lousy error reporting, you should report the error yourself with something like [NSApp presentError:] and return a "user cancelled" error to suppress the standard NSDocumentController complaint.]

In that case, there's really no need to mess with the menus at all. As you've already seen, the mechanism for handling the Open Recent submenu is private, so there's nothing there to rely on. (If you're determined to do that, you could get the same effect by disabling the Open Recent menu item itself.)


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to