Commits

Tuukka Norri committed e02ae9d

Fixed bugs

Comments (0)

Files changed (2)

BaseTenAppKit/Sources/BXMultipleChoicePredicateEditorRowTemplate.mm

 	Expect (optionDisplayNameKeyPath);
 	Expect (displayName);
 	
-	NSMutableArray *initialLeftExpressions = [NSMutableArray arrayWithCapacity: [options count]];
-	for (BXDatabaseObject *object in options)
-		[initialLeftExpressions addObject: [NSExpression expressionForConstantValue: object]];
-	
 	id operators [] = {
 		ObjectValue <NSPredicateOperatorType> (NSEqualToPredicateOperatorType),
 		ObjectValue <NSPredicateOperatorType> (NSNotEqualToPredicateOperatorType)
 	};
 	
-	if ((self = [super initWithLeftExpressions: initialLeftExpressions 
+	if ((self = [super initWithLeftExpressions: [NSArray array] 
 							  rightExpressions: [NSArray arrayWithObject: rightExpression]
 									  modifier: modifier
 									 operators: [NSArray arrayWithObjects: operators count: BXArraySize (operators)]
 		[self setDisplayName: displayName];
 		[self setOptionDisplayNameKeyPath: optionDisplayNameKeyPath];
 		[self setOptionObjects: options];
-		[self addObserver: self forKeyPath: @"optionObjects" options: 0 context: kKVOCtx];
+		[self addObserver: self forKeyPath: @"optionObjects" options: NSKeyValueObservingOptionInitial context: kKVOCtx];
 	}
 	return self;
 }
 {
 	NSArray *retval = [super templateViews];
 	
-	[[[[retval objectAtIndex: 0] itemArray] objectAtIndex: 0] setTitle: mDisplayName];
-	for (NSMenuItem* item in [[retval objectAtIndex: 2] itemArray])
+	[[[[retval objectAtIndex: 2] itemArray] objectAtIndex: 0] setTitle: mDisplayName];
+	for (NSMenuItem* item in [[retval objectAtIndex: 0] itemArray])
 	{
 		BXDatabaseObject *optionValue = [[item representedObject] constantValue];
 		[item setTitle: [optionValue valueForKeyPath: mOptionDisplayNameKeyPath]];

BaseTenAppKit/Sources/BXPredicateEditorRowTemplateFactory.mm

 	NSDictionary *optionDisplayNameKeyPathsByRelKeyPath = [NSDictionary dictionaryWithObjects: displayNameKeyPaths forKeys: keyPaths];
 	NSMutableDictionary *sortedKeyPaths = [NSMutableDictionary dictionary];
 	
-	for (NSString *keyPath in sortedKeyPaths)
+	for (NSString *keyPath in keyPaths)
 	{
 		BXEntityDescription *currentEntity = originalEntity;
 		NSComparisonPredicateModifier modifier = NSDirectPredicateModifier;
 	NSMutableArray *templates = [NSMutableArray array];
 	for (BXEntityDescription *entity in sortedKeyPaths)
 	{
-		BXRelationshipKeyPathValue *val = [sortedKeyPaths objectForKey: entity];
-		NSString *keyPath = [val keyPath];
-		NSComparisonPredicateModifier modifier = [val modifier];
-		NSExpression *rightExpression = [NSExpression expressionForKeyPath: keyPath];
-		NSString *optionDisplayNameKeyPath = [optionDisplayNameKeyPathsByRelKeyPath objectForKey: keyPath];
-		NSString *displayName = [displayNamesByRelKeyPath objectForKey: keyPath];
-		
 		id res = [ctx executeFetchForEntity: entity 
 							  withPredicate: nil 
 							returningFaults: NO 
 		if (! res)
 			goto bail;
 		
-		BXMultipleChoicePredicateEditorRowTemplate *rowTemplate = nil;
-		rowTemplate = [[BXMultipleChoicePredicateEditorRowTemplate alloc] initWithLeftExpressionOptions: res
-																						rightExpression: rightExpression
-																			   optionDisplayNameKeyPath: optionDisplayNameKeyPath
-																			 rightExpressionDisplayName: displayName
-																							   modifier: modifier];
-		
-		[templates addObject: rowTemplate];
-		[rowTemplate release];
+		for (BXRelationshipKeyPathValue *val in [sortedKeyPaths objectForKey: entity])
+		{
+			NSString *keyPath = [val keyPath];
+			NSComparisonPredicateModifier modifier = [val modifier];
+			NSExpression *rightExpression = [NSExpression expressionForKeyPath: keyPath];
+			NSString *optionDisplayNameKeyPath = [optionDisplayNameKeyPathsByRelKeyPath objectForKey: keyPath];
+			NSString *displayName = [displayNamesByRelKeyPath objectForKey: keyPath];		
+			
+			BXMultipleChoicePredicateEditorRowTemplate *rowTemplate = nil;
+			rowTemplate = [[BXMultipleChoicePredicateEditorRowTemplate alloc] initWithLeftExpressionOptions: res
+																							rightExpression: rightExpression
+																				   optionDisplayNameKeyPath: optionDisplayNameKeyPath
+																				 rightExpressionDisplayName: displayName
+																								   modifier: modifier];
+			
+			[templates addObject: rowTemplate];
+			[rowTemplate release];			
+		}
 	}
 	
 	retval = [[templates copy] autorelease];