Browse files

Explains why we need to ignore control-mouse-down events in -mouseDow…

…n: due to -menuForEvent: returning nil when we present a custom contextual menu
  • Loading branch information...
1 parent b22874f commit 61e1e6ee5d12b139866652016b3a0e3b9c07ad37 @bavarious bavarious committed Mar 8, 2013
Showing with 8 additions and 1 deletion.
  1. +3 −0 OpenEmu/OEGridView.m
  2. +5 −1 OpenEmu/OETableView.m
View
3 OpenEmu/OEGridView.m
@@ -831,6 +831,9 @@ - (OEGridLayer *)OE_gridLayerForPoint:(const NSPoint)point
- (void)mouseDown:(NSEvent *)theEvent
{
+ // AppKit posts a control-mouse-down event when the user control-clicks the view and -menuForEvent: returns nil
+ // since a nil return normally means there is no contextual menu.
+ // However, we do show a menu before returning nil from -menuForEvent:, so we need to ignore control-mouse-down events.
if([theEvent modifierFlags] & NSControlKeyMask) return;
const NSPoint pointInView = [self OE_pointInViewFromEvent:theEvent];
View
6 OpenEmu/OETableView.m
@@ -258,6 +258,7 @@ - (NSMenu *)menuForEvent:(NSEvent *)theEvent
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedInteger:style] forKey:OEMenuOptionsStyleKey];
[OEMenu openMenu:contextMenu withEvent:theEvent forView:self options:options];
+ return nil;
}
return [super menuForEvent:theEvent];
@@ -273,7 +274,10 @@ - (void)keyDown:(NSEvent *)theEvent
- (void)mouseDown:(NSEvent *)theEvent
{
- if(!(theEvent.modifierFlags & NSControlKeyMask))
+ // AppKit posts a control-mouse-down event when the user control-clicks the view and -menuForEvent: returns nil
+ // since a nil return normally means there is no contextual menu.
+ // However, we do show a menu before returning nil from -menuForEvent:, so we need to ignore control-mouse-down events.
+ if(!([theEvent modifierFlags] & NSControlKeyMask))
[super mouseDown:theEvent];
}

0 comments on commit 61e1e6e

Please sign in to comment.