Re: Correct way to have nil undo manager in Core Data document?
Re: Correct way to have nil undo manager in Core Data document?
- Subject: Re: Correct way to have nil undo manager in Core Data document?
- From: Jerry Krinock <email@hidden>
- Date: Sat, 29 Aug 2009 19:39:10 -0700
On 2009 Aug 29, at 13:41, Quincey Morris wrote:
AFAIK, the problem is that NSPersistentDocument overrides *some* of
NSDocument's undo-related methods, but not all, and calling the un-
overridden ones really messes things up -- you can end up with 2
undo managers, one in a NSDocument private instance variable that's
never used, plus the real one in the MOC.
That's another reason why I want them ^both^ to be nil.
IIRC, the correct strategy is to nil just the one in the MOC and
take your grubby fingers completely off the NSDocument so that
NSPersistentDocument can puts its own grubby fingers on it.
Yes, I tried that, but as shown in my demo, when NSPersistentDocument
sees that is MOC does not have an undo manager it sets its own, which
is not nil. This is indeed documented as noted by Ben below.
I think your third solution overrides NSPersistentDocument's
override of NSDocument's undoManager, which is probably a Bad Idea,
although it probably works fine in this case because you don't want
any undo manager at all (so you're returning what the
NSPersistentDocument override would have returned.)
Actually, the third solution is the only solution (that works).
On 2009 Aug 29, at 17:29, Ben Trumbull wrote:
You need to use the NSDocument API:
/* The document's undo manager. The default implementation of -
setUndoManager:, in addition to recording the undo manager,
registers the document as an observer of various NSUndoManager
notifications so that -updateChangeCount: is invoked as undoable
changes are made to the document. The default implementation of -
undoManager creates an undo manager if the document does not already
have one and -hasUndoManager would return YES. */
Yes, this is this header pretty much says the same thing as the
documentation in different words. I don't see in it any admonition
against overriding -undoManager to return nil as I have done. Since -
hasUndoManager is a "should not override" in NSPersistentDocument, it
looks like this is the "least unsupported" way to do it.
- (void)setHasUndoManager:(BOOL)hasUndoManager;
Yes, I've done that, set to nil.
So far it's working. I'll hang on to this thread for a few weeks and
let y'all know if anything bad happens.
Thanks!
_______________________________________________
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