/*
* This is the implementaiton of the header file that at
* http://pastebin.com/m27607663.
*/
#import "ITToolbarDelegate.h"
/*
*
* All item identifiers are strings; we define the identfier for the search
* toolbar item as a static string for convenience.
*/
static NSString *ITToolbarSearchItemIdentifier
= @"intelliTrack.toolbar.searchItem";
@implementation ITToolbarDelegate
/* The toolbar parameter is ignored in this method, because this
* delegate is associated with just one toolbar. */
return [NSArray arrayWithObjects
: NSToolbarPrintItemIdentifier,
NSToolbarShowFontsItemIdentifier,
NSToolbarShowColorsItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
ITToolbarSearchItemIdentifier, nil];// nil is the last item as per API.
}
/* The toolbar parameter is ignored in this method, because this
* delegate is associated with just one toolbar. */
return [NSArray arrayWithObjects
:NSToolbarFlexibleSpaceItemIdentifier,
ITToolbarSearchItemIdentifier, nil];// nil is the last item as per API.
}
itemForItemIdentifier
:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag {
/*
* This method only needs to implement the logic for returning the
* item corresponding to the ITToolbarSearchItemIdentifier, because
* the other identifiers are handled by the corresponding method
* defined in NSToolbar. Note that the NSToolbar method is called
* first.
*
* This method ignores the <code>flag</code> parameter, as it does
* not affect what is returned.
*/
if ([itemIdentifier isEqual: ITToolbarSearchItemIdentifier]) {
initWithItemIdentifier:ITToolbarSearchItemIdentifier];
/* Set the required labeling information. In a production
* application, this would be externalized. */
[newToolbarItem setLabel:@"Search"];
[newToolbarItem setPaletteLabel:@"Search"];
[newToolbarItem setToolTip:@"Search for Packages"];
/* Now set the view that will represent this item, along with
* its sizing information. */
[newToolbarItem setView:searchToolbarItemView];
CGFloat height = NSHeight([searchToolbarItemView frame]);
[newToolbarItem setMinSize:NSMakeSize(100, height)];
[newToolbarItem setMaxSize:NSMakeSize(200, height)];
/* No need for autorelease, as we are using Objective-C 2.0,
* which has garbage collection. */
return newToolbarItem;
} else {
/*
* If control gets here, there is nothing to return, because
* the passed item descriptor is not supported.
*/
return nil;
}
}
@end