• 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: Enabling undo in a CoreData app?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Enabling undo in a CoreData app?


  • Subject: Re: Enabling undo in a CoreData app?
  • From: Jim Correia <email@hidden>
  • Date: Sat, 29 Apr 2006 18:29:28 -0400

On Apr 29, 2006, at 4:05 PM, email@hidden wrote:

I have a CoreData app, and I don't want the user to be able to undo almost all actions.

Without knowing the specifics of your situation, I'd suggest that you don't do this. Having pervasive undo is generally going to lead to a better user experience.


So, during my -applicationDidFinishLaunching method, I disableUndoRegistration on my managedObjectContext.

Now, I want to add undo/redo in a couple specific situations. During one method, I am calling this:

NSUndoManager *undoManager = [[self managedObjectContext] undoManager];
[undoManager enableUndoRegistration];
[[undoManager prepareWithInvocationTarget:self] addObjects:validRemovals toCollection:collection];
(If I am not isUndoing, I call -setActionName: here with some appropriate text)
[undoManager disableUndoRegistration];


And during the -addObjects method, I am calling the compliment:


NSUndoManager *undoManager = [[self managedObjectContext] undoManager];
[undoManager enableUndoRegistration];
[[undoManager prepareWithInvocationTarget:self] removeObjects:validAdditions fromCollection:collection];
(If I am not isUndoing, I call -setActionName: here with some appropriate text)
[undoManager disableUndoRegistration];


However, my "Undo" menu item never becomes enabled. Am I being too picky about when I am enabling and disabling registration? (I briefly tried leaving undo registration turned on throughout the application, but the Undo menu item still never became available.)

There may be two problems here.

Does the window's delegate return an undo manager (the one for the managed object context) when asked?

Also, you probably don't want to be manually registering undo actions for CoreData operations. CoreData already manages undo, so let it. Normally it will process the pending changes at the end of the current iteration of the event loop. If you have special needs, you can trigger this manually by sending -processPendingChanges to the MOC.

Jim
_______________________________________________
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


  • Follow-Ups:
    • Re: Enabling undo in a CoreData app?
      • From: email@hidden
References: 
 >Enabling undo in a CoreData app? (From: email@hidden)

  • Prev by Date: Re: Distributed objects: connecting to a process running as root?
  • Next by Date: Incorrect flipping when manually drawing NSCells (was: Fwd: -isFlipped not working right when drawing IconAndTextCell to NSImage)
  • Previous by thread: Enabling undo in a CoreData app?
  • Next by thread: Re: Enabling undo in a CoreData app?
  • Index(es):
    • Date
    • Thread