• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSToolbarItem - how to have it respond to a subview?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSToolbarItem - how to have it respond to a subview?


  • Subject: NSToolbarItem - how to have it respond to a subview?
  • From: Michael Hanna <email@hidden>
  • Date: Tue, 18 Jan 2005 11:14:00 -0500

Using a lot of the code from Simple Toolbar, I've managed to create a pop-up and NSTextField in my toolbar called SearchWebViewIdentifier. Upon typing something and pressing return in the text field results in no action at all(the text simply gets highlighted). myActiveSearchItem is a IBOutlet NSToolbarItem * field declaration(initially the target is not set within IB nor is an action set in IB) in this NSDocument(this code is actually from my ToolbarDelegateCategory). Both of the NSLogs in toolbarWillAddItem report and the second one reports an address.

- (void) toolbarWillAddItem: (NSNotification *) notif {

NSLog(@"notif %@", notif);
NSToolbarItem *addedItem = [[notif userInfo] objectForKey: @"item"];
if([[addedItem itemIdentifier] isEqual: SearchWebViewIdentifier]) {
NSLog(@"isEqual: SearchWebViewIdentifier");
myActiveSearchItem = [addedItem retain];
[myActiveSearchItem setTarget: self];
[myActiveSearchItem setAction: @selector(searchUsingToolbarTextField:)];

NSLog(@"myActiveSearchItem %@", myActiveSearchItem);
}


}

- (void) searchUsingToolbarTextField:(id) sender {
// This message is sent when the user strikes return in the search field in the toolbar


NSString* searchString = [myWebSearchField stringValue]; NSLog(@"searchString", searchString);
NSBeginInformationalAlertSheet ( @"searchUsingToolbarTextField is not implemented (left as an exercise to the reader )",@"",@"",@"",myDocumentWindow,nil,nil,nil,nil,@"search string = %@", searchString);
}





My only guess is that myWebSearchField needs some sort of association with myActiveSearchItem. myWebSearchField is actually a subview of an NSView called mySearchItemView I made in IB. mySearchItemView is composed of an NSPopupButton, the NSTextField and an NSProgressIndicator. Not sure how to do this.






this is my
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag method:


NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];


if([itemIdentifier isEqual: SearchWebViewIdentifier]) {
NSMenu *submenu = nil;
NSMenuItem *submenuItem = nil, *menuFormRep = nil;
[item setLabel: @"Search Web"];
[item setPaletteLabel: @"Search Web"];
[item setToolTip: @"Search Web For Visual Cues"];
NSRect searchRect = [mySearchItemView frame];

// Use a custom view, a text field, for the search item
[item setView: mySearchItemView];
[item setMinSize:searchRect.size];
[item setMaxSize:searchRect.size];
submenu = [[[NSMenu alloc] init] autorelease];
submenuItem = [[[NSMenuItem alloc] initWithTitle: @"Search Panel" action: @selector(searchUsingSearchPanel:) keyEquivalent: @""] autorelease];
menuFormRep = [[[NSMenuItem alloc] init] autorelease];
[submenu addItem: submenuItem];
[submenuItem setTarget: self];
[menuFormRep setSubmenu: submenu];
[menuFormRep setTitle: [item label]];
[item setMenuFormRepresentation: menuFormRep];
} else {
// itemIdent refered to a toolbar item that is not provide or supported by us or cocoa
// Returning nil will inform the toolbar this kind of item is not supported
item = nil;
}
return [item autorelease];
}


other supporting methods:

- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
return [NSArray arrayWithObjects:NSToolbarSeparatorItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
SearchWebViewIdentifier, NSToolbarCustomizeToolbarItemIdentifier, nil];
}


- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
return [NSArray arrayWithObjects:NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier, SearchWebViewIdentifier, nil];
}


regards,
Michael

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: NSNumberFormatter and space as a thousands separator
  • Next by Date: Pasting complex text into NSSearchField
  • Previous by thread: Re: NSNumberFormatter and space as a thousands separator
  • Next by thread: Pasting complex text into NSSearchField
  • Index(es):
    • Date
    • Thread