Re: Preserving undo actions on deleted targets
Re: Preserving undo actions on deleted targets
- Subject: Re: Preserving undo actions on deleted targets
- From: Keary Suska <email@hidden>
- Date: Wed, 29 Jan 2014 09:07:52 -0700
On Jan 29, 2014, at 8:30 AM, Matthew LeRoy wrote:
> I *think* the right approach here is to not delete/dealloc the model objects when their corresponding records are removed/deleted, but instead just remove the objects from the collection of “live” objects and hold onto them somewhere else for the purposes of re-inserting them in the collection if the deletion is undone. I suppose my model code for deleting a record from the live collection should register an undo action which calls “undelete” or “insert”; and the code for “undelete” or “insert” (and probably “add” as well) should register an undo action which calls “delete”?
Well, if you want the "delete" action to be undoable, then yes, you would register an undo action for it. As the object of an action the "deleted" object should be retained by NSUndoManager, so you don't have to track it yourself.
> I also shouldn’t call removeAllActionsWithTarget:modelObject, because there’s no way to re-insert those actions back into the undo stack if the deletion is undone and the model object is re-inserted back into the “live” collection. Instead, I just have to trust that the only way for the undo actions which target the “deleted” model object to get sent is for the undo action which undeletes the object to be sent first (because it is higher on the undo stack), thus putting the object back into the live collection. I don’t need to worry about undo actions getting sent to deallocated objects, because the objects aren’t getting deallocated.
Yes. In my experience, manipulating NSUndoManager's stack is an exercise in frustration, as NSUndoManager's gets itself into an inconsistent state. IMHO this is largely due to the opacity of the class, and the near complete lack of introspection available.
For completeness I would add that I find it best that each root object in your data hierarchy have its own undo manager that it disposes of when the object deallocates. This is, for instance, how the document architecture handles it.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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