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: Quincey Morris <email@hidden>
- Date: Sat, 29 Aug 2009 13:41:18 -0700
On Aug 29, 2009, at 13:01, Jerry Krinock wrote:
Apparently when -[NSDocument undoManager] sees that its undo manager
is nil (because I set it to nil), it says to itself, "Golly, we need
an undo manager here. So it creates one, sets it in the subclass -
[NSPersistentDocument setUndoManager:], which in turn says, "Gee,
our moc needs this too", and then invokes -[NSManagedObjectContext
setUndoManager:].
The obvious solution would be to add to the init method:
[self setHasUndoManager:nil] ;
which would probably work for NSDocument but for
NSPersistentDocument, the documentation says:
"Overridden to be a no-op ... You should not override this method.
The persistent document uses the managed object context’s undo
manager."
Overriding -hasUndoManager didn't work either. It's never invoked.
However, my third guess seems to be working. In the MyDocument
implementation I overrode...
- (NSUndoManager*)undoManager {
return nil ;
}
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.
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.
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.)
_______________________________________________
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