Hi guys,
I have a NSSearchField which has a menu attached to it. I attach the menu via this code:
- (void)setupSearchBar
{
NSMenu *cellMenu = [[[NSMenu alloc] initWithTitle:@"Search Menu"] autorelease];
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"PHP.Net Manual" action:@selector(setPHP:) keyEquivalent:@""];
NSMenuItem *item2 = [[NSMenuItem alloc] initWithTitle:@"MySQL Manual" action:@selector(setMySQL:) keyEquivalent:@""];
id searchCell = [searchBar cell];
[cellMenu insertItem:item atIndex:0];
[cellMenu insertItem:item2 atIndex:1];
[item release];
[item2 release];
[searchCell setSearchMenuTemplate:cellMenu];
}
Now, the menu is attached fine, but the menu items are not enabled, they are just grey. I had a look in Apple's docs and this is how they do it too. In case its needed, here are the methods I use (setPHP and setMySQL):
- (void)setPHP:(id)sender
{
id searchBarCell = [searchBar cell];
[searchBarCell setPlaceholderString:@"PHP.Net Manual"];
[phpMenuItem setState:NSOnState];
[sqlMenuItem setState:NSOffState];
[[NSUserDefaults standardUserDefaults] setObject:@"PHP.Net Manual" forKey:@"HelpSearchMode"];
}
- (void)setMySQL:(id)sender
{
id searchBarCell = [searchBar cell];
[searchBarCell setPlaceholderString:@"MySQL Manual"];
[sqlMenuItem setState:NSOnState];
[phpMenuItem setState:NSOffState];
[[NSUserDefaults standardUserDefaults] setObject:@"MySQL Manual" forKey:@"HelpSearchMode"];
}
Now, you would have thought that it would have worked, but it won't! I had a look in the cocoa-dev archives, and someone else had a similar problem but got no reply.
Any ideas?
Thanks,
Oliver