• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: How to enable Undo only for subgroup of managed objects?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >How to enable Undo only for subgroup of managed objects? (From: "Arthur C." <email@hidden>)

  • Prev by Date: CFZombieLevel
  • Next by Date: Re: NSViewAnimation: sliding one view down over another in a tab view
  • Previous by thread: How to enable Undo only for subgroup of managed objects?
  • Next by thread: Re: How to enable Undo only for subgroup of managed objects?
  • Index(es):
    • Date
    • Thread