Re: Status Bar Search Field Can't Get Focus w/ LSUIElement PList Setting
Re: Status Bar Search Field Can't Get Focus w/ LSUIElement PList Setting
- Subject: Re: Status Bar Search Field Can't Get Focus w/ LSUIElement PList Setting
- From: Dalmazio Brisinda <email@hidden>
- Date: Fri, 16 Oct 2009 01:36:59 -0600
In case anyone that is interested, I've solved this problem. Here's how:
In the -awakeFromNib method, add the following two lines (where
statusItem is an NSStatusItem *):
[statusItem setAction:@selector(statusItemClicked:)];
[statusItem setTarget:self];
and make sure to comment the line:
// [statusItem setMenu:statusItemMenu]; <-- comment so your click
selection method is invoked instead
Now in the custom selection method -statusItemClicked: do the
following (where statusItemMenu is an NSMenu *):
// Show the popup menu associated with the status item.
[statusItem popUpStatusItemMenu:statusItemMenu];
// *** Must activate *after* showing the popup menu to obtain focus
for the search field. ***
[NSApp activateIgnoringOtherApps:YES];
And that's it.
The problem I was having was placing the -activateIgnoringOtherApps:
before popping up the status item menu. If you place it before
popping up the menu it will only work the first time (from xcode)
because it auto-activates. But the app needs to be activated after the
menu is popped up in order for the search field to receive focus.
Oh, and make sure LSUIElement is set in the Info.plist file.
Best,
Dalmazio
On 2009-10-15, at 5:19 PM, Dalmazio Brisinda wrote:
I'm having a problem getting a NSSearchField to work properly in an
NSStatusItem a la the Apple Help menu or the Apple Spotlight menu.
Here's what's happening.
I create my custom NSStatusItem / menu / custom view/ search field,
and insert into into the status bar in -awakeFromNib. Setting the
LSUIElement property in the Info.plist file then results in
everything displaying and working correctly the very first time the
NSStatusItem is clicked (after running the application from Xcode
and it becomes "active"). The associated menu pops up with the
custom view and search field, the search field has focus, shows the
insertion pointer, and I can type a search term, press enter, and
everything works great. But if I select the NSStatusItem a second
time to perform a second search there is no insertion pointer, and I
can't select the search field. When I try clicking around the custom
view several times I get the following error:
HIViewSetFocus() failed with error -30599
Now, if I don't set the LSUIElement property in the Info.plist file,
and just run the application as a normal application, then I can get
around the above problem by selecting the application first (making
it active) and then the search field in the menu associated with the
NSStatusItem always gets focus, the insertion pointer appears, and
everything works fine. But I want to build an application that
doesn't have a doc icon, window, or main menu using the LSUIElement
property setting.
From what I understand, it seems that the application needs to be
"active" in order for the search field to get focus and for the text
insertion pointer to appear, but I don't understand how to "force"
this for an application that doesn't have a main window, doc icon,
or menu bar by enabling LSUElement.
Can anyone help?
Best,
Dalmazio
_______________________________________________
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