Re: Undo's setActionName: and Core Data
Re: Undo's setActionName: and Core Data
- Subject: Re: Undo's setActionName: and Core Data
- From: Graham Cox <email@hidden>
- Date: Wed, 12 Aug 2009 11:07:00 +1000
On 12/08/2009, at 4:32 AM, Squ Aire wrote:
The question is: How can I set the name of the undo action to
"Modify Name" using setActionName of the MOC's undo manager just
before the user changes an employee's name in the table view (or by
any other means)?
Do I have to subclass the MO and override the accessor methods?
Sounds like an inefficient way just to get undo action names looking
good... any other ways?
Not sure this is much help, since I realise you're talking about a MO
context and I'm generalising, but..
You don't set an Undo Action name *before* changing anything. Usually,
setting the name is the very last thing you do, and it should be done
at the highest level that you can for the trigger of the change. In
the target/action model, I usually set the action name as the last
step in my IBAction methods, even though what is actually undone was
set up deep down inside my data model. This reflects MVC usage where
the data model change is what to undo, but the action name is the
user's 'view' of what to undo. This also means that if the action
involves a number of data model changes, each of which is individually
undoable, the action name reflects the overall undo operation (group).
Another benefit is that sometimes different operations might be
factored, say actions A, B and C, where C invokes A AND B, but A and B
are in themselves legitimate undoable operations that set an action
name. When C sets the action name it just overwrites whatever A and B
might have set (a concrete example is Cut, which can typically be
implemented in terms of a Copy + Delete, each of which are legitimate
operations in their own right).
So, in short, the approach is: make one or more changes, then name the
changes.
So in the case of changing things from a table, let the table make the
change, and set the action name last just before you return to the
table. In the data source model, this is easy, maybe less so in the
bound-to-core data model, but you could mix datasource and bindings,
and set the action name in the -
tableView:setObjectValue:forTableColumn:row: method. Another way might
be to listen for a KVO notification of the change and set the action
name there.
--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