Skip to content

Instantly share code, notes, and snippets.

Created October 22, 2008 04:55
Show Gist options
  • Save anonymous/18544 to your computer and use it in GitHub Desktop.
Save anonymous/18544 to your computer and use it in GitHub Desktop.
import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
var theWindow;
var toolbar;
var helperObject;
var inputField;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
helperObject = [[HelperObject alloc] init];
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[label setStringValue:@"Hello World!"];
[label setFont:[CPFont boldSystemFontOfSize:24.0]];
[label sizeToFit];
[label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[label setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds]) - CGRectGetWidth([label frame])) / 2.0, (CGRectGetHeight([contentView bounds]) - CGRectGetHeight([label frame])) / 2.0)];
[contentView addSubview:label];
toolbar = [[CPToolbar alloc] initWithIdentifier:@"EditingToolbar"];
[toolbar setDelegate:self];
[theWindow setToolbar:toolbar];
[theWindow orderFront:self];
}
- (CPArray)toolbarDefaultItemIdentifiers:(CPToolbar)aToolbar
{
return ["FOO"];
}
- (CPArray)toolbarAllowedItemIdentifiers:(CPToolbar)aToolbar
{
return ["FOO"];
}
- (CPToolbarItem)toolbar:(CPToolbar)aToolbar itemForItemIdentifier:(CPString)anItemIdentifier willBeInsertedIntoToolbar:(BOOL)aFlag
{
var toolbarItem = [[CPToolbarItem alloc] initWithItemIdentifier:anItemIdentifier];
[toolbarItem setMinSize:CGSizeMake(240, 24)];
[toolbarItem setMaxSize:CGSizeMake(240, 24)];
inputField = [[CPTextField alloc] initWithFrame:CGRectMake(20, 0, 240, 24)];
[inputField setEditable:true];
[inputField setBordered:true];
[inputField setBezeled:true];
[inputField setBezelStyle:CPTextFieldSquareBezel];
[inputField setTarget:helperObject]; //THIS GETS BROKEN
[inputField setAction:@selector(setQuery:)];
[toolbarItem setView:inputField];
[toolbarItem setLabel:"Test"];
return toolbarItem;
}
- (void)setQuery:(id)sender
{
console.log("Target: "+[sender target]+", defaulting to AppController");
}
@end
@implementation HelperObject : CPObject
{
}
- (id)init
{
if ( !(self = [super init]) )
return nil;
return self;
}
- (void)setQuery:(id)sender
{
console.log("Desired target executing code");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment