Bindings Checkpoint.

This commit is contained in:
Ross Boucher committed 2009-09-21 13:27:50 -07:00
1 parent 105bb7512f
commit 3635d0ec26
13 files changed
+142 -240

No files matched your search

+8
View File
@@ -574,6 +574,14 @@ BRIDGE(ImageScaling, imageScaling, "image-scaling")
return [self hasThemeState:CPThemeStateHighlighted];
}
- (id)_replacementKeyPathForBinding:(CPString)binding
{
if ([binding isEqual:@"value"])
return @"objectValue";
return binding;
}
@end
var CPControlValueKey = "CPControlValueKey",
+5 -3
View File
@@ -72,6 +72,11 @@ var CPBindingOperationAnd = 0,
return nil;
}
+ (CPDictionary)allBindingsForObject:(id)anObject
{
return [bindingsMap objectForKey:[anObject hash]];
}
+ (void)unbind:(CPString)aBinding forObject:(id)anObject
{
var bindings = [bindingsMap objectForKey:[anObject hash]];
@@ -272,9 +277,6 @@ var CPBindingOperationAnd = 0,
- (id)_replacementKeyPathForBinding:(CPString)binding
{
if ([binding isEqual:@"value"])
return @"objectValue";
return binding;
}
+1 -1
View File
@@ -401,7 +401,7 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
else
{
var indexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self count])];
[self removeObserver:observer fromObjectsAtIndexes:indexes forKeyPath:aKeyPath];
[self removeObserver:anObserver fromObjectsAtIndexes:indexes forKeyPath:aKeyPath];
}
}
+39
View File
@@ -338,6 +338,45 @@ newDataView.identifier = dataViewUID;
@end
@implementation CPTableColumn (Bindings)
- (void)bind:(CPString)aBinding toObject:(id)anObject withKeyPath:(CPString)aKeyPath options:(CPDictionary)options
{
[super bind:aBinding toObject:anObject withKeyPath:aKeyPath options:options];
if (![aBinding isEqual:@"someListOfExceptedBindings(notAcceptedBindings)"])
[[self tableView] _establishBindingsIfUnbound:anObject];
}
- (void)prepareDataView:(CPView)aDataView forRow:(unsigned)aRow
{
var bindingsDictionary = [CPKeyValueBinding allBindingsForObject:self],
keys = [bindingsDictionary allKeys];
for (var i=0, count = [keys count]; i<count; i++)
{
var bindingName = keys[i],
bindingPath = [aDataView _replacementKeyPathForBinding:bindingName],
bindingInfo = [bindingsDictionary objectForKey:bindingName]._info,
destination = [bindingInfo objectForKey:CPObservedObjectKey],
keyPath = [bindingInfo objectForKey:CPObservedKeyPathKey];
console.log(bindingName+" : "+keyPath+" : "+aRow+" : "+[[destination valueForKeyPath:keyPath] objectAtIndex:aRow]);
[aDataView setValue:[[destination valueForKeyPath:keyPath] objectAtIndex:aRow] forKey:bindingPath];
}
}
//- (void)objectValue
//{
// return nil;
//}
- (void)setValue:(CPArray)content
{
[[self tableView] reloadData];
}
@end
var CPTableColumnIdentifierKey = @"CPTableColumnIdentifierKey",
CPTableColumnHeaderViewKey = @"CPTableColumnHeaderViewKey",
CPTableColumnDataViewKey = @"CPTableColumnDataViewKey",
+48 -10
View File
@@ -200,7 +200,7 @@ CPTableViewSolidHorizontalGridLineMask = 1 << 1;
[_headerView setTableView:self];
_cornerView = [[_CPCornerView alloc] initWithFrame:CGRectMake(0, 0, [CPScroller scrollerWidth], CGRectGetHeight([_headerView frame]))];
_cornerView = nil; //[[_CPCornerView alloc] initWithFrame:CGRectMake(0, 0, [CPScroller scrollerWidth], CGRectGetHeight([_headerView frame]))];
_selectedColumnIndexes = [CPIndexSet indexSet];
_selectedRowIndexes = [CPIndexSet indexSet];
@@ -268,8 +268,8 @@ CPTableViewSolidHorizontalGridLineMask = 1 << 1;
- (void)reloadData
{
if (!_dataSource)
return;
//if (!_dataSource)
// return;
_reloadAllRows = YES;
_objectValues = { };
@@ -538,7 +538,7 @@ CPTableViewSolidHorizontalGridLineMask = 1 << 1;
count = NUMBER_OF_COLUMNS();
for (; index < count; ++index)
if ([_tableColumns identifier] === anIdentifier)
if ([_tableColumns[index] identifier] === anIdentifier)
return index;
return CPNotFound;
@@ -643,10 +643,23 @@ CPTableViewSolidHorizontalGridLineMask = 1 << 1;
*/
- (int)numberOfRows
{
if (!_dataSource)
return 0;
if (_numberOfRows)
return _numberOfRows;
return [_dataSource numberOfRowsInTableView:self];
var contentBindingInfo = [self infoForBinding:@"content"];
if (contentBindingInfo)
{
var destination = [contentBindingInfo objectForKey:CPObservedObjectKey],
keyPath = [contentBindingInfo objectForKey:CPObservedKeyPathKey];
return [[destination valueForKeyPath:keyPath] count];
}
else if (_dataSource)
return [_dataSource numberOfRowsInTableView:self];
return 0;
}
//Displaying Cell
@@ -924,7 +937,8 @@ CPTableViewSolidHorizontalGridLineMask = 1 << 1;
- (void)noteNumberOfRowsChanged
{
_numberOfRows = [_dataSource numberOfRowsInTableView:self];
_numberOfRows = nil;
_numberOfRows = [self numberOfRows];
[self tile];
}
@@ -1308,7 +1322,12 @@ CPTableViewSolidHorizontalGridLineMask = 1 << 1;
[dataView setFrame:[self frameOfDataViewAtColumn:column row:row]];
[dataView setObjectValue:[self _objectValueForTableColumn:tableColumn row:row]];
//This gives the table column an opportunity to apply the bindings.
//It will override the value set in the data source, if there is a data source.
//It will do nothing if there is no value binding set.
[tableColumn prepareDataView:dataView forRow:row];
if ([dataView superview] !== self)
[self addSubview:dataView];
@@ -1733,6 +1752,25 @@ CPTableViewSolidHorizontalGridLineMask = 1 << 1;
@end
@implementation CPTableView (Bindings)
- (void)_establishBindingsIfUnbound:(id)destination
{
if ([[self infoForBinding:@"content"] objectForKey:CPObservedObjectKey] !== destination)
{
[self bind:@"content" toObject:destination withKeyPath:@"arrangedObjects" options:nil];
//[self bind:@"sortDescriptors" toObject:destination withKeyPath:@"sortDescriptors" options:nil];
//[self bind:@"selectionIndexes" toObject:destination withKeyPath:@"selectionIndexes" options:nil];
}
}
- (void)setContent:(CPArray)content
{
[self reloadData];
}
@end
var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey",
CPTableViewDelegateKey = @"CPTableViewDelegateKey",
CPTableViewHeaderViewKey = @"CPTableViewHeaderViewKey",
@@ -1789,7 +1827,7 @@ var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey",
[_headerView setTableView:self];
_cornerView = [[_CPCornerView alloc] initWithFrame:CGRectMake(0, 0, [CPScroller scrollerWidth], CGRectGetHeight([_headerView frame]))];
_cornerView = nil; //[[_CPCornerView alloc] initWithFrame:CGRectMake(0, 0, [CPScroller scrollerWidth], CGRectGetHeight([_headerView frame]))];
_selectedColumnIndexes = [CPIndexSet indexSet];
_selectedRowIndexes = [CPIndexSet indexSet];
+1 -1
View File
@@ -9,7 +9,7 @@
{
if (self = [super initWithFrame:aFrame])
{
[self setBackgroundColor:[CPColor purpleColor]];
[self setBackgroundColor:[CPColor blueColor]];
}
return self;
+1 -1
View File
@@ -321,7 +321,7 @@
*/
- (int)indexOfObject:(id)anObject inRange:(CPRange)aRange
{
if (anObject === nil)
if (anObject === nil || anObject === undefined)
return CPNotFound;
var i = aRange.location,
+39 -25
View File
@@ -14,11 +14,10 @@ CPLogRegister(CPLogConsole);
@implementation AppController : CPObject
{
// CPArray itemsArray;
CPSet itemsSet;
CPArray itemsArray;
CPWindow theWindow;
//CPTableView tableView;
CPTableView tableView;
//CPTextField selectedNameField;
//CPTextField selectedPriceField;
CPTextField totalCountField;
@@ -32,17 +31,7 @@ CPLogRegister(CPLogConsole);
//create our non ui objects
/*var objectController = [[CPObjectController alloc] init];
self.managed = 5;
[objectController bind:@"contentObject" toObject:self withKeyPath:@"managed" options:nil];
console.log([objectController content]);
console.log("f!: " + [self.managed description]);
[objectController addObject:[CPDictionary dictionary]];
console.log("f!: " + [self.managed description]);
*/
itemsArray = [[Item new]];
itemsSet = [[Item new]];
arrayController = [[CPArrayController alloc] init];
@@ -55,9 +44,22 @@ CPLogRegister(CPLogConsole);
//create our UI elements
//tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 400, 200)];
tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 400, 200)];
//[tableView setCenter:[contentView center]];
[tableView setBackgroundColor:[CPColor redColor]];
var column = [[CPTableColumn alloc] initWithIdentifier:@"name"];
[tableView addTableColumn:column];
column = [[CPTableColumn alloc] initWithIdentifier:@"price"];
[tableView addTableColumn:column];
//[tableView setDataSource:self];
[contentView addSubview:tableView];
//create our bindings
[self createBindings];
@@ -67,7 +69,17 @@ CPLogRegister(CPLogConsole);
[theWindow setFullBridge:YES];
[theWindow orderFront:self];
}
/*
- (int)numberOfRowsInTableView:(CPTableView)tableView
{
return [itemsArray count];
}
- (id)tableView:(CPTableView)tableView objectValueForTableColumn:(CPTableColumn)tableColumn row:(int)row
{
return "foo";
}
*/
- (void)add:(id)aSender
{
[arrayController add:self];
@@ -81,14 +93,14 @@ CPLogRegister(CPLogConsole);
- (void)createBindings
{
// bind array controller to self's itemsArray
[arrayController bind:@"contentSet" toObject:self
withKeyPath:@"itemsSet" options:nil];
[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];
var bindingOptions = [CPDictionary dictionary];
// binding options for "name"
//[bindingOptions setObject:@"No Name" forKey:@"NSNullPlaceholder"];
@@ -98,10 +110,10 @@ CPLogRegister(CPLogConsole);
// withKeyPath:@"selection.name" options:bindingOptions];
// binding for "name" column
//var tableColumn = [tableView tableColumnWithIdentifier:@"name"];
var tableColumn = [tableView tableColumnWithIdentifier:@"name"];
//[tableColumn bind:@"value" toObject: arrayController
// withKeyPath:@"arrangedObjects.name" options:bindingOptions];
[tableColumn bind:@"value" toObject: arrayController
withKeyPath:@"arrangedObjects.name" options:bindingOptions];
// binding options for "price"
@@ -117,12 +129,12 @@ CPLogRegister(CPLogConsole);
// binding for "price" column
//tableColumn = [tableView tableColumnWithIdentifier:@"price"];
tableColumn = [tableView tableColumnWithIdentifier:@"price"];
//[tableColumn bind:@"value" toObject: arrayController
// withKeyPath:@"arrangedObjects.price" options:bindingOptions];
[tableColumn bind:@"value" toObject: arrayController
withKeyPath:@"arrangedObjects.price" options:bindingOptions];
}
/*
- (unsigned int)countOfItemsArray
{
return [itemsArray count];
@@ -147,18 +159,20 @@ CPLogRegister(CPLogConsole);
{
[itemsArray replaceObjectAtIndex:index withObject:anObject];
}
*/
@end
@implementation Item : CPObject
{
float price @accessors;
CPString name @accessors;
}
- (id)init
{
self = [super init];
price = 7.0;
name = "bob";
return self;
}
@@ -1,99 +0,0 @@
/*
* AppController.j
*
* Created by __Me__ on __Date__.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*/
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
CPSlider slider;
CPTextField textField;
Track track @accessors;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
textField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[textField setAlignment:CPCenterTextAlignment];
[textField setStringValue:@"Hello World!"];
[textField setFont:[CPFont boldSystemFontOfSize:24.0]];
[textField sizeToFit];
[textField setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[textField setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds]) - CGRectGetWidth([textField frame])) / 2.0, (CGRectGetHeight([contentView bounds]) - CGRectGetHeight([textField frame])) / 2.0)];
[contentView addSubview:textField];
var textFrame = [textField frame];
slider = [[CPSlider alloc] initWithFrame:CGRectMake(CGRectGetMinX(textFrame), CGRectGetMaxY(textFrame)+10, CGRectGetWidth(textFrame), 12)];
[slider setTarget:self];
[slider setAction:@selector(updateVolumeFrom:)];
[slider setContinuous:NO];
[contentView addSubview:slider];
var button = [[CPButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(textFrame)+25, CGRectGetMaxY(textFrame)+40, 100, 18)];
[button setTitle:@"mute"];
[button setTarget:self];
[button setAction:@selector(muteTrack:)];
[contentView addSubview:button];
track = [[Track alloc] init];
[track setVolume:5.0];
[theWindow orderFront:self];
// Uncomment the following line to turn on the standard menu bar.
//[CPMenu setMenuBarVisible:YES];
}
- (void)updateVolumeFrom:(id)sender
{
var newVolume = [sender floatValue];
[track setVolume:newVolume];
[self updateUserInterface];
}
- (void)updateUserInterface
{
[slider setFloatValue:[track volume]];
[textField setStringValue:sprintf(@"%.4f", [track volume])];
}
- (IBAction)muteTrack:(id)sender
{
[track setVolume:0.0];
[self updateUserInterface];
}
@end
@implementation Track : CPObject
{
float volume @accessors;
CPString title @accessors;
}
@end
-12
View File
@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CPApplicationDelegateClass</key>
<string>AppController</string>
<key>CPBundleName</key>
<string>Hello World</string>
<key>CPPrincipalClass</key>
<string>CPApplication</string>
</dict>
</plist>
@@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" lang = "en">
<!--
//
// index-debug.html
//
// Created by __Me__ on __Date__.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
-->
<head>
<title>Hello World</title>
<script type = "text/javascript">
OBJJ_MAIN_FILE = "main.j";
OBJJ_INCLUDE_PATHS = ["Frameworks/Debug", "Frameworks", "SomethingElse"];
</script>
<script src = "Frameworks/Debug/Objective-J/Objective-J.js" type = "text/javascript"></script>
</head>
<body>
<div style="position: absolute; left: 50%; top: 50%;">
<center>
<img src = "Frameworks/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif" style="left: -32px; position: relative; top: -32px;" />
</center>
</div>
</body>
</html>
-36
View File
@@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" lang = "en">
<!--
//
// index.html
//
// Created by __Me__ on __Date__.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
-->
<head>
<title>Hello World</title>
<script type = "text/javascript">
OBJJ_MAIN_FILE = "main.j";
</script>
<script src = "Frameworks/Objective-J/Objective-J.js" type = "text/javascript"></script>
</head>
<body>
<div style="position: absolute; left: 50%; top: 50%;">
<center>
<img src = "Frameworks/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif" style="left: -32px; position: relative; top: -32px;" />
</center>
</div>
</body>
</html>
-17
View File
@@ -1,17 +0,0 @@
/*
* main.j
*
* Created by __Me__ on __Date__.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import "AppController.j"
function main(args, namedArgs)
{
CPApplicationMain(args, namedArgs);
}