RE: How to enable Undo only for subgroup of managed objects?
RE: How to enable Undo only for subgroup of managed objects?
- Subject: RE: How to enable Undo only for subgroup of managed objects?
- From: "Arthur C." <email@hidden>
- Date: Thu, 21 Sep 2006 16:16:19 +0200
According to the Core Data programming guide, page 57, a solution would be
as follows:
NSManagedObjectContext *moc = [[NSApp delegate] managedObjectContext];
[moc processPendingChanges]; // flush operations for which you want undos
[[moc undoManager] disableUndoRegistration];
// do things for which you don't want undo
[moc processPendingChanges]; // flush operations for which you do not want
undos
[[moc undoManager] enableUndoRegistration];
I would then put this code in the setter methods of some objects, for
example:
- (void)setName:(NSString *)value
{
NSManagedObjectContext *moc = [[NSApp delegate] managedObjectContext];
[moc processPendingChanges];
[[moc undoManager] disableUndoRegistration];
[self willChangeValueForKey: @"name"];
[self setPrimitiveValue: value forKey: @"name"];
[self didChangeValueForKey: @"name"];
[moc processPendingChanges];
[[moc undoManager] enableUndoRegistration];
}
But this does not appear to work (changes can still be undone). However when
I put the undo disable / enable code outside of the setter method, undo is
disabled as expected:
<disable undo>
[myObject setName: somevalue];
<enable undo>
Is this expected behaviour? I would rather like to have the undo
disabling/enabling inside the setter method, as that would simply lead to
less code.
Best regards,
Arthur C.
I have a Core Data application in which I would like some objects to have
an undo capability, and others not.
For example, there are some objects which the user can change (which we
want to be undo enabled), and objects that get changed as the program runs,
for example by incoming I/O, network traffic etc. (no undo wanted).
When the user tries to 'undo' some change, the latest change is undone,
regardless what type of object was changed. So this will normally be an
automatically updated object.
Question: can I disable 'undo' for a specific set of objects in a managed
object context?
A solution would be either to throw the automatically changed objects out
of the managed object context, or to create a second managed object
context.
I would like to know if there is a simpler solution, or that one of the
above is really preferred.
Best regards,
Arthur C.
_________________________________________________________________
Play online games with your friends with Messenger
http://www.join.msn.com/messenger/overview
_________________________________________________________________
FREE pop-up blocking with the new Windows Live Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden