On May 13, 2010, at 10:59 PM, Quincey Morris wrote:

This is a little bit harder than it seems. You certainly want to have the document undo manager keep track of the selection changes, in order to stay in sync with the really undoable changes. So:

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.)

Done. Works well.

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.)

Currently I track the selection using NSArrayController's selection methods. I have a custom view that figures out what the selection should or should not be and programatically sets the array controller's selection. It works very well and is clean with not much code. Thus pushing the selection from the view to the model is easy, just do it when the selection is pushed to the array controller.

However, pulling selection changes from the model back into the array controller appears to be challenging. It would seem like bindings could help out here somehow. NSArrayController works with bindings and so does Core Data. Why can't I simply bind the "selectionIndexes" of the array controller to the "selected" model attribute. I have tried this but I can't get the proper bound to object and key path to work. Perhaps NSArrayController is not designed to work in this fashion.

--Richard

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to