From 6a8c6539cc3f7a4b32a9f226da6ae06074e4f0cb Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Wed, 20 Mar 2013 20:40:45 +0100 Subject: [PATCH] Rename methods uniquely between mapping/device controllers. --- Classes/EnjoyableApplicationDelegate.m | 46 +++++++++++++------------- Classes/NJDeviceController.h | 5 ++- Classes/NJDeviceController.m | 10 +----- Classes/NJMappingsController.h | 7 ++-- Classes/NJMappingsController.m | 26 +++------------ Classes/NJOutputController.m | 2 +- Info.plist | 2 +- 7 files changed, 36 insertions(+), 62 deletions(-) diff --git a/Classes/EnjoyableApplicationDelegate.m b/Classes/EnjoyableApplicationDelegate.m index 41d068a..7646363 100644 --- a/Classes/EnjoyableApplicationDelegate.m +++ b/Classes/EnjoyableApplicationDelegate.m @@ -148,14 +148,14 @@ NSURL *URL = [NSURL fileURLWithPath:filename]; NJMapping *mapping = [NJMapping mappingWithContentsOfURL:URL error:&error]; - if ([self.mappingsController[mapping.name] hasConflictWith:mapping]) { - [self promptForMapping:mapping atIndex:self.mappingsController.count]; - } else if (self.mappingsController[mapping.name]) { - [self.mappingsController[mapping.name] mergeEntriesFrom:mapping]; + if ([[self.mappingsController mappingForKey:mapping.name] hasConflictWith:mapping]) { + [self promptForMapping:mapping atIndex:self.mappingsController.mappings.count]; + } else if ([self.mappingsController mappingForKey:mapping.name]) { + [[self.mappingsController mappingForKey:mapping.name] mergeEntriesFrom:mapping]; } else if (mapping) { [self.mvc beginUpdates]; [self.mappingsController addMapping:mapping]; - [self.mvc addedMappingAtIndex:self.mappingsController.count - 1 startEditing:NO]; + [self.mvc addedMappingAtIndex:self.mappingsController.mappings.count - 1 startEditing:NO]; [self.mvc endUpdates]; [self.mappingsController activateMapping:mapping]; } else { @@ -229,10 +229,10 @@ NSError *error; NJMapping *mapping = [NJMapping mappingWithContentsOfURL:panel.URL error:&error]; - if ([self.mappingsController[mapping.name] hasConflictWith:mapping]) { - [self promptForMapping:mapping atIndex:self.mappingsController.count]; - } else if (self.mappingsController[mapping.name]) { - [self.mappingsController[mapping.name] mergeEntriesFrom:mapping]; + if ([[self.mappingsController mappingForKey:mapping.name] hasConflictWith:mapping]) { + [self promptForMapping:mapping atIndex:self.mappingsController.mappings.count]; + } else if ([self.mappingsController mappingForKey:mapping.name]) { + [[self.mappingsController mappingForKey:mapping.name] mergeEntriesFrom:mapping]; } else if (mapping) { [self.mappingsController addMapping:mapping]; } else { @@ -293,7 +293,7 @@ } - (void)promptForMapping:(NJMapping *)mapping atIndex:(NSInteger)idx { - NJMapping *mergeInto = self.mappingsController[mapping.name]; + NJMapping *mergeInto = [self.mappingsController mappingForKey:mapping.name]; NSAlert *conflictAlert = [[NSAlert alloc] init]; conflictAlert.messageText = NSLocalizedString(@"import conflict prompt", @"Title of import conflict alert"); conflictAlert.informativeText = @@ -311,18 +311,18 @@ } - (NSInteger)numberOfMappings:(NJMappingsViewController *)mvc { - return self.mappingsController.count; + return self.mappingsController.mappings.count; } - (NJMapping *)mappingsViewController:(NJMappingsViewController *)mvc mappingForIndex:(NSUInteger)idx { - return self.mappingsController[idx]; + return self.mappingsController.mappings[idx]; } - (void)mappingsViewController:(NJMappingsViewController *)mvc renameMappingAtIndex:(NSInteger)index toName:(NSString *)name { - [self.mappingsController renameMapping:self.mappingsController[index] + [self.mappingsController renameMapping:self.mappingsController.mappings[index] to:name]; } @@ -330,7 +330,7 @@ canMoveMappingFromIndex:(NSInteger)fromIdx toIndex:(NSInteger)toIdx { return fromIdx != toIdx && fromIdx != 0 && toIdx != 0 - && toIdx < (NSInteger)self.mappingsController.count; + && toIdx < (NSInteger)self.mappingsController.mappings.count; } - (void)mappingsViewController:(NJMappingsViewController *)mvc @@ -361,10 +361,10 @@ error:(NSError **)error { NJMapping *mapping = [NJMapping mappingWithContentsOfURL:url error:error]; - if ([self.mappingsController[mapping.name] hasConflictWith:mapping]) { + if ([[self.mappingsController mappingForKey:mapping.name] hasConflictWith:mapping]) { [self promptForMapping:mapping atIndex:index]; - } else if (self.mappingsController[mapping.name]) { - [self.mappingsController[mapping.name] mergeEntriesFrom:mapping]; + } else if ([self.mappingsController mappingForKey:mapping.name]) { + [[self.mappingsController mappingForKey:mapping.name] mergeEntriesFrom:mapping]; } else if (mapping) { [self.mvc beginUpdates]; [self.mvc addedMappingAtIndex:index startEditing:NO]; @@ -377,7 +377,7 @@ - (void)mappingsViewController:(NJMappingsViewController *)mvc addMapping:(NJMapping *)mapping { [mvc beginUpdates]; - [mvc addedMappingAtIndex:self.mappingsController.count startEditing:YES]; + [mvc addedMappingAtIndex:self.mappingsController.mappings.count startEditing:YES]; [self.mappingsController addMapping:mapping]; [mvc endUpdates]; [self.mappingsController activateMapping:mapping]; @@ -385,12 +385,12 @@ - (void)mappingsViewController:(NJMappingsViewController *)mvc choseMappingAtIndex:(NSInteger)idx { - [self.mappingsController activateMapping:self.mappingsController[idx]]; + [self.mappingsController activateMapping:self.mappingsController.mappings[idx]]; } - (id)deviceViewController:(NJDeviceViewController *)dvc elementForUID:(NSString *)uid { - return self.deviceController[uid]; + return [self.deviceController elementForUID:uid]; } - (void)deviceViewControllerDidSelectNothing:(NJDeviceViewController *)dvc { @@ -414,7 +414,7 @@ - (void)deviceController:(NJDeviceController *)dc didAddDevice:(NJDevice *)device { - [self.dvc addedDevice:device atIndex:dc.count - 1]; + [self.dvc addedDevice:device atIndex:dc.devices.count - 1]; } - (void)deviceController:(NJDeviceController *)dc @@ -451,12 +451,12 @@ } - (NSInteger)numberOfDevicesInDeviceList:(NJDeviceViewController *)dvc { - return self.deviceController.count; + return self.deviceController.devices.count; } - (NJDevice *)deviceViewController:(NJDeviceViewController *)dvc deviceForIndex:(NSUInteger)idx { - return self.deviceController[idx]; + return self.deviceController.devices[idx]; } - (IBAction)simulatingEventsChanged:(NSButton *)sender { diff --git a/Classes/NJDeviceController.h b/Classes/NJDeviceController.h index e594f10..41017db 100644 --- a/Classes/NJDeviceController.h +++ b/Classes/NJDeviceController.h @@ -23,10 +23,9 @@ @property (nonatomic, assign) NSPoint mouseLoc; @property (nonatomic, assign) BOOL simulatingEvents; +@property (nonatomic, readonly) NSArray *devices; -- (NJDevice *)objectAtIndexedSubscript:(NSUInteger)idx; -- (NJInputPathElement *)objectForKeyedSubscript:(NSString *)uid; -- (NSUInteger)count; +- (NJInputPathElement *)elementForUID:(NSString *)uid; @end diff --git a/Classes/NJDeviceController.m b/Classes/NJDeviceController.m index 1b64aaf..5df317b 100644 --- a/Classes/NJDeviceController.m +++ b/Classes/NJDeviceController.m @@ -66,14 +66,6 @@ [_continuousOutputsTick invalidate]; } -- (NJDevice *)objectAtIndexedSubscript:(NSUInteger)idx { - return idx < _devices.count ? _devices[idx] : nil; -} - -- (NSUInteger)count { - return _devices.count; -} - - (void)addRunningOutput:(NJOutput *)output { // Axis events will trigger every small movement, don't keep // re-adding them or they trigger multiple times each time. @@ -215,7 +207,7 @@ [self stopHid]; } -- (NJInputPathElement *)objectForKeyedSubscript:(NSString *)uid { +- (NJInputPathElement *)elementForUID:(NSString *)uid { for (NJDevice *dev in _devices) { id item = [dev elementForUID:uid]; if (item) diff --git a/Classes/NJMappingsController.h b/Classes/NJMappingsController.h index 9dd1e15..b9d3e67 100644 --- a/Classes/NJMappingsController.h +++ b/Classes/NJMappingsController.h @@ -8,13 +8,12 @@ @class NJMapping; -@interface NJMappingsController : NSObject +@interface NJMappingsController : NSObject @property (nonatomic, readonly) NJMapping *currentMapping; -@property (nonatomic, readonly) NSUInteger count; +@property (nonatomic, readonly) NSArray *mappings; -- (NJMapping *)objectForKeyedSubscript:(NSString *)name; -- (NJMapping *)objectAtIndexedSubscript:(NSUInteger)idx; +- (NJMapping *)mappingForKey:(NSString *)name; - (NSInteger)indexOfMapping:(NJMapping *)mapping; - (void)addMapping:(NJMapping *)mapping; diff --git a/Classes/NJMappingsController.m b/Classes/NJMappingsController.m index 44a9c43..6902504 100644 --- a/Classes/NJMappingsController.m +++ b/Classes/NJMappingsController.m @@ -27,17 +27,13 @@ return self; } -- (NJMapping *)objectForKeyedSubscript:(NSString *)name { +- (NJMapping *)mappingForKey:(NSString *)name { for (NJMapping *mapping in _mappings) if ([name isEqualToString:mapping.name]) return mapping; return nil; } -- (NJMapping *)objectAtIndexedSubscript:(NSUInteger)idx { - return idx < _mappings.count ? _mappings[idx] : nil; -} - - (void)mappingsSet { [self postLoadProcess]; [NSNotificationCenter.defaultCenter @@ -52,20 +48,12 @@ [self mappingsSet]; } -- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state - objects:(__unsafe_unretained id [])buffer - count:(NSUInteger)len { - return [_mappings countByEnumeratingWithState:state - objects:buffer - count:len]; -} - - (void)activateMappingForProcess:(NSRunningApplication *)app { NJMapping *oldMapping = _manualMapping; NSArray *names = app.possibleMappingNames; BOOL found = NO; for (NSString *name in names) { - NJMapping *mapping = self[name]; + NJMapping *mapping = [self mappingForKey:name]; if (mapping) { [self activateMapping:mapping]; found = YES; @@ -114,8 +102,8 @@ } - (void)postLoadProcess { - for (NJMapping *mapping in self) - [mapping postLoadProcess:self]; + for (NJMapping *mapping in self.mappings) + [mapping postLoadProcess:self.mappings]; } - (void)load { @@ -166,7 +154,7 @@ - (void)removeMappingAtIndex:(NSInteger)idx { NSInteger currentIdx = [self indexOfMapping:_currentMapping]; [_mappings removeObjectAtIndex:idx]; - [self activateMapping:self[MIN(currentIdx, _mappings.count - 1)]]; + [self activateMapping:self.mappings[MIN(currentIdx, _mappings.count - 1)]]; [self mappingsChanged]; } @@ -175,8 +163,4 @@ [self mappingsChanged]; } -- (NSUInteger)count { - return _mappings.count; -} - @end diff --git a/Classes/NJOutputController.m b/Classes/NJOutputController.m index 1567fee..22c387f 100644 --- a/Classes/NJOutputController.m +++ b/Classes/NJOutputController.m @@ -177,7 +177,7 @@ break; case 2: { NJOutputMapping *c = [[NJOutputMapping alloc] init]; - c.mapping = mappingsController[mappingPopup.indexOfSelectedItem]; + c.mapping = mappingsController.mappings[mappingPopup.indexOfSelectedItem]; return c; } case 3: { diff --git a/Info.plist b/Info.plist index a645f94..78a6a1a 100644 --- a/Info.plist +++ b/Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 540 + 548 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright -- 2.30.2