Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMRuleEditorDelegate.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 348 - (hide annotations) (download)
Sun May 9 01:25:25 2010 UTC (13 years, 11 months ago) by masakih
File size: 5427 byte(s)
XspfMRule関連をごっそり変更。
1 masaki 120 //
2     // XspfMRuleEditorDelegate.m
3     // XspfManager
4     //
5     // Created by Hori,Masaki on 09/11/28.
6     // Copyright 2009 masakih. All rights reserved.
7     //
8    
9     #import "XspfMRuleEditorDelegate.h"
10    
11 masakih 348 #import "XspfMRule.h"
12     #import "XspfMRuleRowsBuilder.h"
13     #import "XspfMRuleRowTemplate.h"
14 masaki 120
15     @implementation XspfMRuleEditorDelegate
16 masaki 125
17     static NSString *XspfMREDPredicateRowsKey = @"predicateRows";
18    
19 masakih 348 + (void)initialize
20 masaki 124 {
21 masakih 348 static BOOL isFirst = YES;
22     if(isFirst) {
23     isFirst = NO;
24     [XspfMRule registerStringTypeKeyPaths:[NSArray arrayWithObjects:@"title", @"information.voiceActorsList", @"information.productsList", nil]];
25     [XspfMRule registerDateTypeKeyPaths:[NSArray arrayWithObjects:@"lastPlayDate", @"modificationDate", @"creationDate", nil]];
26     [XspfMRule setUseRating:YES];
27     [XspfMRule setUseLablel:YES];
28 masaki 124 }
29     }
30 masaki 126
31 masaki 120 - (void)awakeFromNib
32     {
33 masakih 348 NSBundle *mainBundle = [NSBundle mainBundle];
34     NSString *templatePath = [mainBundle pathForResource:@"LibraryRowTemplate" ofType:@"plist"];
35     rowTemplate = [[XspfMRuleRowTemplate rowTemplateWithPath:templatePath] retain];
36 masaki 124
37     NSMutableArray *newRows = [NSMutableArray array];
38 masaki 338 for(id keyPath in [XspfMRule leftKeys]) {
39 masakih 348 id c = [rowTemplate criteriaForKeyPath:keyPath];
40 masaki 126 if(c) [newRows addObjectsFromArray:c];
41 masaki 124 }
42 masaki 243
43 masaki 152 simples = [newRows retain];
44 masaki 166 compounds = [[XspfMRule compoundRule] retain];
45 masaki 152
46 masaki 125 predicateRows = [[NSMutableArray alloc] init];
47 masaki 159 [ruleEditor bind:@"rows" toObject:self withKeyPath:XspfMREDPredicateRowsKey options:nil];
48 masaki 120 }
49 masakih 348 - (void)dealloc
50 masaki 150 {
51 masakih 348 [ruleEditor unbind:@"rows"];
52     [simples release];
53     [compounds release];
54     [predicateRows release];
55     [rowTemplate release];
56 masaki 150
57 masakih 348 [super dealloc];
58 masaki 150 }
59    
60 masakih 348 - (void)setPredicateRows:(id)p
61 masaki 123 {
62 masakih 348 if([predicateRows isEqual:p]) return;
63 masaki 123
64 masaki 125 [predicateRows release];
65 masakih 348 predicateRows = [p retain];
66 masaki 123 }
67 masakih 348 - (void)setPredicate:(id)predicate
68 masaki 125 {
69 masakih 348 XspfMRuleRowsBuilder *builder = [XspfMRuleRowsBuilder builderWithPredicate:predicate];
70     builder.rowTemplate = rowTemplate;
71     [builder build];
72     id new = [builder rows];
73    
74     [self setPredicateRows:new];
75 masaki 125 }
76    
77     #pragma mark#### NSRleEditor Delegate ####
78 masaki 152
79 masaki 124 - (NSInteger)ruleEditor:(NSRuleEditor *)editor
80     numberOfChildrenForCriterion:(id)criterion
81     withRowType:(NSRuleEditorRowType)rowType
82     {
83     NSInteger result = 0;
84    
85     if(!criterion) {
86 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
87     result = [compounds count];
88     } else {
89     result = [simples count];
90     }
91 masaki 143 } else {
92 masaki 152 result = [criterion numberOfChildren];
93 masaki 124 }
94    
95     return result;
96     }
97    
98     - (id)ruleEditor:(NSRuleEditor *)editor
99     child:(NSInteger)index
100     forCriterion:(id)criterion
101     withRowType:(NSRuleEditorRowType)rowType
102     {
103     id result = nil;
104    
105     if(!criterion) {
106 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
107     result = [compounds objectAtIndex:index];
108     } else {
109     result = [simples objectAtIndex:index];
110     }
111 masaki 143 } else {
112 masaki 152 result = [criterion childAtIndex:index];
113 masaki 124 }
114 masakih 348
115 masaki 124 return result;
116     }
117     - (id)ruleEditor:(NSRuleEditor *)editor
118     displayValueForCriterion:(id)criterion
119     inRow:(NSInteger)row
120     {
121 masakih 348 id result = [criterion displayValueForRuleEditor:editor inRow:row];
122 masaki 143
123 masaki 124 return result;
124     }
125     - (NSDictionary *)ruleEditor:(NSRuleEditor *)editor
126     predicatePartsForCriterion:(id)criterion
127     withDisplayValue:(id)displayValue
128     inRow:(NSInteger)row
129     {
130 masakih 348 id result = [criterion predicatePartsWithDisplayValue:displayValue forRuleEditor:editor inRow:row];
131 masaki 124
132     return result;
133     }
134     - (void)ruleEditorRowsDidChange:(NSNotification *)notification
135     {
136     //
137     }
138 masakih 348
139     #pragma mark---- Debugging ----
140     - (void)resolveExpression:(id)exp
141     {
142     NSString *message = nil;
143    
144     switch([exp expressionType]) {
145     case NSConstantValueExpressionType:
146     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
147     break;
148     case NSEvaluatedObjectExpressionType:
149     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
150     break;
151     case NSVariableExpressionType:
152     message = [NSString stringWithFormat:@"variable -> %@", [exp variable]];
153     break;
154     case NSKeyPathExpressionType:
155     message = [NSString stringWithFormat:@"keyPath -> %@", [exp keyPath]];
156     break;
157     case NSFunctionExpressionType:
158     message = [NSString stringWithFormat:@"oprand -> %@(%@), function -> %@, arguments -> %@",
159     [exp operand], NSStringFromClass([[exp operand] class]),
160     [exp function], [exp arguments]];
161     break;
162     case NSAggregateExpressionType:
163     message = [NSString stringWithFormat:@"collection -> %@", [exp collection]];
164     break;
165     }
166    
167     fprintf(stderr, "%s\n", [message UTF8String]);
168     }
169     - (void)resolvePredicate:(id)predicate
170     {
171     if([predicate isKindOfClass:[NSCompoundPredicate class]]) {
172     NSArray *sub = [predicate subpredicates];
173     for(id p in sub) {
174     [self resolvePredicate:p];
175     }
176     } else if([predicate isKindOfClass:[NSComparisonPredicate class]]) {
177     id left = [predicate leftExpression];
178     id right = [predicate rightExpression];
179     SEL sel = Nil;
180     if([predicate predicateOperatorType] == NSCustomSelectorPredicateOperatorType) {
181     sel = [predicate customSelector];
182     }
183     fprintf(stderr, "left ->\t");
184     [self resolveExpression:left];
185     if(sel) {
186     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"SEL -> %@", NSStringFromSelector(sel)] UTF8String]);
187     } else {
188     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"type -> %d, opt -> %d, mod -> %d", [predicate predicateOperatorType], [predicate options], [predicate comparisonPredicateModifier]] UTF8String]);
189     }
190     fprintf(stderr, "right ->\t");
191     [self resolveExpression:right];
192     fprintf(stderr, "end resolve.\n");
193     }
194     }
195 masaki 150 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26