Hi,

I'm having difficulty getting a NSSearchField to work properly in an NSStatusItem. What I would like to do is something similar to the spotlight status bar item and the search field that pops up.

After I create my view containing the NSSearchField and a also a simple menu in Interface Builder, I programmatically create my NSStatusItem, add a menu item for the NSSearchField to the previously created IB menu, add it to the menu item's view, and set the IB menu to become visible when the user clicks the status item.

- (void) awakeFromNib;
{
        NSStatusBar * bar = [NSStatusBar systemStatusBar];      
        statusItem = [bar statusItemWithLength:NSSquareStatusItemLength];       
        
NSString * imageName = [[NSBundle mainBundle] pathForResource:kBBStatusBarImage ofType:@"png"]; NSImage * statusBarImage = [[NSImage alloc] initWithContentsOfFile:imageName];
        [statusItem setImage:statusBarImage];
        
imageName = [[NSBundle mainBundle] pathForResource:kBBStatusBarAltImage ofType:@"png"];
        statusBarImage = [[NSImage alloc] initWithContentsOfFile:imageName];
                
        [statusItem setAlternateImage:statusBarImage];          
        [statusItem setHighlightMode:YES];
        [statusItem setEnabled:YES];
        
        searchMenuItem = [[NSMenuItem alloc] initWithTitle:@""
                                action:@selector(performSearch:) 
keyEquivalent:@""];
        [searchMenuItem setView:searchView];
        [searchMenuItem setTarget:self];
        
        [statusItemMenu insertItem:searchMenuItem atIndex:0];

        [statusItem setMenu:statusItemMenu];    
}

Since I want the app to run without a menu bar and without a doc icon, I set the Info.plist property LSUIElement to YES. When I run the program, clicking on the status item causes the menu containing the NSSearchField to display as expected, but I can't select it or enter any data in the search field. Clicking around in the search field gives me these errors in the Console:

        HIViewSetFocus() failed with error -30599

And this ominous looking piece of Console:

09-10-17 1:28:55 AM BuskBar[11794] HIToolbox: ignoring exception '_NSDisplayOperationStack window mismatch on pop' that raised inside Carbon event dispatch
(
        [...]
)

It seems the problem has something to do with the NSSearchField not being able to get focus because the NSStatusBarWindow (private class?) it seems to be associated with can't become key. Has anyone experienced this or know how to get this to work?

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