Re: Undo with NSArrayController
Re: Undo with NSArrayController
- Subject: Re: Undo with NSArrayController
- From: Kevin Bracey <email@hidden>
- Date: Thu, 27 Jan 2011 16:44:21 +1300
Hi Quincey, Thanks for your help!
Sorry, my description wasn't full enough.
This is not Core Data.
MyDocument has the NSMutableArray *allImportHeaders, MyDocument has the KVC insert and remove messages for this.
I have an NSArrayController bound to allImportHeaders for it's content .
The NSTableView Columns bound to the NSArrayController arrangedObject.xxFieldNames.
I found that sending the NSArrayController a rearrangeObjects fixes this problem.
I'm now studying the iSpend example and I see a couple of things:
1. It only implements - (void)insertTransactions:(NSArray *)objects atIndexes:(NSIndexSet *)indexes and - (void)removeTransactionsAtIndexes:(NSIndexSet *)indexes not the other KVO messages. I wonder why it doesn't do the rest.
2. It uses KVO to listen to those and does the setting of Undo of the Insert and Remove there.
3. The SubClass of NSArrayController is also Listening for its @"contentArray" to change and is sending it's self a rearrangeObjects if it does.
4. To Implement Undo in the Model object Transaction, they pass in the Document to all the Transaction objects so it can access the UndoManager, seems a bit anti MVC.
thanks
Kevin
On 27/01/2011, at 3:49 PM, Quincey Morris wrote:
> On Jan 26, 2011, at 17:55, Kevin Bracey wrote:
>
>> I'm trying to patch in Undo and Redo to a NSTableView > NSArrayController > -( void )insertObject:( id )object inAllImportHeadersAtIndex:( NSInteger )index and -( void )removeObjectfromAllImportHeadersAtIndex:( NSInteger )index, using the example from Cocoa® Programming for Mac® OS X, Third Edition.
>>
>> The Undo and Redo are working BUT (and we like big buts)
>> After Undoing an Insert the Object is deleted as expected from vanishes TableView as expected but there is a Ghost blank entry in the TableView as if the NSArrayController is aware of the change.
>> So, Add, Add, Add, Undo, Undo, Undo leaves me with 3 Ghost lines in the TableView. It seems that -( NSInteger )countOfAllImportHeaders is not being called.
>
> Hmm, maybe I've spaced out here, but this doesn't look right to me.
>
> What class is 'insertObject:inAllImportHeadersAtIndex:' implemented in? Surely not a subclass of NSArrayController? That's how I first read your description, but I see now that's possibly not what you meant. Is "allImportHeaders" a non-Core Data property of a managed object subclass? Is that where the accessors are?
>
> Why are accessors ('insertObject:inAllImportHeadersAtIndex:') handling undo? They're typically called on both undo and redo, which makes messing with undo hard if you try inside them. If you're handling undo yourself, how are you preventing unwanted interactions with Core Data undo of Core Data properties, which is "automatic"?
>
> So it looks like you're messing with undo, with Core Data, and with the MVC paradigm in ways that are essentially guaranteed to fail. Or maybe I misunderstand your description.
>
_______________________________________________
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