}
- (id)initWithCoder:(NSCoder *)aDecoder
-{
- self = [self init];
-
- if( self )
- {
+{
+ if ( (self = [super init]) ) {
[aDecoder decodeValueOfObjCType: @encode(short) at: &mKeyCode];
[aDecoder decodeValueOfObjCType: @encode(long) at: &mModifiers];
}
- (BOOL)isEqual:(KeyCombo *)object
{
- return ([object isKindOfClass:[KeyCombo class]]) &&
- ([object keyCode] == [self keyCode]) &&
- ([object modifiers] == [self modifiers]);
+ return ( ([object isKindOfClass:[KeyCombo class]]) &&
+ ([object keyCode] == [self keyCode]) &&
+ ([object modifiers] == [self modifiers]) );
}
- (NSString *)description
- (NSString *)userDisplayRep
{
- if ([self isValid] == NO)
- {
- return @"None";
- }
- else
- {
+ if ( ! [self isValid] ) {
+ return @"";
+ } else {
return [NSString stringWithFormat: @"%@%@",
[KeyCombo _stringForModifiers: mModifiers],
[KeyCombo _stringForKeyCode: mKeyCode]];
+ (NSString *)_stringForModifiers: (long)modifiers
{
- static long modToChar[4][2] =
- {
+ static long modToChar[4][2] = {
{ cmdKey, 0x23180000 },
{ optionKey, 0x23250000 },
- { controlKey, 0x005E0000 },
+ { controlKey, 0x23030000 },
{ shiftKey, 0x21e70000 }
};
NSString *charStr;
long i;
- for (i = 0; i < 4; i++)
- {
- if (modifiers & modToChar[i][0])
- {
+ for (i = 0; i < 4; i++) {
+ if (modifiers & modToChar[i][0]) {
charStr = [NSString stringWithCharacters:(const unichar *)&modToChar[i][1] length:1];
str = [str stringByAppendingString:charStr];
}
dict = [self keyCodesDictionary];
key = [NSString stringWithFormat: @"%d", keyCode];
str = [dict objectForKey: key];
-
- if( !str )
+
+ if( !str ) {
str = [NSString stringWithFormat: @"%X", keyCode];
+ }
return str;
}
{
static NSDictionary *keyCodes = nil;
- if (keyCodes == nil)
- {
+ if (keyCodes == nil) {
NSString *path;
NSString *contents;
- (void)setKeyCombo:(KeyCombo *)combo forKey:(NSString *)key
{
NSData *data;
- if (combo)
- {
+ if (combo) {
data = [NSArchiver archivedDataWithRootObject:combo];
- }
- else
- {
+ } else {
data = nil;
}
[self setObject:data forKey:key];
{
NSData *data = [self objectForKey:key];
KeyCombo *combo;
- if (data)
- {
- combo = [[NSUnarchiver unarchiveObjectWithData:data] retain];
- }
- if (combo == nil)
- {
- combo = [[KeyCombo alloc] init];
+ if (data) {
+ combo = [NSUnarchiver unarchiveObjectWithData:data];
+ } else {
+ combo = nil;
}
+
return combo;
}