Ira Klein
Ira Klein

Reputation: 425

Undo/Redo Menu Items not working with Document based app OSX 10.7

I've created a very simple test Document based application with Core Data. I did no coding, just wired it up. The XIB file has one array controller, one table view and two buttons, one to add a row and one to delete. The array controller is binded the Files Owner's managedObjectContext. The columns of the table are bound to the three entities defined in the model. The buttons are wired to the array controllers Add and Remove actions. That's it. The application works fine, but the menu items for Undo and Redo stay disabled after you add or remove rows. Is there something you have to do to enable undo/redo functionality at this level?

Upvotes: 0

Views: 1137

Answers (2)

pickwick
pickwick

Reputation: 3154

If a menu item is disabled, that means there is nothing in the responder chain that responds to the message it's sending. In this case, it likely means that your window is not returning the undoManager. You need to have something like this in your window controller:

- (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)sender
{
    return [self.managedObjectContext undoManager];
}

Upvotes: 0

ipmcc
ipmcc

Reputation: 29906

I think the problem here may be related to this:

The columns of the table are bound to the three entities defined in the model.

I'm not even sure how you would do that (bind different columns to different entities.) I'm wondering if you mean "three properties defined on one entity in the model," but I'm not sure.

Regardless, I replicated something like your setup: a simple entity Person with one string property name, an NSArrayController, in entity mode, bound to the (File's Owner, , managedObjectContext), an NSTableView with one column, bound to (Array Controller, managedObjects, name) and everything works great, including Undo and Redo.

I'd recommend starting from that simple point (one entity, one property, one column, everything works) and adding complexity/features one little thing at a time until something breaks -- when it breaks, you'll know exactly what broke it. Luckily, you're starting from boilerplate, so there's not a lot of extra app logic getting in the way.

Upvotes: 1

Related Questions