diff --git a/Tests/AppKit/ArrayController1/AppController.j b/Tests/AppKit/ArrayController1/AppController.j new file mode 100644 index 000000000..e1f0797c2 --- /dev/null +++ b/Tests/AppKit/ArrayController1/AppController.j @@ -0,0 +1,177 @@ +/* + * AppController.j + * ArrayController + * + * Created by __Me__ on __Date__. + * Copyright 2008 __MyCompanyName__. All rights reserved. + */ + +@import +@import + +CPLogRegister(CPLogConsole); + +@implementation AppController : CPObject +{ + CPArray itemsArray; + + //CPTableView tableView; + //CPTextField selectedNameField; + //CPTextField selectedPriceField; + CPTextField totalCountField; + + CPArrayController arrayController; +} + +- (void)applicationDidFinishLaunching:(CPNotification)aNotification +{ + var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], + contentView = [theWindow contentView]; + + //create our non ui objects + + itemsArray = [[Item new]]; + + arrayController = [[CPArrayController alloc] init]; + + [arrayController setEditable:YES]; + [arrayController setObjectClass:Item]; + [arrayController setAutomaticallyPreparesContent:YES]; + + [arrayController setSelectsInsertedObjects:YES]; + [arrayController setAvoidsEmptySelection:YES]; + + //create our UI elements + + //tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 400, 200)]; + //[tableView setCenter:[contentView center]]; + + totalCountField = [[CPTextField alloc] initWithFrame:CGRectMake(0, 0, 300, 20)]; + [totalCountField setCenter:[contentView center]]; + + [totalCountField setStringValue:@"HELLO WORLD"]; + + [contentView addSubview:totalCountField]; + + var frame = [totalCountField frame], + button = [[CPButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(frame)+100, CGRectGetMaxY(frame)+10, 100, 18)]; + + [button setTitle:"ADD"]; + [button setTarget:arrayController]; + [button setAction:@selector(add:)]; + + [contentView addSubview:button]; + + button = [[CPButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(frame)+100, CGRectGetMaxY(frame)+38, 100, 18)]; + + [button setTitle:"REMOVE"]; + [button setTarget:arrayController]; + [button setAction:@selector(remove:)]; + + [contentView addSubview:button]; + + //create our bindings + + [self createBindings]; + + //order front window + + [theWindow orderFront:self]; +} + +- (void)createBindings +{ + // bind array controller to self's itemsArray + [arrayController bind:@"contentArray" toObject: self + withKeyPath:@"itemsArray" options:nil]; + + // bind the total field -- no options on this one + [totalCountField bind:CPValueBinding toObject:arrayController + withKeyPath:@"arrangedObjects.@sum.price" options:nil]; + + + //var bindingOptions = [CPDictionary dictionary]; + + // binding options for "name" + //[bindingOptions setObject:@"No Name" forKey:@"NSNullPlaceholder"]; + + // binding for selected "name" field + //[selectedNameField bind: @"value" toObject: arrayController + // withKeyPath:@"selection.name" options:bindingOptions]; + + // binding for "name" column + //var tableColumn = [tableView tableColumnWithIdentifier:@"name"]; + + //[tableColumn bind:@"value" toObject: arrayController + // withKeyPath:@"arrangedObjects.name" options:bindingOptions]; + + + // binding options for "price" + // no need for placeholder as overridden by formatters + //[bindingOptions removeObjectForKey:@"NSNullPlaceholder"]; + + //[bindingOptions setObject:YES + // forKey:CPValidatesImmediatelyBindingOption]; + + // binding for selected "price" field + //[selectedPriceField bind: @"value" toObject: arrayController + // withKeyPath:@"selection.price" options:bindingOptions]; + + + // binding for "price" column + //tableColumn = [tableView tableColumnWithIdentifier:@"price"]; + + //[tableColumn bind:@"value" toObject: arrayController + // withKeyPath:@"arrangedObjects.price" options:bindingOptions]; + + +} + +- (unsigned int)countOfItemsArray +{ + return [itemsArray count]; +} + +- (id)objectInItemsArrayAtIndex:(unsigned int)index +{ + return [itemsArray objectAtIndex:index]; +} + +- (void)insertObject:(id)anObject inItemsArrayAtIndex:(unsigned int)index +{ + [itemsArray insertObject:anObject atIndex:index]; +} + +- (void)removeObjectFromItemsArrayAtIndex:(unsigned int)index +{ + [itemsArray removeObjectAtIndex:index]; +} + +- (void)replaceObjectInItemsArrayAtIndex:(unsigned int)index withObject:(id)anObject +{ + [itemsArray replaceObjectAtIndex:index withObject:anObject]; +} + +@end + +@implementation Item : CPObject +{ + float price @accessors; +} + +- (id)init +{ + self = [super init]; + price = 1.0; + return self; +} + +- (BOOL)validatePrice:(id)value error:({CPError})error +{ + if ([value intValue] >= 0) + return YES; + + return NO; +} + +@end diff --git a/Tests/AppKit/ArrayController1/Frameworks/AppKit b/Tests/AppKit/ArrayController1/Frameworks/AppKit new file mode 120000 index 000000000..fe0746a80 --- /dev/null +++ b/Tests/AppKit/ArrayController1/Frameworks/AppKit @@ -0,0 +1 @@ +/Users/boucher/Projects/Build/Release/AppKit \ No newline at end of file diff --git a/Tests/AppKit/ArrayController1/Frameworks/Debug/AppKit b/Tests/AppKit/ArrayController1/Frameworks/Debug/AppKit new file mode 120000 index 000000000..418997121 --- /dev/null +++ b/Tests/AppKit/ArrayController1/Frameworks/Debug/AppKit @@ -0,0 +1 @@ +/Users/boucher/Projects/Build/Debug/AppKit \ No newline at end of file diff --git a/Tests/AppKit/ArrayController1/Frameworks/Debug/Foundation b/Tests/AppKit/ArrayController1/Frameworks/Debug/Foundation new file mode 120000 index 000000000..f9d8a3215 --- /dev/null +++ b/Tests/AppKit/ArrayController1/Frameworks/Debug/Foundation @@ -0,0 +1 @@ +/Users/boucher/Projects/Build/Debug/Foundation \ No newline at end of file diff --git a/Tests/AppKit/ArrayController1/Frameworks/Debug/Objective-J b/Tests/AppKit/ArrayController1/Frameworks/Debug/Objective-J new file mode 120000 index 000000000..7c88c9522 --- /dev/null +++ b/Tests/AppKit/ArrayController1/Frameworks/Debug/Objective-J @@ -0,0 +1 @@ +/Users/boucher/Projects/Build/Debug/Objective-J \ No newline at end of file diff --git a/Tests/AppKit/ArrayController1/Frameworks/Foundation b/Tests/AppKit/ArrayController1/Frameworks/Foundation new file mode 120000 index 000000000..2698043eb --- /dev/null +++ b/Tests/AppKit/ArrayController1/Frameworks/Foundation @@ -0,0 +1 @@ +/Users/boucher/Projects/Build/Release/Foundation \ No newline at end of file diff --git a/Tests/AppKit/ArrayController1/Frameworks/Objective-J b/Tests/AppKit/ArrayController1/Frameworks/Objective-J new file mode 120000 index 000000000..c46828f8c --- /dev/null +++ b/Tests/AppKit/ArrayController1/Frameworks/Objective-J @@ -0,0 +1 @@ +/Users/boucher/Projects/Build/Release/Objective-J \ No newline at end of file diff --git a/Tests/AppKit/ArrayController1/Info.plist b/Tests/AppKit/ArrayController1/Info.plist new file mode 100644 index 000000000..34268e938 --- /dev/null +++ b/Tests/AppKit/ArrayController1/Info.plist @@ -0,0 +1,12 @@ + + + + + CPApplicationDelegateClass + AppController + CPBundleName + ArrayController + CPPrincipalClass + CPApplication + + diff --git a/Tests/AppKit/ArrayController1/index-debug.html b/Tests/AppKit/ArrayController1/index-debug.html new file mode 100644 index 000000000..070d80375 --- /dev/null +++ b/Tests/AppKit/ArrayController1/index-debug.html @@ -0,0 +1,36 @@ + + + + + + + Hello World + + + + + + + + +
+
+ +
+
+ + + diff --git a/Tests/AppKit/ArrayController1/index.html b/Tests/AppKit/ArrayController1/index.html new file mode 100644 index 000000000..801edfb68 --- /dev/null +++ b/Tests/AppKit/ArrayController1/index.html @@ -0,0 +1,37 @@ + + + + + + + Hello World + + + + + + + + + +
+
+ +
+
+ + + + diff --git a/Tests/AppKit/ArrayController1/main.j b/Tests/AppKit/ArrayController1/main.j new file mode 100644 index 000000000..94bf98cc3 --- /dev/null +++ b/Tests/AppKit/ArrayController1/main.j @@ -0,0 +1,18 @@ +/* + * main.j + * ArrayController + * + * Created by __Me__ on __Date__. + * Copyright 2008 __MyCompanyName__. All rights reserved. + */ + +@import +@import + +@import "AppController.j" + + +function main(args, namedArgs) +{ + CPApplicationMain(args, namedArgs); +}