Share Pastebin
Guest
Public paste!

nomothetis

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