Re: NSArrayController Undo
Re: NSArrayController Undo
- Subject: Re: NSArrayController Undo
- From: Richard Somers <email@hidden>
- Date: Sat, 22 May 2010 10:52:56 -0600
On May 14, 2010, at 10:25 AM, Quincey Morris wrote:
If I understand you correctly, you're on the right track -- you want
to bind the array controller's selection indexes to your data
model's selection property.
As you noted this is easy to implement but unfortunately it does not
work. The array controller's selection indexes are based on the
current arrangement of objects in the array. This arranged order not
preserved for example when a selected object is removed from the array
and then restored with a managed object context undo. So the selected
objects which are deleted are not the same as the selected objects
after an undo delete. It appears now that this solution would be
complex and difficult to implement.
Looks like I am back to trying your original suggestion as outlined
below.
On May 13, 2010, at 10:59 PM, Quincey Morris wrote:
1. You need to add a transient property for the selection to your
managed data model. (Or non-transient, if you want the selection to
persist when the document is re-opened.)
2. You need to keep track of the changes to the selection by
modifying your Core Data selection property whenever the selection
changes. However, you don't want these to be recorded as undoable
actions (most likely, although there are scenarios -- think of
Photoshop -- where selection changes are undoable), so you have to
disable the undo manager temporarily around such changes. (Don't
forget to invoke processPendingChanges before disabling the undo
manager, and again before enabling it.)
3. You can't just track the selection state at the time of the
undoable action, because the selection you ultimately want is
different depending on whether you're undoing or redoing.
(Convincing yourself that this is an issue is left as an exercise
for the reader.) I think the easiest way to do this is to create an
undo group for each action that needs to restore the selection, with
2 actions in the group: the first one changes all the non-selection
properties to their new values; the second changes the selection
property to the post-change selection. (The latter changes the
selection without disabling the undo manager, of course.) I *think*
that gives the right selection depending whether you're undoing or
redoing. (But I haven't actually tried this approach. The last time
I had to deal with this problem in a Core Data environment, I think
I did something clunkier.)
--Richard
_______________________________________________
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