Search code examples
objective-cmacoscocoansundomanager

NSUndoManager in Document based Application wrong behaviour


In my document based app I call prepareWithInvocationTarget and registerUndoWithTarget for [self undoManager]. However, in Edit menu, Undo & Redo are still blank. I can execute undo manually by calling [[self undoManager] undo] and it works.

Just to make sure, I created a new project, called in it prepareWithInvocationTarget and registerUndoWithTarget. Magic! Undo/Redo elements in Edit menu could be clicked now.

What could be a possible reason for this? I tried checking connections in interface builder but they are the same as in the new project I created. Any idea how to fix it?


Solution

  • Ok, I've got it worked out.

    The issue was that I had a document based project and in my document delegate I callsed [self undoManager]. I was supposed to call it on the main window instead. I've chcanged it to [mProjectWindow undoManager] (because mProjectWindow points to the main window of the document) and now eveyrthing works fine.