Search code examples
cocoaosx-mountain-lionnstextfieldnstextview

How to access application's shared NSTextView


I want to add a menu item to all text field's contextual menu. I can do it if I get a hold of the internal field editor of type NSTextView used by all NSTextField's through out the application. The thing is the only way I can think of getting it, is by accessing it from [window firstResponder]. Does anyone know another way ?


Solution

  • One more method that I can think of is subclassing the NSTextField to extend its behaviour by overriding the menuForEvent method.

    Finally return an instance of the custom field editor using windowWillReturnFieldEditor method in the window delegate.