Share Pastebin
Guest
Public paste!

Matt

By: a guest | Aug 4th, 2009 | Syntax: Objective C | Size: 3.16 KB | Hits: 36 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. /*
  2.  * This is the implementation of the header file that at
  3.  * http://pastebin.com/m27607663.
  4.  */
  5.  
  6. #import "ITToolbarDelegate.h"
  7.  
  8. /*
  9.  * All item identifiers are strings; we define the identifier for the search
  10.  * toolbar item as a static string for convenience.
  11.  */
  12. static NSString *ITToolbarSearchItemIdentifier = @"intelliTrack.toolbar.searchItem";
  13.  
  14. @implementation ITToolbarDelegate
  15.  
  16. - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
  17.     /* The toolbar parameter is ignored in this method, because this
  18.      * delegate is associated with just one toolbar. */
  19.     return [NSArray arrayWithObjects: NSToolbarPrintItemIdentifier,
  20.             NSToolbarShowFontsItemIdentifier,
  21.             NSToolbarShowColorsItemIdentifier,
  22.             NSToolbarSpaceItemIdentifier,
  23.             NSToolbarFlexibleSpaceItemIdentifier,
  24.             NSToolbarSeparatorItemIdentifier,
  25.             NSToolbarCustomizeToolbarItemIdentifier,
  26.             ITToolbarSearchItemIdentifier, nil];// nil is the last item as per API.
  27. }
  28.  
  29. - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
  30.     /* The toolbar parameter is ignored in this method, because this
  31.      * delegate is associated with just one toolbar. */
  32.     return [NSArray arrayWithObjects:NSToolbarFlexibleSpaceItemIdentifier,
  33.             ITToolbarSearchItemIdentifier, nil];// nil is the last item as per API.
  34. }
  35.  
  36. - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
  37.      itemForItemIdentifier:(NSString *)itemIdentifier
  38.  willBeInsertedIntoToolbar:(BOOL)flag {
  39.     /*
  40.      * This method only needs to implement the logic for returning the
  41.      * item corresponding to the ITToolbarSearchItemIdentifier, because
  42.      * the other identifiers are handled by the corresponding method
  43.      * defined in NSToolbar. Note that the NSToolbar method is called
  44.      * first.
  45.      *
  46.      * This method ignores the <code>flag</code> parameter, as it does
  47.      * not affect what is returned.
  48.      */
  49.     if ([itemIdentifier isEqual: ITToolbarSearchItemIdentifier]) {
  50.         NSToolbarItem *newToolbarItem = [[NSToolbarItem alloc]
  51.                                          initWithItemIdentifier:ITToolbarSearchItemIdentifier];
  52.        
  53.         /* Set the required labeling information. In a production
  54.          * application, this would be externalized. */
  55.         [newToolbarItem setLabel:@"Search"];
  56.         [newToolbarItem setPaletteLabel:@"Search"];
  57.         [newToolbarItem setToolTip:@"Search for Packages"];
  58.        
  59.         /* Now set the view that will represent this item, along with
  60.          * its sizing information. */
  61.         [newToolbarItem setView:searchToolbarItemView];
  62.         CGFloat height = NSHeight([searchToolbarItemView frame]);
  63.         [newToolbarItem setMinSize:NSMakeSize(100, height)];
  64.         [newToolbarItem setMaxSize:NSMakeSize(200, height)];
  65.  
  66.        
  67.         /* No need for autorelease, as we are using Objective-C 2.0,
  68.          * which has garbage collection. */
  69.         return newToolbarItem;
  70.     } else {
  71.         /*
  72.          * If control gets here, there is nothing to return, because
  73.          * the passed item descriptor is not supported.
  74.          */
  75.         return nil;
  76.     }
  77. }
  78.  
  79. @end