Hello, Michael.

Below is a snipped of code which I use to populate the "Recent Searches" 
section of a similar NSSearchField.  It works.  I modified Apple's example 
quite a bit.

As you can see, in my code, the menu item that is tagged with 
NSSearchFieldRecentsMenuItemTag has nil action and no target.  That tag makes 
it a "magic" item which tells Cocoa to put the recent items there.  So I think 
the answer to your question of why the selector of that item never gets invoked 
is that this behavior is expected.  There are actually five (5) such magic 
items with magic tags, which I've commented with  // (*).

If I remember correctly, the way the "search" happens for a recent search is 
the same as the way the search happens for a typed-in-with-keyboard search, 
which is that the search field sends its action.  I also had to subclass 
NSSearchField to get everything working.  But maybe this will get you started.


// *** Recent Searches Section

// Separator
[searchMenu insertItem:[NSMenuItem separatorItem]
               atIndex:index++];

// "Recent Searches" Title Item
title = [[BkmxBasis sharedBasis] labelRecentSearches] ;
item = [[NSMenuItem alloc] initWithTitle:title
                                  action:nil
                           keyEquivalent:@""];
[item setTag:NSSearchFieldRecentsTitleMenuItemTag]; // (*)
[searchMenu insertItem:item
               atIndex:index++];
[item release];

// "No Recent Searches"
title = [[BkmxBasis sharedBasis] labelNoRecentSearches] ;
item = [[NSMenuItem alloc] initWithTitle:title
                                  action:nil
                           keyEquivalent:@""];
[item setTag:NSSearchFieldNoRecentsMenuItemTag]; // (*)
[searchMenu insertItem:item
               atIndex:index++];
[item release];

// Placeholder for the actual Recent Searches
item = [[NSMenuItem alloc] initWithTitle:title
                                  action:nil
                           keyEquivalent:@""];
[item setTag:NSSearchFieldRecentsMenuItemTag]; //  (*)
[searchMenu insertItem:item
               atIndex:index++];
[item release];

// Separator
item = (NSMenuItem*)[NSMenuItem separatorItem];
[item setTag:NSSearchFieldRecentsTitleMenuItemTag]; //  (*)
[searchMenu insertItem:item
               atIndex:index++];

// Clear Recent Searches
title = [[BkmxBasis sharedBasis] labelClearRecentSearches] ;
item = [[NSMenuItem alloc] initWithTitle:title
                                  action:nil
                           keyEquivalent:@""];
[item setTag:NSSearchFieldClearRecentsMenuItemTag]; //  (*)
[searchMenu insertItem:item
               atIndex:index++];
[item release];




_______________________________________________

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

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

Reply via email to