On Oct 6, 2011, at 1:14 AM, Richard Somers wrote:

> It is very common for Applications to update the selection during undo 
> operations.
> 
> By default NSArrayController automatically selects objects as they are 
> inserted. This works if objects are added using one of the controller's add 
> or insert methods. If objects are added directly to the controller content 
> object using other means then this mechanism does not work.
> 
> Take for example a NSArrayController with a managed object context for the 
> content. If one or more objects are added to managed object context as the 
> result of an undo, the controller's selection does not change or update.
> 
> Is there an easy way to set the controller's selection when an undo operation 
> adds objects back into a managed object context?

AFAIK you will need to manage selection restoration semantics yourself, and it 
may not be easy and it may be fragile. Note also that the preserve and avoid 
empty selection settings will also have an effect. That being said, the 
approach would be--before adding/deleting outside the controller--to grab the 
managed object context's undo manager, open an undo group, add selection 
restoration operations, perform the operation, then close the group. This 
should cause the undo to restore selection. Of course, this is theory, as I 
haven't had to actually do it, and more experienced Core Data wranglers may 
have more to add.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to