Вопрос

Why is [self undoManager] zero in a child window, in a doc-based app?

Should it not refer to the undo manager of its parent window? In the parent window, I get an actual address for the undo manager!

Это было полезно?

Решение

The undoManageris not a member of NSWindowController. This is just a NSDocument "feature".

An excerpt from the NSDocument docs : ... A document manages its window’s edited status and is set up to perform undo and redo operations. ....

Section "Subclassing NSDocument":

.... Subclasses are also responsible for the creation of the window controllers that manage document windows and for the implementation of undo and redo. ....

The code you've written won't work on other strongly typed languages because you would send a message to an object that doesn't exist. I'm pretty sure you should have a compiler warning here.

Hope this helps,

best,

Flo

Другие советы

Flo's answer was a good starting point. Some time later, it turns out that the responder chain is somehow acting up (or, it may be me :-) ).

The child window, controlled by NSWindowController, should automatically (??) have a document property so that [self document] returns the document associated with this window. It's easy to pull the Undo manager from that.

However, in my application (and in a small testing app, too) this document is not set. When I set it manually from within the document ([newWindow setDocument:self]), everything works: registering the undo/redo actions, the menu bar, etc.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top