-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataStoreObject.m
782 lines (619 loc) · 20 KB
/
DataStoreObject.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
/* Copyright (c) 2010 Per Johansson, per at morth.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "DataStoreObject.h"
#import "DataStore.h"
#import "base64.h"
#import "erf.h"
/* XXX layering violation */
#import "AddInsList.h"
@implementation DataStoreObject
@dynamic node;
- (void)awakeFromFetch
{
[super awakeFromFetch];
DataStore *store = (DataStore*)[[self objectID] persistentStore];
self.node = [[[store cacheNodeForObjectID:[self objectID]] propertyCache] objectForKey:@"node"];
}
@end
@implementation Path
@dynamic contents;
@dynamic modazipin;
@dynamic path;
@dynamic type;
@dynamic verified;
static NSPredicate *isERF;
- (NSMutableDictionary*)dataForContents:(NSArray*)contents
{
NSMutableDictionary *res = [NSMutableDictionary dictionaryWithCapacity:[contents count]];
/* XXX layering violation */
NSURL *url = [[[AddInsList sharedAddInsList] fileURL] URLByAppendingPathComponent:self.path];
NSDirectoryEnumerator *enumer = [[NSFileManager defaultManager] enumeratorAtURL:url includingPropertiesForKeys:nil options:0 errorHandler:^(NSURL *u, NSError *error) { return YES; }];
NSURL *item;
NSArray *keys = [NSArray arrayWithObjects:NSURLNameKey, NSURLIsRegularFileKey, nil];
if (!isERF)
isERF = [NSPredicate predicateWithFormat:@"SELF MATCHES[c] '\\.[ce]rf'"];
while ((item = [enumer nextObject]))
{
NSDictionary *props = [item resourceValuesForKeys:keys error:nil];
if (![[props objectForKey:NSURLIsRegularFileKey] boolValue])
continue;
NSString *name = [props objectForKey:NSURLNameKey];
if ([contents indexOfObject:name] != NSNotFound)
[res setObject:[NSData dataWithContentsOfURL:item] forKey:name];
else if ([isERF evaluateWithObject:name])
{
NSData *erfdata = [NSData dataWithContentsOfURL:item options:NSDataReadingMapped error:nil];
parse_erf_data([erfdata bytes], [erfdata length], ^(struct erf_header *header, struct erf_file *file)
{
if (!file->name)
return;
NSString *n = [NSString stringWithCString:file->name encoding:NSASCIIStringEncoding];
if ([n caseInsensitiveCompare:name] == NSOrderedSame)
[res setObject:[NSData dataWithBytes:(void*)file->data length:file->length] forKey:name];
});
}
}
return res;
}
@end
@interface Modazipin (CoreDataGeneratedPrimitiveAccessors)
- (NSMutableSet*)primitivePaths;
- (void)setPrimitivePaths:(NSMutableSet*)value;
@end
@implementation Modazipin
@dynamic item;
@dynamic paths;
@dynamic origGameVersion;
- (void)addPathNodes:(NSSet*)paths
{
if (!self.node)
return;
NSXMLElement *node = [[(NSXMLElement*)self.node elementsForName:@"paths"] objectAtIndex:0];
if (!node)
{
node = [NSXMLElement elementWithName:@"paths"];
[(NSXMLElement*)self.node addChild:node];
}
for (Path *p in paths)
{
NSXMLElement *pnode = [NSXMLElement elementWithName:p.type];
[pnode addAttribute:[NSXMLNode attributeWithName:@"path" stringValue:p.path]];
[node addChild:pnode];
p.node = pnode;
}
}
- (void)addPathsObject:(Path *)value
{
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"paths" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[[self primitivePaths] addObject:value];
[self didChangeValueForKey:@"paths" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[self addPathNodes:changedObjects];
}
- (void)addPaths:(NSSet *)value
{
[self addPathNodes:value];
[self willChangeValueForKey:@"paths" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
[[self primitivePaths] unionSet:value];
[self didChangeValueForKey:@"paths" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
}
@end
@implementation LocalizedText
@dynamic langcode;
@dynamic value;
@end
@implementation Text
@dynamic DefaultText;
@dynamic languages;
@dynamic item;
@dynamic localizedValue;
- (void)updateLocalizedValue:(NSNotification*)notice
{
/* XXX I should probably use a fetch request, but it is a bit of a bother right now. */
NSPredicate *equalTmpl = [NSPredicate predicateWithFormat:@"langcode == $code"];
NSPredicate *beginTmpl = [NSPredicate predicateWithFormat:@"langcode beginswith[c] $code"];
NSString *value = nil;
NSSet *available = [self languages];
for (NSString *lang in [NSLocale preferredLanguages])
{
NSSet *found = [available filteredSetUsingPredicate:[equalTmpl predicateWithSubstitutionVariables:[NSDictionary dictionaryWithObject:lang forKey:@"code"]]];
if ([found count])
{
value = [[found anyObject] valueForKey:@"value"];
break;
}
found = [available filteredSetUsingPredicate:[beginTmpl predicateWithSubstitutionVariables:[NSDictionary dictionaryWithObject:lang forKey:@"code"]]];
if ([found count])
{
value = [[found anyObject] valueForKey:@"value"];
break;
}
NSRange usc = [lang rangeOfString:@"_"];
if (usc.location == NSNotFound)
continue;
NSString *prefix = [lang substringToIndex:usc.location];
found = [available filteredSetUsingPredicate:[equalTmpl predicateWithSubstitutionVariables:[NSDictionary dictionaryWithObject:prefix forKey:@"code"]]];
if ([found count])
{
value = [[found anyObject] valueForKey:@"value"];
break;
}
found = [available filteredSetUsingPredicate:[beginTmpl predicateWithSubstitutionVariables:[NSDictionary dictionaryWithObject:prefix forKey:@"code"]]];
if ([found count])
{
value = [[found anyObject] valueForKey:@"value"];
break;
}
}
if (!value)
value = self.DefaultText;
if (![value isEqualToString:self.localizedValue])
{
self.localizedValue = value;
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"languages"])
[self updateLocalizedValue:nil];
}
- (void)listenForLocalizedValue
{
[self updateLocalizedValue:nil];
[self addObserver:self forKeyPath:@"languages" options:NSKeyValueChangeSetting | NSKeyValueChangeInsertion | NSKeyValueChangeRemoval | NSKeyValueChangeReplacement context:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateLocalizedValue:) name:NSCurrentLocaleDidChangeNotification object:nil];
}
- (void)didTurnIntoFault
{
[self removeObserver:self forKeyPath:@"languages"];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSCurrentLocaleDidChangeNotification object:nil];
}
- (void)awakeFromInsert
{
[super awakeFromInsert];
[self listenForLocalizedValue];
}
- (void)awakeFromFetch
{
[super awakeFromFetch];
[self listenForLocalizedValue];
}
@end
@implementation Item
@dynamic BioWare;
@dynamic Enabled;
@dynamic ExtendedModuleUID;
@dynamic Format;
@dynamic GameVersion;
@dynamic Image;
@dynamic Name;
@dynamic Price;
@dynamic Priority;
@dynamic ReleaseDate;
@dynamic Size;
@dynamic Type;
@dynamic UID;
@dynamic Version;
@dynamic Description;
@dynamic modazipin;
@dynamic Publisher;
@dynamic Rating;
@dynamic RatingDescription;
@dynamic Title;
@dynamic URL;
@dynamic displayed;
@dynamic missingFiles;
+ (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString *)key
{
NSSet *res = [super keyPathsForValuesAffectingValueForKey:key];
if ([key isEqualToString:@"hasConfigSections"])
res = [res setByAddingObject:@"configSections"];
return res;
}
- (NSMutableString*)replaceProperties:(NSMutableString*)str
{
NSEntityDescription *textEntity = [NSEntityDescription entityForName:@"Text" inManagedObjectContext:[self managedObjectContext]];
for (NSPropertyDescription *prop in [self entity])
{
NSString *repFrom = [NSString stringWithFormat:@"%%%@%%", [prop name]];
NSString *repTo = nil;
NSString *secStart = [NSString stringWithFormat:@"%%?%@%%", [prop name]];
NSString *secEnd = [NSString stringWithFormat:@"%%!%@%%", [prop name]];
if ([[prop class] isSubclassOfClass:[NSRelationshipDescription class]])
{
NSRelationshipDescription *rel = (NSRelationshipDescription*)prop;
if ([rel isToMany])
{
NSSet *set = [self valueForKey:[prop name]];
if ([set count])
repTo = [[NSNumber numberWithInteger:[set count]] stringValue];
else
repTo = @"";
}
else if ([rel destinationEntity] == textEntity)
{
Text *t = [self valueForKey:[prop name]];
if (t)
{
[t updateLocalizedValue:nil];
repTo = [t localizedValue];
}
else
repTo = @"";
}
else
{
id v = [self valueForKey:[prop name]];
if (v)
repTo = @"1";
else
repTo = @"";
}
}
else if ([[prop class] isSubclassOfClass:[NSFetchedPropertyDescription class]])
{
NSArray *arr = [self valueForKey:[prop name]];
if ([arr count])
{
NSString *repPath = [[prop userInfo] objectForKey:@"repPath"];
if (repPath)
repTo = [[arr objectAtIndex:0] valueForKey:repPath];
else
repTo = [[NSNumber numberWithInteger:[arr count]] stringValue];
}
else
repTo = @"";
}
else
{
NSAttributeDescription *attr = (NSAttributeDescription*)prop;
switch ([attr attributeType])
{
case NSStringAttributeType:
repTo = [self valueForKey:[prop name]];
if (!repTo)
repTo = @"";
break;
case NSDecimalAttributeType:
case NSBooleanAttributeType:
if ([[self valueForKey:[prop name]] boolValue])
repTo = [[self valueForKey:[prop name]] stringValue];
else
repTo = @"";
break;
case NSBinaryDataAttributeType:
{
NSData *data = [self valueForKey:[prop name]];
repTo = [data base64];
}
break;
}
}
if (repTo)
{
[str replaceOccurrencesOfString:repFrom withString:repTo options:0 range:NSMakeRange(0, [str length])];
if ([repTo length])
{
[str replaceOccurrencesOfString:secStart withString:@"" options:0 range:NSMakeRange(0, [str length])];
[str replaceOccurrencesOfString:secEnd withString:@"" options:0 range:NSMakeRange(0, [str length])];
}
else
{
while (1)
{
NSRange rs = [str rangeOfString:secStart];
NSRange re = [str rangeOfString:secEnd];
if (rs.location == NSNotFound || re.location == NSNotFound || re.location < rs.location)
break;
rs.length = re.location + re.length - rs.location;
[str deleteCharactersInRange:rs];
}
}
}
}
NSString *secStart = [NSString stringWithFormat:@"%%?%@%%", [[self entity] name]];
NSString *secEnd = [NSString stringWithFormat:@"%%!%@%%", [[self entity] name]];
[str replaceOccurrencesOfString:secStart withString:@"" options:0 range:NSMakeRange(0, [str length])];
[str replaceOccurrencesOfString:secEnd withString:@"" options:0 range:NSMakeRange(0, [str length])];
while (1)
{
NSRange rs = [str rangeOfString:@"%?"];
if (rs.location == NSNotFound)
break;
while ([str characterAtIndex:rs.location + rs.length] != '%')
rs.length++;
secEnd = [NSString stringWithFormat:@"%%!%@", [str substringWithRange:NSMakeRange(rs.location + 2, rs.length - 1)]];
NSRange re = [str rangeOfString:secEnd];
if (re.location == NSNotFound || re.location < rs.location)
{
NSLog(@"didn't find %@ to match %@", secEnd, [str substringWithRange:rs]);
break;
}
rs.length = re.location + re.length - rs.location;
[str deleteCharactersInRange:rs];
}
return str;
}
- (NSMutableAttributedString *)infoAttributedString
{
if (cachedInfo)
return cachedInfo;
NSURL *infoURL = [[NSBundle mainBundle] URLForResource:@"ItemInfo" withExtension:@"rtfd"];
if (!infoURL)
return nil;
cachedInfo = [[NSMutableAttributedString alloc] initWithURL:infoURL documentAttributes:nil];
if (!cachedInfo)
return nil;
[self replaceProperties:[cachedInfo mutableString]];
return cachedInfo;
}
- (NSMutableString *)detailsHTML
{
if (cachedDetails)
return cachedDetails;
NSURL *detailsURL = [[NSBundle mainBundle] URLForResource:@"ItemDetails" withExtension:@"html"];
if (!detailsURL)
return nil;
cachedDetails = [NSMutableString stringWithContentsOfURL:detailsURL encoding:NSUTF8StringEncoding error:nil];
if (!cachedDetails)
return nil;
return [self replaceProperties:cachedDetails];
}
- (NSMutableString*)galleryHTMLWithContents:(NSDictionary**)outContents
{
NSError *err = nil;
NSFetchRequest *req = [[[self entity] managedObjectModel] fetchRequestFromTemplateWithName:@"contentsOfTypeForItem" substitutionVariables:[NSDictionary dictionaryWithObjectsAndKeys:@".dds", @"type", self, @"item", nil]];
NSArray *images = [[self managedObjectContext] executeFetchRequest:req error:&err];
NSMutableString *res = [NSMutableString stringWithString:@"<html><body style='color: #b7a266;'>"];
/*XXX NSMapTable*/NSMutableDictionary *pcmap = [NSMutableDictionary dictionary];
for (NSManagedObject *image in images)
{
Path *p = [image valueForKey:@"path"];
NSString *name = [image valueForKey:@"name"];
NSMutableArray *a = [pcmap objectForKey:p.path];
if (a)
[a addObject:name];
else
[pcmap setObject:[NSMutableArray arrayWithObjects:p, name, nil] forKey:p.path];
}
for (NSString *path in [pcmap allKeys])
{
NSMutableArray *a = [pcmap objectForKey:path];
NSMutableDictionary *cm = [NSMutableDictionary dictionary];
Path *p = [a objectAtIndex:0];
[a removeObjectAtIndex:0];
NSMutableDictionary *imgdata = [p dataForContents:[pcmap objectForKey:p]];
[imgdata enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop)
{
[cm setObject:obj forKey:key];
[res appendFormat:@"<img style='max-width: 340px' src='content:%@'/><br/>", key];
}];
*outContents = [NSDictionary dictionaryWithDictionary:cm];
}
[res appendString:@"</body></html>"];
return res;
}
- (void)didTurnIntoFault
{
[super didTurnIntoFault];
cachedInfo = nil;
cachedDetails = nil;
}
- (void)updateInfo
{
cachedDetails = nil;
cachedInfo = nil;
[self willChangeValueForKey:@"infoAttributedString"];
[self infoAttributedString];
[self didChangeValueForKey:@"infoAttributedString"];
#if 0
/* Slow and unnecessary. */
[self willChangeValueForKey:@"detailsHTML"];
[self detailsHTML];
[self didChangeValueForKey:@"detailsHTML"];
#endif
}
- (void)updateConfigView
{
if (!configView)
{
configView = [[NSView alloc] initWithFrame:(NSRect){{0, 0}, {0, 0}}];
[self addObserver:self forKeyPath:@"configSections" options:0 context:nil];
}
NSSet *sections = [self valueForKey:@"configSections"];
/* Sort reverse to get index 0 at top. */
NSArray *sortedSections = [[sections allObjects] sortedArrayUsingComparator:^NSComparisonResult(id a, id b)
{
int idxa = [[a valueForKey:@"index"] intValue];
int idxb = [[b valueForKey:@"index"] intValue];
if (idxa < idxb)
return NSOrderedDescending;
if (idxa > idxb)
return NSOrderedAscending;
return NSOrderedSame;
}];
NSPoint loc = {0, 0};
NSInteger width = 0;
for (NSView *newSub in [sortedSections valueForKey:@"view"])
{
if ([newSub superview] != configView)
[configView addSubview:newSub];
[newSub setFrameOrigin:loc];
NSRect subFrame = [newSub frame];
loc.y += subFrame.size.height;
if (subFrame.size.width > width)
width = subFrame.size.width;
}
[configView setFrame:(NSRect){{0, 0}, {width, 0}}];
[[configView animator] setFrame:(NSRect){{0, 0}, {width, loc.y}}];
}
- (BOOL)hasConfigSections
{
return [[self valueForKey:@"configSections"] count] > 0;
}
- (NSView*)configView
{
if (!configView)
[self updateConfigView];
return configView;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object == self && [keyPath isEqualToString:@"configSections"])
{
[self updateConfigView];
/* This is a one-shot. */
[self removeObserver:self forKeyPath:@"configSections"];
}
else
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
@end
@implementation AddInItem
@dynamic RequiresAuthorization;
@dynamic State;
@end
@implementation PRCItem
@dynamic microContentID;
@dynamic ProductID;
@dynamic Title;
@dynamic Version;
@end
@implementation OfferItem
@dynamic Presentation;
@dynamic PRCList;
@end
@implementation Manifest
@end
@implementation AddInManifest
@dynamic AddInsList;
@end
@implementation ConfigSection
- (NSArray*)sortedKeys
{
return [[[self valueForKey:@"keys"] allObjects] sortedArrayUsingComparator:^NSComparisonResult(id a, id b)
{
int idxa = [[a valueForKey:@"index"] intValue];
int idxb = [[b valueForKey:@"index"] intValue];
if (idxa < idxb)
return NSOrderedDescending;
if (idxa > idxb)
return NSOrderedAscending;
return NSOrderedSame;
}];
}
- (NSView*)view
{
if (!view)
{
#if MACOS_DEPLOYMENT_TARGET < 1080
if ([[NSBundle mainBundle] respondsToSelector:@selector(loadNibNamed:owner:topLevelObjects:)])
#endif
[[NSBundle mainBundle] loadNibNamed:@"ConfigSection" owner:self topLevelObjects:nil];
#if MACOS_DEPLOYMENT_TARGET < 1080
else
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[NSBundle loadNibNamed:@"ConfigSection" owner:self];
#pragma clang diagnostic pop
}
#endif
NSPoint loc = {8, 10};
NSInteger width = 0;
for (NSView *newSub in [[self sortedKeys] valueForKey:@"view"])
{
if ([newSub superview] != box)
[box addSubview:newSub];
[newSub setFrameOrigin:loc];
NSRect subFrame = [newSub frame];
loc.y += subFrame.size.height;
if (subFrame.size.width > width)
width = subFrame.size.width;
}
[view setFrame:(NSRect){{0, 0}, {width + 22, loc.y + 34}}];
}
return view;
}
@end
@implementation ConfigKey
- (NSArray*)sortedValues
{
return [[[self valueForKey:@"values"] allObjects] sortedArrayUsingComparator:^NSComparisonResult(id a, id b)
{
int idxa = [[a valueForKey:@"index"] intValue];
int idxb = [[b valueForKey:@"index"] intValue];
if (idxa < idxb)
return NSOrderedAscending;
if (idxa > idxb)
return NSOrderedDescending;
return NSOrderedSame;
}];
}
- (NSAttributedString*)attributedDescription
{
NSString *desc = [self valueForKey:@"Description"];
if (!desc)
return nil;
return [[NSAttributedString alloc] initWithString:desc];
}
- (NSView*)view
{
if (!view)
{
#if MACOS_DEPLOYMENT_TARGET < 1080
if ([[NSBundle mainBundle] respondsToSelector:@selector(loadNibNamed:owner:topLevelObjects:)])
#endif
[[NSBundle mainBundle] loadNibNamed:@"ConfigKey" owner:self topLevelObjects:nil];
#if MACOS_DEPLOYMENT_TARGET < 1080
else
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[NSBundle loadNibNamed:@"ConfigKey" owner:self];
#pragma clang diagnostic pop
}
#endif
NSRect r = [view frame];
r.size.height = 28;
NSString *desc = [self valueForKey:@"Description"];
if (desc)
{
[[descView textContainer] setHeightTracksTextView:NO];
[descView sizeToFit];
r.size.height += [descView frame].size.height + 16;
}
[view setFrameSize:r.size];
}
return view;
}
- (IBAction)valueChanged:(id)sender
{
/* XXX layering violation */
[[AddInsList sharedAddInsList] saveDocument:self];
}
@end
@implementation ControlKeyScrollView
- (void)scrollWheel:(NSEvent *)theEvent
{
[[self superview] scrollWheel:theEvent];
}
@end