Re: Undo Names in NSPersistentDocument
Re: Undo Names in NSPersistentDocument
- Subject: Re: Undo Names in NSPersistentDocument
- From: Graham Cox <email@hidden>
- Date: Sat, 19 Dec 2009 15:39:30 +1100
On 19/12/2009, at 12:08 PM, Gerriet M. Denkmann wrote:
> How would I do this?
> Subclass the NSArrayControllers and overrriding add: and remove: to call setActionName:?
> Or is there a simpler way?
My take on this is this: The action name is part of the View layer (because it appears in the menu) but the add/remove are themselves part of the data model. So the action name is best set also by the controller that triggers the add/remove events in the data model.
The typical pattern I use is this:
- (IBAction) someAction:(id) sender
{
[myDataModel doSomethingUndoable]; // calls through to data model's -add: method which registers -remove: with the undo manager
[[self undoManager] setActionName:[sender title]];
}
This assumes that the sender has a title that is useful as an action name (a menu item, say) - if not just set it using NSLocalizedString().
Once a given undo group has an action name, that action name will "stick to" that group for future undos and redos without you having to set it up again - in fact you really don't want to change it during an undo or a redo, though you can if you want.
So that's nice and straightforward with target/action, but with Bindings, maybe less so. You could subclass the controller but another way might be to observe changes purely for the purpose of registering a relevant action name, which would avoid that. I've done this by getting my observable data model classes to export an undo description string for each property that can be changed, so they supply something appropriate and localised.
Unfortunately I haven't used Core Data so I'm not sure what's needed to fit in with that, if the framework hasn't already solved it.
--Graham
_______________________________________________
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