Created
March 4, 2011 01:38
-
-
Save watersofoblivion/854000 to your computer and use it in GitHub Desktop.
CPTableView and Bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import <Foundation/CPObject.j> | |
@implementation Model : CPObject | |
{ | |
CPString foo @accessors; | |
CPString bar @accessors; | |
} | |
@end | |
@implementation AppController : CPObject | |
{ | |
CPArrayController controller; | |
} | |
- (void)applicationDidFinishLaunching:(CPNotification)aNotification | |
{ | |
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask]; | |
var contentView = [theWindow contentView]; | |
var frame = CGRectMake(0, 0, CGRectGetWidth([contentView bounds]), CGRectGetHeight([contentView bounds])); | |
controller = [[CPArrayController alloc] init]; | |
[controller setContent:[CPArray array]]; | |
var table = [[CPTableView alloc] initWithFrame:frame]; | |
[table setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; | |
[table setUsesAlternatingRowBackgroundColors:YES]; | |
[table setTarget:self]; | |
[table setDoubleAction:@selector(openInspector)]; | |
[table bind:@"content" toObject:controller withKeyPath:@"contentArray" options:nil]; | |
var fooColumn = [[CPTableColumn alloc] initWithIdentifier:@"foo"]; | |
[[fooColumn headerView] setStringValue:@"Foo"]; | |
[fooColumn bind:CPValueBinding toObject:controller withKeyPath:@"arrangedObjects.foo" options:nil]; | |
[table addTableColumn:fooColumn]; | |
var barColumn = [[CPTableColumn alloc] initWithIdentifier:@"bar"]; | |
[[barColumn headerView] setStringValue:@"Bar"]; | |
[barColumn bind:CPValueBinding toObject:controller withKeyPath:@"arrangedObjects.bar" options:nil]; | |
[table addTableColumn:barColumn]; | |
var scrollView = [[CPScrollView alloc] initWithFrame:frame]; | |
[scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; | |
[scrollView setDocumentView:table]; | |
[contentView addSubview:scrollView]; | |
[theWindow orderFront:self]; | |
var modelOne = [[Model alloc] init]; | |
var modelTwo = [[Model alloc] init]; | |
[controller addObject:modelOne]; | |
[controller addObject:modelTwo]; | |
[modelOne setFoo:@"Foo One"]; | |
[modelOne setBar:@"Bar One"]; | |
[modelTwo setFoo:@"Foo Two"]; | |
[modelTwo setBar:@"Bar Two"]; | |
// Uncomment the following line to turn on the standard menu bar. | |
//[CPMenu setMenuBarVisible:YES]; | |
} | |
-(void)openInspector | |
{ | |
var inspector = [[CPWindow alloc] initWithContentRect:CGRectMake(100, 100, 200, 50) styleMask:CPTitledWindowMask | CPClosableWindowMask | CPResizableWindowMask]; | |
var contentView = [inspector contentView]; | |
var textField = [[CPTextField alloc] initWithFrame:CGRectMake(10, 10, 180, 30)]; | |
[textField setEnabled:YES]; | |
[textField setBordered:YES]; | |
[textField setBezeled:YES]; | |
[contentView addSubview:textField]; | |
[textField bind:CPValueBinding toObject:controller withKeyPath:@"selection.foo" options:nil]; | |
[inspector makeKeyAndOrderFront:self]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment