Re: Search Field MenuItem Enabling
Re: Search Field MenuItem Enabling
- Subject: Re: Search Field MenuItem Enabling
- From: Scott Thompson <email@hidden>
- Date: Mon, 5 Apr 2004 07:23:03 -0500
>
Well, I am. I create a menu and set the field's template outlet to the
>
menu. I never modify the template; I only create it in the nib file
>
and connect it.
>
>
Have you had success in putting menu items in the field's menu? If so,
>
would you care to write a very small example demonstrating how?
I ran into the same problem (Search menu items not enabling properly)
the other day. As I recall what I had to do was explicitly run through
the menu items in the template and enable them after the menu was
loaded from the NIB. In my - (void) windowDidLoad method (on a
document's window controller) :
- (void)windowDidLoad
{
/* ... other stuff ... */
[self updateSearchMenu];
}
Then you need the code for updateSearchMenu which ensures the items are
checked appropriately and enabled. Note that at the end of the routine
I re-set the newly modified menu into the search field's menu template.
I think this triggers the search field to re-generate the "real" menu
with the newly enabled/checked items:
/* ---------------------------------------------------------
updateSearchMenu */
/*
Make sure the right items in the search menu that are supposed to be
checked are, in fact, checked.
*/
- (void) updateSearchMenu
{
NSMenu *searchTemplate = nil;
if(mSearchField && (searchTemplate = [[mSearchField cell]
searchMenuTemplate])) {
NSMenuItem *noSearchItem = [searchTemplate itemWithTag:
kNoSearchCriteria];
NSMenuItem *questionSearchItem = [searchTemplate itemWithTag:
kQuestionTextSearch];
NSMenuItem *alignmentSearchItem = [searchTemplate itemWithTag:
kQuestionAlignmentSearch];
if(noSearchItem && questionSearchItem && alignmentSearchItem) {
[noSearchItem setEnabled: YES];
[questionSearchItem setEnabled: YES];
[alignmentSearchItem setEnabled: YES];
[noSearchItem setState: (mSearchKind == kNoSearchCriteria ?
NSOnState : NSOffState)];
[questionSearchItem setState: (mSearchKind == kQuestionTextSearch ?
NSOnState : NSOffState)];
[alignmentSearchItem setState: (mSearchKind ==
kQuestionAlignmentSearch ? NSOnState : NSOffState)];
}
[[mSearchField cell] setSearchMenuTemplate: searchTemplate];
}
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.