ResKnife/Cocoa/Classes/AttributesFormatter.m

81 lines
2.2 KiB
Mathematica
Raw Normal View History

2001-10-19 19:41:13 +00:00
#import "AttributesFormatter.h"
#import <Carbon/Carbon.h>
@implementation AttributesFormatter
- (NSString *)stringForObjectValue:(id)obj
{
BOOL addComma = NO;
short attributes = [obj shortValue];
NSMutableString *string = [NSMutableString string];
2002-02-02 11:31:28 +00:00
// there's probably a smarter, bitwise, way to do this
short attributeCount = 0;
if( attributes & resPreload ) attributeCount++;
if( attributes & resProtected ) attributeCount++;
if( attributes & resLocked ) attributeCount++;
if( attributes & resPurgeable ) attributeCount++;
if( attributes & resSysHeap ) attributeCount++;
// create string
2001-10-19 19:41:13 +00:00
if( attributes & resPreload )
{
2002-02-02 11:31:28 +00:00
if( addComma ) [string appendString:@", "];
if( attributeCount > 2 ) [string appendString:@"Pre"];
else [string appendString:@"Preload"];
2001-10-19 19:41:13 +00:00
addComma = YES;
}
if( attributes & resProtected )
{
2002-02-02 11:31:28 +00:00
if( addComma ) [string appendString:@", "];
if( attributeCount > 2 ) [string appendString:@"Pro"];
else [string appendString:@"Protected"];
2001-10-19 19:41:13 +00:00
addComma = YES;
}
if( attributes & resLocked )
{
2002-02-02 11:31:28 +00:00
if( addComma ) [string appendString:@", "];
if( attributeCount > 2 ) [string appendString:@"L"];
else [string appendString:@"Locked"];
2001-10-19 19:41:13 +00:00
addComma = YES;
}
if( attributes & resPurgeable )
{
2002-02-02 11:31:28 +00:00
if( addComma ) [string appendString:@", "];
if( attributeCount > 2 ) [string appendString:@"Pur"];
else [string appendString:@"Purgeable"];
2001-10-19 19:41:13 +00:00
addComma = YES;
}
if( attributes & resSysHeap )
{
2002-02-02 11:31:28 +00:00
if( addComma ) [string appendString:@", "];
if( attributeCount > 2 ) [string appendString:@"Sys"];
else [string appendString:@"SysHeap"];
2001-10-19 19:41:13 +00:00
addComma = YES;
}
return string;
}
- (NSAttributedString *)attributedStringForObjectValue:(id)obj withDefaultAttributes:(NSDictionary *)attrs
{
NSString *string = [self stringForObjectValue:obj];
return [[NSAttributedString alloc] initWithString:string attributes:attrs];
}
- (NSString *)editingStringForObjectValue:(id)obj
{
return nil;
}
- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string errorDescription:(NSString **)error
{
return NO;
}
- (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error
{
return NO;
}
@end