September 17, 2008

テストサンプル2
ツールバーはこんな感じか。単純なボタンを作るメソッドを用意したので1行で作れる。 NSImageの準備はちょっと行数食ってるが。

#import <SafariAddOn/SafariAddOn.h>

@implementation SAExampleOtherTest
+(BOOL)SAExtensionLoad:(id)core
{
    SAExampleTest* addon=[[SAExampleTest alloc]init];
    [core addToolbarDelegate:addon forItemIdentifier:@"my_test1"];
    return YES;
}

-(NSToolbarItem *)toolbar:(NSToolbar *)toolbar
  itemForItemIdentifier:(NSString *)itemIdentifier
  willBeInsertedIntoToolbar:(BOOL)flag
{
    static NSImage* toolbarImage=nil;
    if(toolbarImage==nil){
        NSBundle* myBundle=[NSBundle bundleForClass:[self class]];
        NSString* imgPath=[myBundle pathForResource:@"test" ofType:@"tiff"];
        toolbarImage=[[NSImage alloc]initWithContentsOfFile:imgPath];
    }
    return [SACore singleSegmentToolbarItemWithItemIdentifier:itemIdentifier
     action:@selector(toolbarAction:) target:self image:toolbarImage label:@"test"];
}
-(void)toolbarAction:(id)sender
{
    NSLog(@"toolbar clicked");
}

@end

  1. griffin-stewie reblogged this from hetima
  2. hetima posted this