Re: Why does menu item with shift-delete not work?

2014-01-17 Thread Andy Lee
I think the key event is getting stolen by the first responder of whatever your 
key window is at the time.  I did a quick test and found the menu item did not 
get invoked when a text view was selected but *did* get invoked when I removed 
the text view.

I suspect a more precise technical answer lies in the docs on keyboard event 
handling.  See Cocoa Event Handling Guide = The Path of Key Events, in 
particular the part about key equivalents:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/1060i-CH3-SW10

A workaround would be to subclass NSApplication and override keyDown: to detect 
Shift-Delete.  Offhand, I'd think you could do something like

- (void)keyDown:(NSEvent *)theEvent
{
if ([self isShiftDeleteEvent:theEvent]
 [[NSApp mainMenu performKeyEquivalent:theEvent])
{
return;
}

[super keyDown:theEvent];
}

But maybe someone has a better idea?

--Andy

On Jan 17, 2014, at 12:45 PM, Steve Mills smi...@makemusic.com wrote:

 We have a menu item whose key equiv is shift-delete (backspace, not forward 
 delete). Typing that key does not even call the menu's performKeyEquivalent 
 method. How can we get this to work like it should?
 
 BTW, I've already noticed that when you set the key equiv in IB, it sets it 
 to 8 (Unicode backspace), but when you type that key, the character in the 
 event is 127 (Unicode delete). Is that the problem? The OS just doesn't know 
 how to map it correctly? I had to remap 127 to 8 in our NSMenu subclass' 
 performKeyEquivalent method in order to get command-delete to work.
 
 I've also tried programmatically changing the item's key equiv from 0x08 to 
 0x7f after installing the menu and that didn't help.
 
 --
 Steve Mills



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Why does menu item with shift-delete not work?

2014-01-17 Thread Steve Mills
On Jan 17, 2014, at 13:34:08, Andy Lee ag...@mac.com wrote:

 I think the key event is getting stolen by the first responder of whatever 
 your key window is at the time.  I did a quick test and found the menu item 
 did not get invoked when a text view was selected but *did* get invoked when 
 I removed the text view.
 
 I suspect a more precise technical answer lies in the docs on keyboard event 
 handling.  See Cocoa Event Handling Guide = The Path of Key Events, in 
 particular the part about key equivalents:
 
 https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/1060i-CH3-SW10
 
 A workaround would be to subclass NSApplication and override keyDown: to 
 detect Shift-Delete.  Offhand, I'd think you could do something like

We already have a keyDown handler for the focused view, so it would be easy to 
catch it here and do the right thing. However, the menu is only alive when a 
certain tool is active, and I'd rather not muddy up all key event handling for 
this one case. We also already have install a local monitor in the app with 
addLocalMonitorForEventsMatchingMask, which handles other bugs in the Cocoa 
menu key handling, so our key events are already muddied up.

Luckily, our non-menu-key handling code was written long before we added this 
key equiv to the menu item, so it falls back to that code. It's still wrong 
that Apple menus can't handle 100% of the keys that can be set in the menu 
items. They need to seriously work on Cocoa menu item key equivs and glyph 
handling and get it back on par with the features and Carbon menus offered.

--
Steve Mills
office: 952-818-3871
home: 952-401-6255



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com