Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/cappuccino/cappuccino
Browse files Browse the repository at this point in the history
  • Loading branch information
primalmotion committed Jul 25, 2012
2 parents fa1441c + b1e519f commit 673c3c1
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 78 deletions.
56 changes: 27 additions & 29 deletions AppKit/CPRuleEditor/CPRuleEditor.j
Expand Up @@ -507,7 +507,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
- (int)parentRowForRow:(int)rowIndex
{
if (rowIndex < 0 || rowIndex >= [self numberOfRows])
[CPException raise:CPRangeException reason:_cmd+@" row " + rowIndex + " is out of range"];
[CPException raise:CPRangeException reason:_cmd + @" row " + rowIndex + " is out of range"];

var targetObject = [[self _rowCacheForIndex:rowIndex] rowObject];

Expand Down Expand Up @@ -548,7 +548,7 @@ TODO: implement
- (CPRuleEditorRowType)rowTypeForRow:(int)rowIndex
{
if (rowIndex < 0 || rowIndex > [self numberOfRows])
[CPException raise:CPRangeException reason:_cmd+@"row " + rowIndex + " is out of range"];
[CPException raise:CPRangeException reason:_cmd + @"row " + rowIndex + " is out of range"];

var rowcache = [self _rowCacheForIndex:rowIndex];
if (rowcache)
Expand Down Expand Up @@ -588,7 +588,7 @@ TODO: implement
if (indexInSubrows !== CPNotFound)
{
[indexes addIndex:i];
objectsCount --;
objectsCount--;

if ([self rowTypeForRow:i] === CPRuleEditorRowTypeCompound)
i += [[self subrowIndexesForRow:i] count];
Expand Down Expand Up @@ -848,7 +848,7 @@ TODO: implement
}
catch(error)
{
CPLogConsole(@"Compound predicate error: [%@]\npredicateType:%i",[error description],compoundType);
CPLogConsole(@"Compound predicate error: [%@]\npredicateType:%i", [error description], compoundType);
compoundPredicate = nil;
}
finally
Expand Down Expand Up @@ -893,23 +893,21 @@ TODO: implement
try
{
if (selector !== nil)
predicate = [CPComparisonPredicate
predicateWithLeftExpression:lhs
rightExpression:rhs
customSelector:selector
predicate = [CPComparisonPredicate predicateWithLeftExpression:lhs
rightExpression:rhs
customSelector:selector
];
else
predicate = [CPComparisonPredicate
predicateWithLeftExpression:lhs
rightExpression:rhs
modifier:(modifier || CPDirectPredicateModifier)
type:operator
options:(options || CPCaseInsensitivePredicateOption)
predicate = [CPComparisonPredicate predicateWithLeftExpression:lhs
rightExpression:rhs
modifier:(modifier || CPDirectPredicateModifier)
type:operator
options:(options || CPCaseInsensitivePredicateOption)
];
}
catch(error)
{
CPLogConsole(@"Row predicate error: ["+[error description]+"] for row "+aRow);
CPLogConsole(@"Row predicate error: [" + [error description] + "] for row " + aRow);
predicate = nil;
}
finally
Expand Down Expand Up @@ -1135,7 +1133,7 @@ TODO: implement

- (_CPRuleEditorViewSliceDropSeparator)_createSliceDropSeparator
{
var view = [[_CPRuleEditorViewSliceDropSeparator alloc] initWithFrame:CGRectMake(0,-10, [self frame].size.width, 2)];
var view = [[_CPRuleEditorViewSliceDropSeparator alloc] initWithFrame:CGRectMake(0, -10, [self frame].size.width, 2)];
[view setAutoresizingMask:CPViewWidthSizable];
return view;
}
Expand Down Expand Up @@ -1316,7 +1314,7 @@ TODO: implement
return [_boundArrayOwner mutableArrayValueForKey:_boundArrayKeyPath];
}

- (BOOL)_nextUnusedItems:({CPArray})items andValues:({CPArray})values forRow:(int)rowIndex forRowType:(unsigned int)type
- (BOOL)_nextUnusedItems:(CPArray)items andValues:(CPArray)values forRow:(int)rowIndex forRowType:(unsigned int)type
{
var parentItem = [items lastObject], // if empty items array, this is NULL aka the root item;
childrenCount = [self _queryNumberOfChildrenOfItem:parentItem withRowType:type],
Expand Down Expand Up @@ -1398,7 +1396,7 @@ TODO: implement
{
var item = [items objectAtIndex:i],
value = [values objectAtIndex:i],
itemAndValue = [CPDictionary dictionaryWithObjects:[item,value] forKeys:["item","value"]];
itemAndValue = [CPDictionary dictionaryWithObjects:[item, value] forKeys:["item", "value"]];

[itemsAndValues addObject:itemAndValue];
}
Expand Down Expand Up @@ -2109,9 +2107,9 @@ TODO: implement
mainRowIndex = [slice rowIndex],
draggingRows = [CPIndexSet indexSetWithIndex:mainRowIndex],
selected_indices = [self _selectedSliceIndices],
pasteboard = [CPPasteboard pasteboardWithName: CPDragPboard];
pasteboard = [CPPasteboard pasteboardWithName:CPDragPboard];

[pasteboard declareTypes:[CPArray arrayWithObjects: CPRuleEditorItemPBoardType, nil] owner: self];
[pasteboard declareTypes:[CPArray arrayWithObjects:CPRuleEditorItemPBoardType, nil] owner: self];

if ([selected_indices containsIndex:mainRowIndex])
[draggingRows addIndexes:selected_indices];
Expand Down Expand Up @@ -2314,7 +2312,7 @@ TODO: implement
{
var rowObject = [[self _rowCacheForIndex:current_index] rowObject],
subrows = [self _subrowObjectsOfObject:rowObject],
subIndexes = [self _globalIndexesForSubrowIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0,[subrows count])] ofParentObject:rowObject];
subIndexes = [self _globalIndexesForSubrowIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [subrows count])] ofParentObject:rowObject];

numberOfChildrenOfPreviousBrother = [subIndexes count];
}
Expand Down Expand Up @@ -2416,17 +2414,17 @@ var CPRuleEditorAlignmentGridWidthKey = @"CPRuleEditorAlignmentGridWidth",
if (self !== nil)
{
[self setFormattingStringsFilename:[coder decodeObjectForKey:CPRuleEditorStringsFilenameKey]];
_alignmentGridWidth = [coder decodeFloatForKey:CPRuleEditorAlignmentGridWidthKey];
_sliceHeight = [coder decodeDoubleForKey:CPRuleEditorSliceHeightKey];
_alignmentGridWidth = [coder decodeFloatForKey:CPRuleEditorAlignmentGridWidthKey];
_sliceHeight = [coder decodeDoubleForKey:CPRuleEditorSliceHeightKey];
_editable = [coder decodeBoolForKey:CPRuleEditorEditableKey];
_allowsEmptyCompoundRows = [coder decodeBoolForKey:CPRuleEditorAllowsEmptyCompoundRowsKey];
_disallowEmpty = [coder decodeBoolForKey:CPRuleEditorDisallowEmptyKey];
_nestingMode = [coder decodeIntForKey:CPRuleEditorNestingModeKey];
_typeKeyPath = [coder decodeObjectForKey:CPRuleEditorRowTypeKeyPathKey];
_itemsKeyPath = [coder decodeObjectForKey:CPRuleEditorItemsKeyPathKey];
_valuesKeyPath = [coder decodeObjectForKey:CPRuleEditorValuesKeyPathKey];
_subrowsArrayKeyPath = [coder decodeObjectForKey:CPRuleEditorSubrowsArrayKeyPathKey];
_boundArrayKeyPath = [coder decodeObjectForKey:CPRuleEditorBoundArrayKeyPathKey];
_nestingMode = [coder decodeIntForKey:CPRuleEditorNestingModeKey];
_typeKeyPath = [coder decodeObjectForKey:CPRuleEditorRowTypeKeyPathKey];
_itemsKeyPath = [coder decodeObjectForKey:CPRuleEditorItemsKeyPathKey];
_valuesKeyPath = [coder decodeObjectForKey:CPRuleEditorValuesKeyPathKey];
_subrowsArrayKeyPath = [coder decodeObjectForKey:CPRuleEditorSubrowsArrayKeyPathKey];
_boundArrayKeyPath = [coder decodeObjectForKey:CPRuleEditorBoundArrayKeyPathKey];

_slicesHolder = [[self subviews] objectAtIndex:0];
_boundArrayOwner = [coder decodeObjectForKey:CPRuleEditorBoundArrayOwnerKey];
Expand Down
2 changes: 1 addition & 1 deletion AppKit/Cib/CPCib.j
Expand Up @@ -162,7 +162,7 @@ var CPCibObjectDataKey = @"CPCibObjectDataKey";

- (BOOL)instantiateCibWithOwner:(id)anOwner topLevelObjects:(CPArray)topLevelObjects
{
return [self instantiateCibWithExternalNameTable:[CPDictionary dictionaryWithObjectsAndKeys:anOwner, CPCibOwner, topLevelObjects, CPCibTopLevelObjects]];
return [self instantiateCibWithExternalNameTable:[CPDictionary dictionaryWithObjects:[anOwner, topLevelObjects] forKeys:[CPCibOwner, CPCibTopLevelObjects]]];
}

@end
Expand Down
28 changes: 28 additions & 0 deletions Foundation/CPArray+KVO.j
Expand Up @@ -514,6 +514,31 @@

@implementation CPArray (KeyValueObserving)

/*!
Raises an exception.
CPArray objects are not observable, so this method raises an exception when invoked on an CPArray object.
Instead of observing a array, observe the ordered to-many relationship for which the array is the collection of related objects.
*/
- (void)addObserver:(id)anObserver forKeyPath:(CPString)aKeyPath options:(CPKeyValueObservingOptions)anOptions context:(id)aContext
{
[CPException raise:CPInvalidArgumentException reason:"[CPArray " + CPStringFromSelector(_cmd) + "] is not supported. Key path: " + aKeyPath];
}

/*!
Raises an exception.
CPArray objects are not observable, so this method raises an exception when invoked on an CPArray object.
Instead of observing a array, observe the ordered to-many relationship for which the array is the collection of related objects.
*/
- (void)removeObserver:(id)anObserver forKeyPath:(CPString)aKeyPath
{
[CPException raise:CPInvalidArgumentException reason:"[CPArray " + CPStringFromSelector(_cmd) + "] is not supported. Key path: " + aKeyPath];
}

/*!
Registers an observer to receive key value observer notifications for the specified key-path relative to the objects at the indexes.
*/
- (void)addObserver:(id)anObserver toObjectsAtIndexes:(CPIndexSet)indexes forKeyPath:(CPString)aKeyPath options:(unsigned)options context:(id)context
{
var index = [indexes firstIndex];
Expand All @@ -526,6 +551,9 @@
}
}

/*!
Removes anObserver from all key value observer notifications associated with the specified keyPath relative to the array’s objects at indexes.
*/
- (void)removeObserver:(id)anObserver fromObjectsAtIndexes:(CPIndexSet)indexes forKeyPath:(CPString)aKeyPath
{
var index = [indexes firstIndex];
Expand Down
26 changes: 9 additions & 17 deletions Foundation/CPNumberFormatter.j
Expand Up @@ -57,6 +57,7 @@ CPNumberFormatterRoundHalfUp = CPRoundPlain;
{
CPNumberFormatterStyle _numberStyle @accessors(property=numberStyle);
CPString _perMillSymbol @accessors(property=perMillSymbol);
CPString _groupingSeparator @accessors(property=groupingSeparator);
CPNumberFormatterRoundingMode _roundingMode @accessors(property=roundingMode);
CPUInteger _maximumFractionalDigits @accessors(property=maximalFractionalDigits);

Expand All @@ -69,6 +70,7 @@ CPNumberFormatterRoundHalfUp = CPRoundPlain;
{
_roundingMode = CPNumberFormatterRoundHalfUp;
_maximumFractionalDigits = 3;
_groupingSeparator = @",";
}

return self;
Expand All @@ -90,17 +92,18 @@ CPNumberFormatterRoundHalfUp = CPRoundPlain;
preFraction = parts[0],
fraction = parts.length > 1 ? parts[1] : "",
preFractionLength = [preFraction length],
commaPosition = 3,
perMillSymbol = [self _effectivePerMillSymbol];
commaPosition = 3;

// TODO This is just a temporary solution. Should be generalised.
// Add in thousands separators.
if (perMillSymbol)
while (commaPosition < [preFraction length])
if (_groupingSeparator)
{
for (var commaPosition = 3, prefLength = [preFraction length]; commaPosition < prefLength; commaPosition += 4)
{
preFraction = [preFraction stringByReplacingCharactersInRange:CPMakeRange(commaPosition, 0) withString:perMillSymbol];
commaPosition += 4;
preFraction = [preFraction stringByReplacingCharactersInRange:CPMakeRange(prefLength - commaPosition, 0) withString:_groupingSeparator];
prefLength += 1;
}
}

if (fraction)
return preFraction + "." + fraction;
Expand Down Expand Up @@ -139,17 +142,6 @@ CPNumberFormatterRoundHalfUp = CPRoundPlain;
return YES;
}

/*!
@ignore
Return the perMillSymbol if set, otherwise the locale default.
*/
- (CPString)_effectivePerMillSymbol
{
if (_perMillSymbol === nil || _perMillSymbol === undefined)
return ","; // (FIXME US Locale specific.)
return _perMillSymbol;
}

- (void)setRoundingMode:(CPNumberFormatterRoundingMode)aRoundingMode
{
_roundingMode = aRoundingMode;
Expand Down
34 changes: 25 additions & 9 deletions Foundation/CPSet/_CPConcreteMutableSet.j
Expand Up @@ -48,13 +48,21 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;
{
var UID = [anObject UID];

if (!hasOwnProperty.call(_contents, UID))
return nil;
if (hasOwnProperty.call(_contents, UID))
return _contents[UID];
else
{
for (var objectUID in _contents)
{
if (!hasOwnProperty.call(_contents, objectUID))
continue;

var object = _contents[UID];
var object = _contents[objectUID];

if (object === anObject || [object isEqual:anObject])
return object;
if (object === anObject || [object isEqual:anObject])
return object;
}
}

return nil;
}
Expand Down Expand Up @@ -100,11 +108,19 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;
*/
- (void)removeObject:(id)anObject
{
if (![self containsObject:anObject])
return;
// Removing nil is an error.
if (anObject === nil || anObject === undefined)
[CPException raise:CPInvalidArgumentException reason:@"attempt to remove nil or undefined"];

delete _contents[[anObject UID]];
_count--;
// anObject might be isEqual: another object in the set. We need the exact instance so we can remove it by UID.
var object = [self member:anObject];

// ...but removing an object not present in the set is not an error.
if (object !== nil)
{
delete _contents[[object UID]];
_count--;
}
}

/*
Expand Down
8 changes: 8 additions & 0 deletions Tests/Foundation/CPArrayTest.j
Expand Up @@ -673,6 +673,14 @@
[self assertTrue:s2[0] === A message:s2[0] + " is larger then " + A + " when sorting descending"];
}

- (void)testDisallowObservers
{
var anArray = [CPArray arrayWithObject:0];

[self assertThrows:function() { [anArray addObserver:self forKeyPath:@"self" options:0 context:nil]; }];
[self assertThrows:function() { [anArray removeObserver:self forKeyPath:@"self"]; }];
}

@end

@implementation AlwaysEqual : CPObject
Expand Down
3 changes: 3 additions & 0 deletions Tests/Foundation/CPIndexSetTest.j
Expand Up @@ -288,6 +288,9 @@ function descriptionWithoutEntity(aString)
{
[self assert:[_set lastIndex] equals:19];
[self assert:[[CPIndexSet indexSet] lastIndex] equals:CPNotFound];

var singleIndexSet = [CPIndexSet indexSetWithIndex:3];
[self assert:3 equals:[singleIndexSet lastIndex]];
}
/*
- (void)testAddSpeed
Expand Down
23 changes: 23 additions & 0 deletions Tests/Foundation/CPNumberFormatterTest.j
Expand Up @@ -16,6 +16,29 @@
[self assert:@"122,344.456" equals:formattedNumberString];
}

- (void)testSetGroupingSeparator_
{
var numberFormatter = [CPNumberFormatter new];
[numberFormatter setNumberStyle:CPNumberFormatterDecimalStyle];

[self assert:@"1" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:1]]];
[self assert:@"12" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:12]]];
[self assert:@"123" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:123]]];
[self assert:@"1,234" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:1234]]];
[self assert:@"12,345" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:12345]]];
[self assert:@"123,456" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:123456]]];
[self assert:@"1,234,567" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:1234567]]];

[numberFormatter setGroupingSeparator:@" "];
[self assert:@"1" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:1]]];
[self assert:@"12" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:12]]];
[self assert:@"123" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:123]]];
[self assert:@"1 234" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:1234]]];
[self assert:@"12 345" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:12345]]];
[self assert:@"123 456" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:123456]]];
[self assert:@"1 234 567" equals:[numberFormatter stringFromNumber:[CPNumber numberWithInt:1234567]]];
}

- (void)testRoundingMode
{
var numberFormatter = [[CPNumberFormatter alloc] init],
Expand Down

0 comments on commit 673c3c1

Please sign in to comment.