Re: Give a menu keyboard focus – in code
Re: Give a menu keyboard focus – in code
- Subject: Re: Give a menu keyboard focus – in code
- From: Jerry Krinock <email@hidden>
- Date: Mon, 10 Oct 2011 11:10:50 -0700
On 2011 Oct 10, at 02:57, Andy Lee wrote:
> Accessorizer's "Action Menu" is a status item that provides the exact UI Jerry is talking about
Thank you, Andy.
After thinking about what Kevin Callahan has done with Accessorizer, and the suggestion by Graham and Seth, I have an answer that's even better than what I was looking for.
Like Kevin's Accessorizer, which is a utility for Xcode, my app is a bookmarking utility which, among other things, grabs sites from web browsers. Users want it to be accessible via a global keyboard shortcut while other apps are active. My original idea was to make this shortcut activate my app's Status Item or Dock Menu. But now I realize that, thanks to -[NSMenu popUpMenuPositioningItem:atLocation:inView:] which was introduced in 10.6, I don't need the damned Status Item or Dock Menu. This is great, because the same anti-mouse keyboard-aholic power users who want the global keyboard shortcuts are generally the same users that hate Status Items and hate the Dock.
So all I do is InstallApplicationEventHandler(), and RegisterEventHotKey() with the user's preferred keyboard shortcut. My handler invokes this 3-line method which is implemented in the NSMenu subclass which I use for my Status Item and Dock Menu…
- (void)popUpAnywhereMenu {
NSPoint mouseLocation = [NSEvent mouseLocation] ;
[self popUpMenuPositioningItem:[[self itemArray] objectAtIndex:0]
atLocation:mouseLocation
inView:nil] ;
}
Hit the keyboard shortcut while in any web browser, and Poof! My app's menu appears, with keyboard focus, at the current mouse location on the screen.
I'll leave my Status Item Dock Menu as a preference option for the mouse fans. But I'm also keeping my Bug 10122120 open, because it's stupid that the F8 shortcut can't access non-Apple Status Items. We can't all be as smart (or hacky as Charles suspects) as the bjango guys are.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden