[ruleeditor commit] r96 - branches/CPRuleEditor

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 21, 2008, 3:15:10 PM10/21/08
to psruleedit...@googlegroups.com
Author: caca...@gmail.com
Date: Tue Oct 21 12:13:45 2008
New Revision: 96

Added:
branches/CPRuleEditor/CPPredicateTest.j
Removed:
branches/CPRuleEditor/CPPredicateTests.j
Modified:
branches/CPRuleEditor/AppController.j
branches/CPRuleEditor/CPComparisonPredicate.j
branches/CPRuleEditor/CPCompoundPredicate.j
branches/CPRuleEditor/CPRuleEditor.j
branches/CPRuleEditor/CPRuleEditorPopupButtonCell.j
branches/CPRuleEditor/CPRuleEditorViewSliceRow.j
branches/CPRuleEditor/RuleDelegate.j
branches/CPRuleEditor/index.html
branches/CPRuleEditor/main.j

Log:
Minor updates

Modified: branches/CPRuleEditor/AppController.j
==============================================================================
--- branches/CPRuleEditor/AppController.j (original)
+++ branches/CPRuleEditor/AppController.j Tue Oct 21 12:13:45 2008
@@ -3,6 +3,8 @@
import "CPRuleEditor.j"
import "RuleDelegate.j"

+
+
@implementation CPObject (Additions)

- (id)mutableArrayValueForKey:(CPString)key
@@ -24,16 +26,33 @@
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero()
styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];

- var ruleeditor = [[RuleEditor alloc]
initWithFrame:CGRectMake(0,0,600,400)];
- var datasource = [[RuleDelegate alloc] init];
- [ruleeditor setDelegate:datasource];
+ var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"aà"]
rightExpression:[CPExpression expressionForConstantValue:@"àa"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:3];
+
+ CPLogConsole("RESULT = "+[pred evaluateWithObject:nil]);
+
+ var ruleeditor = [[RuleEditor alloc]
initWithFrame:CGRectMake(0,0,400,200)];
+ [ruleeditor setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin |
CPViewHeightSizable];
+
+ var datasource = [[RuleDelegate alloc] init];
+ [ruleeditor setDelegate:datasource];

[ruleeditor setBackgroundColor:[CPColor grayColor]];
- [contentView addSubview:ruleeditor];

- [ruleeditor addRow:self];
+
+ var aView = [[CPView alloc] initWithFrame:CGRectMake(0,0,50,200)];
+ [aView setBackgroundColor:[CPColor greenColor]];
+
+ var split = [[CPSplitView alloc]
initWithFrame:CGRectMake(0,0,600,400)];
+ [split addSubview:aView];
+ [split addSubview:ruleeditor];
+
+ [contentView addSubview:split];
+ [ruleeditor addRow:self];
[theWindow orderFront:self];

+ var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"àa"]
rightExpression:[CPExpression expressionForConstantValue:@"aà"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:3];
+
+
// Uncomment the following line to turn on the standard menu bar.
//[CPMenu setMenuBarVisible:YES];
}

Modified: branches/CPRuleEditor/CPComparisonPredicate.j
==============================================================================
--- branches/CPRuleEditor/CPComparisonPredicate.j (original)
+++ branches/CPRuleEditor/CPComparisonPredicate.j Tue Oct 21 12:13:45 2008
@@ -239,6 +239,8 @@

- (BOOL)_evaluateValue:leftResult rightValue:rightResult
{
+var CPDiacriticInsensitiveSearch = 128;
+
var leftIsNil = (leftResult == nil || [leftResult isEqual:[CPNull null]]);
var rightIsNil = (rightResult == nil || [rightResult isEqual:[CPNull
null]]);

@@ -247,6 +249,8 @@
&& (_type == CPEqualToPredicateOperatorType
|| _type == CPLessThanOrEqualToPredicateOperatorType
|| _type == CPGreaterThanOrEqualToPredicateOperatorType));
+
+ var string_compare_options = 0;

// left and right should be casted first [CAST()] following 10.5 rules.
switch(_type){
@@ -272,22 +276,20 @@
case CPMatchesPredicateOperatorType:
if(_options & CPDiacriticInsensitivePredicateOption)
{
- leftResult = replace_diacritics(leftResult);
- rightResult = replace_diacritics(rightResult);
+ leftResult = _stripDiacritics(leftResult);
+ rightResult = _stripDiacritics(rightResult);
}

var commut = (_options &
CPCaseInsensitivePredicateOption) ? "gi":"g";
var reg = new RegExp(rightResult,commut);
return reg.test(leftResult);

- case CPLikePredicateOperatorType:
-
+ case CPLikePredicateOperatorType:
if(_options & CPDiacriticInsensitivePredicateOption)
{
- leftResult = replace_diacritics(leftResult);
- rightResult = replace_diacritics(rightResult);
+ leftResult = _stripDiacritics(leftResult);
+ rightResult = _stripDiacritics(rightResult);
}
-
var commut = (_options &
CPCaseInsensitivePredicateOption) ? "gi":"g";
var like_pattern = escape_regex(rightResult);
var reg = new RegExp(like_pattern,commut);
@@ -295,25 +297,15 @@

case CPBeginsWithPredicateOperatorType:
var range = CPMakeRange(0,[rightResult length]);
- var string_compare_options = (_options &
CPCaseInsensitivePredicateOption) ? CPCaseInsensitiveSearch : 0;
-
- if(_options & CPDiacriticInsensitivePredicateOption)
- {
- leftResult = replace_diacritics(leftResult);
- rightResult = replace_diacritics(rightResult);
- }
+ if (_options & CPCaseInsensitivePredicateOption) string_compare_options
|= CPCaseInsensitiveSearch;
+ if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;

return ([leftResult compare:rightResult options:string_compare_options
range:range] == CPOrderedSame);

case CPEndsWithPredicateOperatorType:
var range = CPMakeRange([leftResult length] - [rightResult
length],[rightResult length]);
- var string_compare_options = (_options &
CPCaseInsensitivePredicateOption) ? CPCaseInsensitiveSearch : 0;
-
- if(_options & CPDiacriticInsensitivePredicateOption)
- {
- leftResult = replace_diacritics(leftResult);
- rightResult = replace_diacritics(rightResult);
- }
+ if (_options & CPCaseInsensitivePredicateOption) string_compare_options
|= CPCaseInsensitiveSearch;
+ if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;

return ([leftResult compare:rightResult options:string_compare_options
range:range] == CPOrderedSame);

@@ -337,11 +329,8 @@
return NO;
}

- if(_options & CPDiacriticInsensitivePredicateOption)
- {
- leftResult = replace_diacritics(leftResult);
- rightResult = replace_diacritics(rightResult);
- }
+ if (_options & CPCaseInsensitivePredicateOption)
string_compare_options |= CPCaseInsensitiveSearch;
+ if (_options & CPDiacriticInsensitivePredicateOption)
string_compare_options |= CPDiacriticInsensitiveSearch;

return ([rightResult rangeOfString: leftResult options:
string_compare_options].location != CPNotFound);

@@ -389,24 +378,34 @@

@end

-function replace_diacritics(str)
+function _stripDiacritics(str)
{
- var diacritics = [
- /[À-Æ]/g, /[à-æ]/g, // A, a
- /È-Ë/g, /[è-ë]/g, // E, e
- /[Ì-Ï]/g, /[ì-ï]/g, // I, i
- /[Ò-Ö]/g, /[ò-ö]/g, // O, o
- /[Ù-Ü]/g, /[ù-ü]/g, // U, u
- /Ñ/g, /ñ/g, // N, n
- /Ç/g, /ç/g, // C, c
- ];
-
- var normalized =
['A','a','E','e','I','i','O','o','U','u','N','n','C','c'];
-
- for (var i = 0; i < diacritics.length; i++)
- str = str.replace(diacritics[i],normalized[i])
+var buffer = "";
+
+ var diacritics =
[[192,198],[224,230],[231,231],[232,235],[236,239],[242,246],[249,252]];
+ var normalized = [65,97,99,101,105,111,117];
+
+ for (var indexSource = 0; indexSource < [str length]; indexSource++)
+ {
+ var code = str.charCodeAt(indexSource);
+
+ for (var i = 0; i < diacritics.length; i++)
+ {
+ var drange = diacritics[i];
+
+ if(code >= drange[0] && code <= drange[1])
+ {
+ CPLogConsole(str.charAt(indexSource) + " ; old code = "+code+" ; new
= "+ normalized[i]);
+ code = normalized[i];
+ break;
+ }
+ }
+
+ buffer += String.fromCharCode(code);
+ }
+

-return str;
+return buffer;
}

function escape_regex(str)

Modified: branches/CPRuleEditor/CPCompoundPredicate.j
==============================================================================
--- branches/CPRuleEditor/CPCompoundPredicate.j (original)
+++ branches/CPRuleEditor/CPCompoundPredicate.j Tue Oct 21 12:13:45 2008
@@ -46,7 +46,7 @@
var sp = [p predicateWithSubstitutionVariables:variables];
[subp addObject:sp];
}
- return [[[CPCompoundPredicate alloc] initWithType:_type
subpredicates:subp] autorelease];
+ return [[CPCompoundPredicate alloc] initWithType:_type
subpredicates:subp];
}

- (CPString)predicateFormat

Added: branches/CPRuleEditor/CPPredicateTest.j
==============================================================================
--- (empty file)
+++ branches/CPRuleEditor/CPPredicateTest.j Tue Oct 21 12:13:45 2008
@@ -0,0 +1,82 @@
+import <Foundation/Foundation.j>
+import "CPPredicate.j"
+
+@implementation CPPredicateTest : OJTestCase
+
+-(void)testExpressionsInitialization{
+
+ var expression_keypath = [CPExpression expressionForKeyPath:@"name"];
+ [self assertNotNull:expression_keypath message:"Expression should not
be nil"];
+
+ var expression_str = [CPExpression
expressionForConstantValue:@"j[a-z]an"];
+ [self assertNotNull:expression_str message:"Expression should not be
nil"];
+
+ var expression_num = [CPExpression
expressionForConstantValue:[CPNumber numberWithInt:1]];
+ [self assertNotNull:expression_num message:"Expression should not be
nil"];
+
+ var expression_collection = [CPExpression
expressionForConstantValue:[CPArray arrayWithObjects:@"a",@"b",@"d",nil]];
+ [self assertNotNull:expression_collection message:"Expression should
not be nil"];
+
+ var expression_var = [CPExpression expressionForVariable:@"variable"];
+ [self assertNotNull:expression_var message:"Expression should not be
nil"];
+
+ var expression_function = [CPExpression expressionForFunction:@"sum:"
arguments:[CPArray arrayWithObjects:expression_num,expression_num,nil]];
+ [self assertNotNull:expression_function message:"Expression should not
be nil"];
+
+ var expression_self = [CPExpression expressionForEvaluatedObject];
+ [self assertNotNull:expression_self message:"Expression should not be
nil"];
+
+ var expression_aggregate = [CPExpression
expressionForAggregate:[CPArray
arrayWithObjects:expression_str,expression_num,expression_function,nil]];
+ [self assertNotNull:expression_aggregate message:"Expression should
not be nil"];
+
+// var expression_subquery = [CPExpression
expressionForSubquery:expression_collection usingIteratorVariable:@"self"
predicate:[CPPredicate predicateWithValue:YES]];
+// [self assertNotNull:expression_subquery message:"Expression should
not be nil"];
+
+ var set = [CPSet setWithObjects:@"a",@"b",@"d",nil];
+ var array = [CPArray arrayWithObjects:@"a",@"b",@"d",nil];
+
+ var expression_intersect = [CPExpression expressionForIntersectSet:set
with:array];
+ [self assertNotNull:expression_intersect message:"Expression should
not be nil"];
+
+ var expression_unionset = [CPExpression expressionForUnionSet:set
with:array];
+ [self assertNotNull:expression_unionset message:"Expression should not
be nil"];
+
+ var expression_minusset = [CPExpression expressionForMinusSet:set
with:array];
+ [self assertNotNull:expression_minusset message:"Expression should not
be nil"];
+
+}
+
+- (void)testOptions
+{
+ var pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"àa"]
rightExpression:[CPExpression expressionForConstantValue:@"aà"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:3];
+
+ [self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred
description] + "/ should be true"];
+
+ pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"aB"]
rightExpression:[CPExpression expressionForConstantValue:@"Ab"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:1];
+
+ [self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred
description] + "/ should be true"];
+
+
+}
+
+-(void)testOperators{
+ var predicate_match = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:"Farenight
451"] rightExpression:[CPExpression expressionForConstantValue:"(F|
g)\\w+\\s\\d{3}"] modifier:CPDirectPredicateModifier
type:CPMatchesPredicateOperatorType options:2];
+
+ [self assertTrue:[predicate_match evaluateWithObject:nil] message:"/"+
[predicate_match description] + "/ should be true"];
+
+ pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"b"]
rightExpression:[CPExpression expressionForConstantValue:@"[a-c]"]
modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType
options:1];
+
+ [self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred
description] + "/ should be true"];
+
+
+ pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"Aa"]
rightExpression:[CPExpression expressionForConstantValue:@"ab"]
modifier:CPDirectPredicateModifier type:CPLessThanPredicateOperatorType
options:0];
+
+ [self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred
description] + "/ should be true"];
+
+ pred = [[CPComparisonPredicate alloc]
initWithLeftExpression:[CPExpression expressionForConstantValue:@"Ac"]
rightExpression:[CPExpression expressionForConstantValue:@"ab"]
modifier:CPDirectPredicateModifier type:CPLessThanPredicateOperatorType
options:2];
+
+ [self assertTrue:[pred evaluateWithObject:nil] message:" should be
true"];
+
+}
+
+@end
\ No newline at end of file

Modified: branches/CPRuleEditor/CPRuleEditor.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditor.j (original)
+++ branches/CPRuleEditor/CPRuleEditor.j Tue Oct 21 12:13:45 2008
@@ -22,18 +22,16 @@
CPRuleEditorRowsDidChangeNotification
= "CPRuleEditorRowsDidChangeNotification";
CPRuleEditorRulesDidChangeNotification
= "CPRuleEditorRulesDidChangeNotification";

+var CPRuleEditorNestingMode;
CPRuleEditorNestingModeSingle = 0; // Only a single row is allowed.
Plus/minus buttons will not be shown
CPRuleEditorNestingModeList = 1; // Allows a single list, with no
nesting and no compound rows
CPRuleEditorNestingModeCompound = 2; // Unlimited nesting and compound
rows; this is the default
CPRuleEditorNestingModeSimple = 3; // One compound row at the top with
subrows beneath it, and no further nesting allowed

-var CPRuleEditorNestingMode;
-
+var CPRuleEditorRowType;
CPRuleEditorRowTypeSimple = 0;
CPRuleEditorRowTypeCompound = 1;

-var CPRuleEditorRowType;
-
var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType";

var itemsContext = @"items";
@@ -47,11 +45,11 @@
var elideUpdating = 1;
var lastAlternateKeyValue = 1;
var extendedDelegateCalls = 1;
- var editable = 1;
+ var editable = YES;
var settingSize = 1;
var suppressKeyDown = 1;
var dropWasSuccessful = 1;
- var delegateWantsValidation = 1;
+ var delegateWantsValidation = YES;
var disallowEmpty = 1;
var lastDrewWithFRAppearance = 1;
var allowsEmptyCompoundRows = 1;
@@ -78,7 +76,7 @@

CPTimer _frameTimer;
CPView _slicesHolder;
- CPViewAnimation _currentAnimation;
+ // CPViewAnimation _currentAnimation;

int _lastRow;
int _nestingMode;
@@ -129,16 +127,16 @@

_nestingMode = [coder decodeIntForKey:@"CPRuleEditorNestingMode"];

- _typeKeyPath = [[coder decodeObjectForKey:@"CPRuleEditorRowTypeKeyPath"]
retain];
- _itemsKeyPath = [[coder decodeObjectForKey:@"CPRuleEditorItemsKeyPath"]
retain];
- _valuesKeyPath = [[coder
decodeObjectForKey:@"CPRuleEditorValuesKeyPath"] retain];
- _subrowsArrayKeyPath = [[coder
decodeObjectForKey:@"CPRuleEditorSubrowsArrayKeyPath"] retain];
- _boundArrayKeyPath = [[coder
decodeObjectForKey:@"CPRuleEditorBoundArrayKeyPath"] retain];
+ _typeKeyPath = [coder decodeObjectForKey:@"CPRuleEditorRowTypeKeyPath"];
+ _itemsKeyPath = [coder decodeObjectForKey:@"CPRuleEditorItemsKeyPath"];
+ _valuesKeyPath = [coder decodeObjectForKey:@"CPRuleEditorValuesKeyPath"];
+ _subrowsArrayKeyPath = [coder
decodeObjectForKey:@"CPRuleEditorSubrowsArrayKeyPath"];
+ _boundArrayKeyPath = [coder
decodeObjectForKey:@"CPRuleEditorBoundArrayKeyPath"];

_rowClass = CPClassFromString([coder
decodeObjectForKey:@"CPRuleEditorRowClass"]);
_boundArrayOwner = [coder
decodeObjectForKey:@"CPRuleEditorBoundArrayOwner"];

- _slices = [[coder decodeObjectForKey:@"CPRuleEditorSlices"] retain];
+ _slices = [coder decodeObjectForKey:@"CPRuleEditorSlices"]
// var dragTypes = [coder decodeObjectForKey:@"CPDragTypes"];

[self _initRuleEditorShared];
@@ -204,8 +202,8 @@
_dropLineView = [self _createSliceDropSeparator];

_slicesHolder = [[RuleEditorViewSliceHolder alloc] initWithFrame:[self
bounds]];
- [_slicesHolder setAutoresizingMask:64];
- // [_slicesHolder addSubview:_dropLineView];
+ [_slicesHolder setAutoresizingMask:CPViewHeightSizable |
CPViewWidthSizable];
+ [_slicesHolder addSubview:_dropLineView];
[self addSubview:_slicesHolder];

_boundArrayOwner = [[RuleEditorViewUnboundRowHolder alloc] init];
@@ -307,9 +305,8 @@

- (void)setCriteriaKeyPath:(CPString)value
{
- if (_itemsKeyPath != value) {
+ if (_itemsKeyPath != value)
_itemsKeyPath = value;
- }
}

- (CPString)displayValuesKeyPath
@@ -319,9 +316,8 @@

- (void)setDisplayValuesKeyPath:(CPString)value
{
- if (_valuesKeyPath != value) {
- _valuesKeyPath = [value retain];
- }
+ if (_valuesKeyPath != value)
+ _valuesKeyPath = value;
}

- (CPString)subrowsKeyPath
@@ -331,9 +327,8 @@

- (void)setSubrowsKeyPath:(CPString)value
{
- if (_subrowsArrayKeyPath != value) {
- _subrowsArrayKeyPath = [value retain];
- }
+ if (_subrowsArrayKeyPath != value)
+ _subrowsArrayKeyPath = value;
}

- (CPString)rowTypeKeyPath
@@ -343,9 +338,8 @@

- (void)setRowTypeKeyPath:(CPString)value
{
- if (_typeKeyPath != value) {
- _typeKeyPath = [value retain];
- }
+ if (_typeKeyPath != value)
+ _typeKeyPath = value;
}

- (id)delegate
@@ -600,8 +594,6 @@
[subrows removeObjectsAtIndexes:childsIndexes];
}

-/* KVO & UICHANGES */
-
- (void)addObserver:(CPObject)anObserver forKeyPath:(CPString)keyPath
options:(CPKeyValueObservingOptions)options context:(void)context
{
CPLogConsole(@"addObserver:" + anObserver +" keypath: " + keyPath + "
options:" + options);
@@ -611,16 +603,14 @@
- (void)_setBoundDataSource:(id)datasource withKeyPath:(CPString)keyPath
options:(CPDictionary)options
{
if(_boundArrayOwner)
- {
[_boundArrayOwner removeObserver:self forKeyPath:_boundArrayKeyPath];
- [_boundArrayOwner release];
- }
+
[self setBoundArrayKeyPath:keyPath];

var boundRows = [CPArray arrayWithArray:[datasource valueForKey:keyPath]];

[[datasource valueForKey:keyPath] removeAllObjects];
- _boundArrayOwner = [datasource retain];// retain or not retain the bound
object ?
+ _boundArrayOwner = datasource;

[_boundArrayOwner addObserver:self forKeyPath:_boundArrayKeyPath
options:CPKeyValueObservingOptionOld|CPKeyValueObservingOptionNew
context:boundArrayContext];

@@ -738,8 +728,9 @@

- (id)_insertNewRowAtIndex:(int)insertIndex
ofType:(CPRuleEditorRowType)rowtype withParentRow:(int)parentRowIndex
{
+ CPLogConsole(_cmd);
// why parentRowIndex is not used here ?
- var row = [[[[self rowClass] alloc] init] autorelease];
+ var row = [[[self rowClass] alloc] init];
[row setValue:[CPMutableArray array] forKey:_itemsKeyPath];
[row setValue:[CPMutableArray array] forKey:_valuesKeyPath];
[row setValue:[CPNumber numberWithInt:rowtype] forKey:_typeKeyPath];
@@ -748,6 +739,8 @@
return row;
}

+#pragma mark Key value observing
+
- (void)_startObservingRowObjectsRecursively:(id)rowObjects
{
for(var rowObject in rowObjects)
@@ -779,7 +772,9 @@

- (void)observeValueForKeyPath:(CPString)keypath ofObject:(id)object
change:(CPDictionary)change context:(void)context
{
- CPLogConsole([CPString stringWithFormat:"KVO CHANGE %@ of %@ in
context %d Change:%d\nOld:%@\nNew:%@",keypath,[object
className],context,[[change objectForKey:CPKeyValueChangeKindKey]
intValue],[change objectForKey:CPKeyValueChangeOldKey],[change
objectForKey:CPKeyValueChangeNewKey]]);
+ CPLogConsole(_cmd);
+
+ CPLogConsole([CPString stringWithFormat:"KVO CHANGE %@ of %@ in
context %d Change:%d\nOld:%@\nNew:%@",keypath,[object
className],context,[[change objectForKey:CPKeyValueChangeKindKey]
intValue],[change objectForKey:CPKeyValueChangeOldKey],[change
objectForKey:CPKeyValueChangeNewKey]]);
var changeKind = [[change objectForKey:CPKeyValueChangeKindKey] intValue];
var changeNewValue = [change objectForKey:CPKeyValueChangeNewKey];
var changeOldValue = [change objectForKey:CPKeyValueChangeOldKey];
@@ -913,7 +908,6 @@
[cache setRowIndex:newCacheIndex];
[cache setIndentation:parentCacheindentation + 1];
[_rowCache insertObject:cache atIndex:newCacheIndex];
- [cache release];

if([[obj valueForKey:_itemsKeyPath] count]==0){
var itemsandvalues = [self
_getItemsAndValuesToAddForRow:newRowCacheindex ofType:newRowType];
@@ -982,7 +976,7 @@

- (RuleEditorViewSliceRow)_createNewSliceWithFrame:(CGRect)frame
ruleEditorView:(RuleEditor)editor
{
- var newslice = [[[RuleEditorViewSliceRow alloc] initWithFrame:frame
ruleEditorView:editor] autorelease];
+ var newslice = [[RuleEditorViewSliceRow alloc] initWithFrame:frame
ruleEditorView:editor];
return newslice;
}

@@ -1102,10 +1096,8 @@

- (void)setPredicate:(CPPredicate)value
{
- if (_predicate != value) {
- [_predicate release];
- _predicate = [value retain];
- }
+ if (_predicate != value)
+ _predicate = value;
}

- (void)reloadPredicate
@@ -1121,7 +1113,7 @@
current_index = [subindexes indexGreaterThanIndex:current_index];
}

- var new_predicate = [[[CPCompoundPredicate alloc]
initWithType:CPOrPredicateType subpredicates:subpredicates] autorelease];
+ var new_predicate = [[CPCompoundPredicate alloc]
initWithType:CPOrPredicateType subpredicates:subpredicates];

//[self willChangeValueForKey:@"predicate"];
[self setPredicate:new_predicate];
@@ -1143,12 +1135,14 @@
var displayValueForCriterion =
@selector(ruleEditor:predicatePartsForCriterion:withDisplayValue:inRow:);

if (![_ruleDelegate respondsToSelector:predicatePartsForCriterion])
- { CPLogConsole(@"Delegate doesn't respond to " +
CPStringFromSelector(predicatePartsForCriterion));
+ {
+ CPLogConsole(@"Delegate doesn't respond to " +
CPStringFromSelector(predicatePartsForCriterion));
return NULL;
}

if (![_ruleDelegate respondsToSelector:displayValueForCriterion])
- { [CPException raise:CPInternalInconsistencyException
+ {
+ [CPException raise:CPInternalInconsistencyException
format:@"Delegate doesn't respond to " +
CPStringFromSelector(displayValueForCriterion)];
return NULL;
}
@@ -1188,13 +1182,21 @@
if ([subpredicates count] == 0)
return nil;
else
- {
- compoundPredicate = [[[CPCompoundPredicate alloc ]
initWithType:compoundType subpredicates:subpredicates] autorelease];
-/*
- CPLogConsole(@"Compound predicate error: [%@]\npredicateType:%i",[e
description],compoundType);
- compoundPredicate = NULL;
-*/
- return compoundPredicate;
+ {
+ var error;
+ try
+ {
+ compoundPredicate = [[CPCompoundPredicate alloc ]
initWithType:compoundType subpredicates:subpredicates];
+ }
+ catch(error)
+ {
+ CPLogConsole(@"Compound predicate error: [%@]\npredicateType:%i",[e
description],compoundType);
+ compoundPredicate = NULL;
+ }
+ finally
+ {
+ return compoundPredicate;
+ }

}
}
@@ -1215,7 +1217,10 @@

var predicate;
CPLogConsole(@"lhs: " + lhs + " operator:" + operator + " rhs:" + rhs + "
modifier:" + modifier + " options:" + options + " selector:" + selector);
- // ADD A try directive here. It seems try nested inside statements is
buggy currently.
+
+ var error;
+ try
+ {
if(selector != 0)
predicate = [CPComparisonPredicate
predicateWithLeftExpression:lhs
@@ -1230,12 +1235,16 @@
type:[operator intValue] // CPNumber
options:(options) ? [options
intValue]:CPCaseInsensitivePredicateOption // CPNumber
];
-/*
+ }
+ catch(error)
+ {
CPLogConsole(@"Row predicate error: ["+[e description]+"] For row "+row);
- predicate = nil; // NULL ou FALSEPREDICATE ? That is the question a 2
balles.
-*/
+ predicate = nil;
+ }
+ finally
+ {
return predicate;
-
+ }
}

/* SLICES */
@@ -1441,7 +1450,7 @@

- (void)setFrameSize:(CPSize)size
{
- CPLogConsole(@"setFrameSize:%@",CPStringFromSize(size));
+ CPLogConsole(_cmd);
[super setFrameSize:size];
}

@@ -1467,11 +1476,9 @@

- (void)setFormattingStringsFilename:(CPString)value
{
- if (_stringsFilename != value) {
- [_stringsFilename release];
- _stringsFilename = [value retain];
- }
-}
+ if (_stringsFilename != value)
+ _stringsFilename = value;
+ }

- (void)mouseDragged:(CPEvent)event
{
@@ -1527,8 +1534,8 @@
var theDraggedSliceFrame = CGRectMake(0, firstIndex *_sliceHeight, [self
frame].size.width, (lastIndex - firstIndex + 1) *_sliceHeight);

var pdfData = [self dataWithPDFInsideRect:theDraggedSliceFrame];
- var pdfImage = [[[CPImage alloc] initWithData:pdfData] autorelease];
- var dragImage = [[[CPImage alloc] initWithSize:theDraggedSliceFrame.size]
autorelease];
+ var pdfImage = [[CPImage alloc] initWithData:pdfData];
+ var dragImage = [[CPImage alloc] initWithSize:theDraggedSliceFrame.size];

[dragImage lockFocus];
[pdfImage dissolveToPoint: CPMakePoint(0,0) fraction: .75];

Modified: branches/CPRuleEditor/CPRuleEditorPopupButtonCell.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditorPopupButtonCell.j (original)
+++ branches/CPRuleEditor/CPRuleEditorPopupButtonCell.j Tue Oct 21 12:13:45
2008
@@ -20,13 +20,11 @@
return self;
}

-
- (BOOL)sliceIsEditable
{
var slice = [[self controlView] superview];
return [slice isEditable];
}
-

- (BOOL)trackMouse:(CPEvent)theEvent inRect:(CGRect)cellFrame
ofView:(CPView)controlView untilMouseUp:(BOOL)untilMouseUp
{

Modified: branches/CPRuleEditor/CPRuleEditorViewSliceRow.j
==============================================================================
--- branches/CPRuleEditor/CPRuleEditorViewSliceRow.j (original)
+++ branches/CPRuleEditor/CPRuleEditorViewSliceRow.j Tue Oct 21 12:13:45
2008
@@ -25,12 +25,9 @@
CPButton _subtractButton;
int _rowType;
int _plusButtonRowType;
- struct {
- unsigned int editable:1;
- unsigned int reserved:31;
- } _sliceRowFlags;
+ BOOL editable = YES;
+
id _sliceRowReserved;
-
}

- (id)initWithFrame:(CGRect)frame ruleEditorView:(id)editor
@@ -78,7 +75,6 @@

var buttoncell = [[RuleEditorButtonCell alloc] init];
[button setCell:buttoncell];
- [buttoncell release];

var plus_image = [CPImage imageNamed:CPImageNameAddTemplate];

@@ -96,7 +92,6 @@

var buttoncell = [[RuleEditorButtonCell alloc] init];
[button setCell:buttoncell];
- [buttoncell release];

var minus_image = [CPImage imageNamed:CPImageNameRemoveTemplate];

@@ -111,7 +106,7 @@
- (CPMenuItem )_createMenuItemWithTitle:(CPString )title
{
var loc_title = CPLocalizedStringFromTable(title,[_ruleEditor
formattingStringsFilename],nil);
- return [[[CPMenuItem alloc] initWithTitle:loc_title action:0
keyEquivalent:@""] autorelease];
+ return [[CPMenuItem alloc] initWithTitle:loc_title action:0
keyEquivalent:@""];
}

- (CPPopUpButton )_createPopUpButtonWithItems:(CPArray )itemsArray
selectedItemIndex:(int)index
@@ -119,7 +114,7 @@
// [RuleEditorViewSliceRow _minimumVerticalPopupPadding]
var item;

- var popup = [[[RuleEditorPopupButton alloc] init] autorelease];
+ var popup = [[RuleEditorPopupButton alloc] init];

[popup setFrame:NSMakeRect(0, ([_ruleEditor rowHeight] - [popup
frame].size.height)/2, CONTROL_HEIGHT, 40)];
var menu = [[CPMenu alloc] init];
@@ -130,8 +125,6 @@
[popup setMenu:menu];
[popup selectItemAtIndex:index];
[popup sizeToFit];
-
- [menu release];

return popup;
}

Modified: branches/CPRuleEditor/RuleDelegate.j
==============================================================================
--- branches/CPRuleEditor/RuleDelegate.j (original)
+++ branches/CPRuleEditor/RuleDelegate.j Tue Oct 21 12:13:45 2008
@@ -1,10 +1,10 @@

import <Foundation/Foundation.j>
- import "CPRuleEditor.j"
+import "CPRuleEditor.j"

var CPRuleEditorPredicateKeys = new
Array(CPRuleEditorPredicateLeftExpression,CPRuleEditorPredicateRightExpression,CPRuleEditorPredicateComparisonModifier,CPRuleEditorPredicateOptions,CPRuleEditorPredicateOperatorType,CPRuleEditorPredicateCustomSelector,CPRuleEditorPredicateCompoundType);

-@implementation CPDictionary (Additions)
+@implementation CPDictionary (ReadFile)

+(id)dictionaryWithContentsOfURL:(CPURL)url
{
@@ -22,9 +22,27 @@

@end

+@implementation CPArray (ReadFile)
+
++(id)arrayWithContentsOfURL:(CPURL)url
+{
+
+ var request = [CPURLRequest requestWithURL:url];
+ var data = [CPURLConnection sendSynchronousRequest:request
returningResponse:NULL error:NULL];
+ if(data)
+ {
+ var array = [CPPropertyListSerialization propertyListFromData:data
format:CPPropertyListXMLFormat_v1_0 errorDescription:NULL];
+ return array;
+ }
+
+ return nil;
+}
+
+@end
+
@implementation RuleDelegate : CPObject
{
-CPDictionary rows;
+ CPDictionary rows;
}

- (id)init
@@ -84,7 +102,7 @@
if(view == nil)
{
var custom_class = CPClassFromString(custom_control_class);
- view = [[[custom_class alloc] initWithFrame:CGZeroRect] autorelease];
+ view = [[custom_class alloc] initWithFrame:CGZeroRect];

[criterion setObject:view forKey:viewkey];
}

Modified: branches/CPRuleEditor/index.html
==============================================================================
--- branches/CPRuleEditor/index.html (original)
+++ branches/CPRuleEditor/index.html Tue Oct 21 12:13:45 2008
@@ -14,13 +14,13 @@
-->
<head>

- <title>Hello World</title>
+ <title>CPRuleEditor</title>

<script src = "Frameworks/Objective-J/Objective-J.js" type
= "text/javascript"></script>

<script type = "text/javascript">

- objj_import("main.j", YES, function() { main();
});OBJJ_EXCEPTION_OUTPUT_STREAM = console.error;
+ objj_import("main.j", YES, function() { main(); });
</script>

</head>

Modified: branches/CPRuleEditor/main.j
==============================================================================
--- branches/CPRuleEditor/main.j (original)
+++ branches/CPRuleEditor/main.j Tue Oct 21 12:13:45 2008
@@ -3,6 +3,14 @@

import "AppController.j"

+@implementation CPString (description)
+
+-(CPString)description{
+ return self;
+}
+
+@end
+
function main(args, namedArgs)
{
CPApplicationMain(args, namedArgs);
Reply all
Reply to author
Forward
0 new messages