/Volumes/Plantain/MyDocuments/Projects/MacTrek/MacTrek/App/KeyMapTableDataSource.m

00001 //
00002 //  KeyMapTableDataSource.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 26/05/2006.
00006 //  Copyright 2006 __MyCompanyName__. All rights reserved.
00007 //
00008 
00009 #import "KeyMapTableDataSource.h"
00010 
00011 
00012 @implementation KeyMapTableDataSource
00013 
00014 - (id) init {
00015     self = [super init];
00016     if (self != nil) {
00017         // allocate the default map
00018         myMap = [[MTKeyMap alloc] init];
00019         // initial query is in seperate thread
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"; // unknown column
00050         }
00051     }
00052     return @"ERROR";
00053 }
00054 
00055 // delegate functions
00056 - (void)tableView:(NSTableView *)tableView setObjectValue:(id)object
00057    forTableColumn:(NSTableColumn *)column row:(int)row {
00058     
00059     // only the key column is editable
00060     if (tableView == keyMapTableView) {           
00061         NSArray *actionKeys = [myMap allKeys];
00062         int action = [[actionKeys objectAtIndex:row] intValue];
00063         // only accept a single character
00064         // use of a formatter would be better
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

Generated on Fri Jul 28 19:15:14 2006 for MacTrek by  doxygen 1.4.7