I want to present NSTextView-like context menu for a certain NSString
object (say, "text") each time -rightMouseDown
-method of my custom NSResponder
-subclass get called.
Where can I obtain these items for some NSString
?
UPD
Created NSTextView
instance and used its -menuForEvent:
-method. Some of items was disabled (like 'copy' and so on), I reset its target value to custom object with overridden selectors (like -copy:
and others).
NSTextView
is anNSView
subclass, which provides a class method+defaultMenu
. So you can ask forNSMenu * menu = [NSTextView defaultMenu];
to get your very own copy to do with as you please. You may have to walk its structure and customize individualNSMenuItem
instances to adjust their target/action but most (all?) should work just fine with nil-target (sends action to first responder) and their default action.I must admit, however, I'm not sure what you mean by "Where can I obtain these items for some
NSString
?" The context menu is opened from some UI control (like a text view) and sends its action (like-checkSpelling...
) to some target (like the first responder; which should be something like a text view, which acts as the view for a string or attributed string) to act upon.