For the More Curious: Windows and the Undo Manager

A view can add inverse actions for its edits to the undo manager. NSTextView, for example, can put the undo action for each edit that the user makes to the text onto the undo manager. How does the text view know which undo manager to use? First, it asks its delegate. NSTextView delegates can implement this method:

o​p​t​i​o​n​a​l​ ​f​u​n​c​ ​u​n​d​o​M​a​n​a​g​e​r​F​o​r​T​e​x​t​V​i​e​w​(​v​i​e​w​:​ ​N​S​T​e​x​t​V​i​e​w​!​)​ ​-​>​ ​N​S​U​n​d​o​M​a​n​a​g​e​r​?​

Next, it asks its window. NSWindow inherits a property for this purpose from NSResponder:

v​a​r​ ​u​n​d​o​M​a​n​a​g​e​r​:​ ​N​S​U​n​d​o​M​a​n​a​g​e​r​?​ ​{​ ​g​e​t​ ​}​

The window’s delegate can supply an undo manager for the ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.