00001
00002
00003
00004
00005
00006
00007
00008
00009 #import "KeyMapTableDataSource.h"
00010
00011
00012 @implementation KeyMapTableDataSource
00013
00014 - (id) init {
00015 self = [super init];
00016 if (self != nil) {
00017
00018 myMap = [[MTKeyMap alloc] init];
00019
00020 [NSThread detachNewThreadSelector:@selector(readDefaultKeyMap) toTarget:myMap withObject:nil];
00021 }
00022 return self;
00023 }
00024
00025 - (MTKeyMap *) keyMap {
00026 return myMap;
00027 }
00028
00029 - (int)numberOfRowsInTableView:(NSTableView *)aTableView {
00030
00031 if (keyMapTableView == aTableView) {
00032 return [myMap count];
00033 }
00034 return 0;
00035 }
00036
00037 - (id)tableView:(NSTableView *)aTableView
00038 objectValueForTableColumn:(NSTableColumn *)aTableColumn
00039 row:(int)rowIndex {
00040
00041 if (keyMapTableView == aTableView) {
00042 NSArray *actionKeys = [myMap allKeys];
00043 int action = [[actionKeys objectAtIndex:rowIndex] intValue];
00044 if ([[aTableColumn identifier] isEqualTo: @"description"]) {
00045 return [myMap descriptionForAction:action];
00046 } else if ([[aTableColumn identifier] isEqualTo: @"key"]) {
00047 return [NSString stringWithFormat:@"%c", [myMap keyForAction:action]];
00048 } else {
00049 return @"ERROR";
00050 }
00051 }
00052 return @"ERROR";
00053 }
00054
00055
00056 - (void)tableView:(NSTableView *)tableView setObjectValue:(id)object
00057 forTableColumn:(NSTableColumn *)column row:(int)row {
00058
00059
00060 if (tableView == keyMapTableView) {
00061 NSArray *actionKeys = [myMap allKeys];
00062 int action = [[actionKeys objectAtIndex:row] intValue];
00063
00064
00065 if ([object length] == 1) {
00066 NSString *newkey = object;
00067 char c = [newkey characterAtIndex:0];
00068 [myMap setKey:c forAction:action];
00069 }
00070 }
00071 }
00072
00073
00074 @end