Nicolas Miari
Nicolas Miari

Reputation: 16256

Get the Location of Right Click Event on Context Menu Action

My custom NSView subclass overrides menu(for:) in order to display a context menu on right click (ctrl-click).

I created a menu item with appropriate target/action, and added it to the menu.

I want to instantiate a subview and place it at the location in which the right click originally occurred; However, it isn't clear how to obtain the location of the original click event that causes the menu to be displayed.

The sender argument of the action method gets the NSMenuItem instance, but this does not seem to have any property to determine its position on screen (or its superview).

How can I determine the location of the initial right click event?

Upvotes: 0

Views: 475

Answers (1)

Willeke
Willeke

Reputation: 15633

You have to store (the location of) the event passed to menu(for:) somewhere. You can use the representedObject of the menu item.

Upvotes: 1

Related Questions