Oops. I spoke too soon.

It *seems* to work because I send a URL off to Safari (which becomes active) and then with Safari active I try clicking on the status bar item and the search field accepts focus. But if I switch to another application first, the same problem appears as before. I have to click on the status bar item twice (the popup shows up disappears and shows up again) before I can edit the search field.

???

Anyone have any ideas?

Best,
Dalmazio



On 2009-10-16, at 1:36 AM, Dalmazio Brisinda wrote:

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 (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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to