Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Undo logic location?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Undo logic location?




My App has this sort of structure:

MyDocument has-a Catalogue (my model class) which contains an NSMutableArray

MyDocument.nib contains an NSArrayController whose contentArray is bound to MyDocument.catalogue.definitionItems and an NSTableView whose content is bound to the NSArrayController.

This all works fine, but I'm not sure where to put my undo logic. At the moment I have this method in Catalogue (inspired by Hillegass):

- (void)removeObjectFromDefinitionItemsAtIndex:(int)index
{
DefinitionItem* d = [definitionItems objectAtIndex:index];
// add inverse of operation to undo stack
NSUndoManager* undo = [owner undoManager];
[[undo prepareWithInvocationTarget:self] insertObject:d inDefinitionItemsAtIndex:index];
if (![undo isUndoing])
{
[undo setActionName:@"Delete Definition Item"];
}
[owner stopObservingDefinitionItem:d];
[definitionItems removeObjectAtIndex:index];
}


and I set the owner of the Catalogue to the MyDocument instance, but I'd rather not have undo logic in my model at all.

1. Where does the undo logic belong?
2. How does wherever it goes observe the changes to the definitionItems array?


Thanks for any ideas,
  Tom


-- email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How Do I Flip An NSScrollView? (From: Dan Saul <email@hidden>)
 >Re: How Do I Flip An NSScrollView? (From: David Jeffery <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.