views:

17

answers:

1

I have a simple document-based application that simply creates a custom XML file. It uses an Outline View to navigate the XML document. When an item in the Outline View is selected a custom view is displayed as a sub view of the document view that allows the user to enter in data. On one of the views has a NSTextField. It has its "Allows Undo" flag set. I tested to ensure the undoManager is called on the NSDocument when the editing is completed. So the control seems to be bouncing through the First Responder as it should.

In the IBAction I use the ActionName so it will display correctly in the menu. Now here is the problem. Not only is the ActionName not displayed in the menu, but clicking undo doesn't reverse the action taken on the NSTextField but the action registered just before it. Is there something I overlooked when setting up undo with NSTextField?

(IBAction)textFieldChanged:(id)sender{

...some code here...

[[self undoManager]setActionName:@"Change Text"];

}

Thanks in advance, Rob

A: 

Is the text field in the same window as your outline view (ie, the document's main window)? If not, you'll need to set a delegate for that extra window and respond to -windowWillReturnUndoManager: by returning the document's undo manager.

Because you're saying -undoManager is being called against your document, I'm guessing the above isn't the case. I've never known a text field not to use the document's undo manager when it's in the document's main window and Allows Undo is checked. Have you tried something as simple as deleting the field and recreating it? Sometimes IB does some strange stuff ... funny enough, these problems tend to crop up when undoing/redoing changes in Interface Builder itself. :-)

Joshua Nozzi
The text field and the outline view are in the same window but on different sides of a split view. Deleting and replacing the text field didn't work. Do you know if the undo manager is called before the IBAction is called on a text field?
Rob
I finally got it working. I had to turn off the "Allows Undo" in IB and then use the delegate "- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor" and call the registerUndoWithTarget command directly.
Rob