Skip to content

Instantly share code, notes, and snippets.

@matthewreagan
Last active January 3, 2019 09:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewreagan/02b6fefa537d67832ff8 to your computer and use it in GitHub Desktop.
Save matthewreagan/02b6fefa537d67832ff8 to your computer and use it in GitHub Desktop.
Fixing control-click vs right-click contextual menus in NSView
override func mouseDown(theEvent: NSEvent)
{
/* Hard-coding this behavior isn't great, and shouldn't be necessary. (It should
be up to OS X to define what a contextual-menu click is/isn't, and we should
only care about vending our NSMenu via `menuForEvent:`). */
let modifierFlags = theEvent.modifierFlags;
if (modifierFlags.contains(.ControlKeyMask))
{
if let menu = self.menuForEvent(theEvent)
{
NSMenu.popUpContextMenu(menu, withEvent:theEvent, forView:self);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment