mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
Fixed: support for dates (CPDatePicker) in CPPredicateEditor
Before this commit, row templates and views belo,ging to them were copied via archiving/unarchiving. This was causing problems when the view was not completely CPCoding compliant, like for CPDatePicker. With this commit, template views use CPCopying (-copy method) when available. Also added CPCopying for CPDatePicker as a category in CPPredicateEditor. Test: in CPPredicateEditorTest, on the right panel, choose a keypath, operator, and select 'Dates' in the popup for the right expression. Fixes #2041
This commit is contained in:
@@ -27,8 +27,7 @@
|
||||
@import "CPMenuItem.j"
|
||||
@import "CPTextField.j"
|
||||
|
||||
// NOTE: CPDatePicker is not implemented yet
|
||||
@class CPDatePicker
|
||||
@import "CPDatePicker.j"
|
||||
|
||||
|
||||
CPUndefinedAttributeType = 0;
|
||||
@@ -488,7 +487,36 @@ CPTransformableAttributeType = 1800;
|
||||
|
||||
- (id)copy
|
||||
{
|
||||
return [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:self]];
|
||||
var views = [CPArray array];
|
||||
|
||||
var copy = [[[self class] alloc] init];
|
||||
[copy _setTemplateType:_templateType];
|
||||
[copy _setOptions:_predicateOptions];
|
||||
[copy _setModifier:_predicateModifier];
|
||||
[copy _setLeftAttributeType:_leftAttributeType];
|
||||
[copy _setRightAttributeType:_rightAttributeType];
|
||||
[copy setLeftIsWildcard:_leftIsWildcard];
|
||||
[copy setRightIsWildcard:_rightIsWildcard];
|
||||
|
||||
[_views enumerateObjectsUsingBlock:function(aView, idx, stop)
|
||||
{
|
||||
var vcopy;
|
||||
|
||||
if ([aView implementsSelector:@selector(copy)])
|
||||
{
|
||||
vcopy = [aView copy];
|
||||
}
|
||||
else
|
||||
{
|
||||
vcopy = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:aView]];
|
||||
}
|
||||
|
||||
[views addObject:vcopy];
|
||||
}];
|
||||
|
||||
[copy setTemplateViews:views];
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
+ (id)_operatorsForAttributeType:(CPAttributeType)attributeType
|
||||
@@ -680,7 +708,7 @@ CPTransformableAttributeType = 1800;
|
||||
view = [[CPCheckBox alloc] initWithFrame:CGRectMake(0, 0, 50, 26)];
|
||||
}
|
||||
else if (attributeType == CPDateAttributeType)
|
||||
view = [[CPDatePicker alloc] initWithFrame:CGRectMake(0, 0, 150, 26)];
|
||||
view = [[CPDatePicker alloc] initWithFrame:CGRectMake(0, 0, 180, 26)];
|
||||
else
|
||||
return nil;
|
||||
|
||||
@@ -797,5 +825,31 @@ var CPPredicateTemplateTypeKey = @"CPPredicateTemplateType",
|
||||
[coder encodeObject:_views forKey:CPPredicateTemplateViewsKey];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// Copy support for built-in types
|
||||
@implementation CPDatePicker (CPCopying)
|
||||
|
||||
- (id)copy
|
||||
{
|
||||
var ret = [[[self class] alloc] initWithFrame:[self frame]];
|
||||
|
||||
[ret setTextFont:[self textFont]];
|
||||
[ret setMinDate:[self minDate]];
|
||||
[ret setMaxDate:[self maxDate]];
|
||||
[ret setTimeInterval:[self timeInterval]];
|
||||
[ret setDatePickerMode:[self datePickerMode]];
|
||||
[ret setDatePickerElements:[self datePickerElements]];
|
||||
[ret setDatePickerStyle:[self datePickerStyle]];
|
||||
[ret setLocale:[self locale]];
|
||||
[ret setDateValue:[self dateValue]];
|
||||
[ret setBackgroundColor:[self backgroundColor]];
|
||||
[ret setDrawsBackground:[self drawsBackground]];
|
||||
[ret setBordered:[self isBordered]];
|
||||
[ret _init];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@end
|
||||
/*! @endcond */
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
{
|
||||
CPWindow window;
|
||||
CPPredicateEditor predicateEditor;
|
||||
|
||||
|
||||
CPTableView leftTable;
|
||||
CPTableView rightTable;
|
||||
CPPopUpButton rightExpressionsType;
|
||||
@@ -28,7 +28,7 @@
|
||||
+ (void)initialize
|
||||
{
|
||||
var transformer = [[PredicateTransformer alloc] init];
|
||||
[CPValueTransformer setValueTransformer:transformer forName:@"PredicateTransformer"];
|
||||
[CPValueTransformer setValueTransformer:transformer forName:@"PredicateTransformer"];
|
||||
}
|
||||
|
||||
- (void)awakeFromCib
|
||||
@@ -109,7 +109,7 @@
|
||||
template = [[CPPredicateEditorRowTemplate alloc] initWithLeftExpressions:leftExpressions rightExpressionAttributeType:CPStringAttributeType modifier:0 operators:operators options:0];
|
||||
else if (type == 1)
|
||||
template = [[CPPredicateEditorRowTemplate alloc] initWithLeftExpressions:leftExpressions rightExpressionAttributeType:CPInteger16AttributeType modifier:0 operators:operators options:0];
|
||||
else if (type ==2)
|
||||
else if (type == 2)
|
||||
{
|
||||
var rightExpressions = [CPMutableArray array],
|
||||
count = [rightConstants count];
|
||||
@@ -121,6 +121,8 @@
|
||||
|
||||
template = [[CPPredicateEditorRowTemplate alloc] initWithLeftExpressions:leftExpressions rightExpressions:rightExpressions modifier:0 operators:operators options:0];
|
||||
}
|
||||
else if (type == 3)
|
||||
template = [[CPPredicateEditorRowTemplate alloc] initWithLeftExpressions:leftExpressions rightExpressionAttributeType:CPDateAttributeType modifier:0 operators:operators options:0];
|
||||
|
||||
var templates = [[predicateEditor rowTemplates] arrayByAddingObject:template];
|
||||
[predicateEditor setRowTemplates:templates];
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user