Rename methods uniquely between mapping/device controllers.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 20 Mar 2013 19:40:45 +0000 (20:40 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 20 Mar 2013 19:40:45 +0000 (20:40 +0100)
Classes/EnjoyableApplicationDelegate.m
Classes/NJDeviceController.h
Classes/NJDeviceController.m
Classes/NJMappingsController.h
Classes/NJMappingsController.m
Classes/NJOutputController.m
Info.plist

index 41d068a3ee7d261afe45d4342534bfe20d48e623..764636390927a2a4e3694a1cd35a4ad7de18d08a 100644 (file)
     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 {
                       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 {
 }
 
 - (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 =
 }
 
 - (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];
 }
 
        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
                          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];
 - (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];
 
 - (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 {
 
 - (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
 }
 
 - (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 {
index e594f1058ed6a3dfbb85b794ee81eaab90038cc3..41017db0eab364aa32ee3dde8f9ca976d77ebfe2 100644 (file)
 
 @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
 
index 1b64aaf3f694e5dd26eb3c8324ebf0de77c82e04..5df317bda64a13d019d06180b4834c517783292c 100644 (file)
     [_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.
         [self stopHid];
 }
 
-- (NJInputPathElement *)objectForKeyedSubscript:(NSString *)uid {
+- (NJInputPathElement *)elementForUID:(NSString *)uid {
     for (NJDevice *dev in _devices) {
         id item = [dev elementForUID:uid];
         if (item)
index 9dd1e157da0005c66fa5ac7498438e7fe49ba0d2..b9d3e678aad1a1552fabddea9f943f5ac3cf9d05 100644 (file)
@@ -8,13 +8,12 @@
 
 @class NJMapping;
 
-@interface NJMappingsController : NSObject <NSFastEnumeration>
+@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;
index 44a9c43e1eb2819e20f050350d9b8de4434907ad..69025049f351a1cd1eab592872f398539cb862d3 100644 (file)
     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
     [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;
 }
 
 - (void)postLoadProcess {
-    for (NJMapping *mapping in self)
-        [mapping postLoadProcess:self];
+    for (NJMapping *mapping in self.mappings)
+        [mapping postLoadProcess:self.mappings];
 }
 
 - (void)load {
 - (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];
 }
 
     [self mappingsChanged];
 }
 
-- (NSUInteger)count {
-    return _mappings.count;
-}
-
 @end
index 1567fee7507534ddced90980e439a0afba122ebf..22c387fc9490107a4bee3a0d89e8fc7ef23556bc 100644 (file)
             break;
         case 2: {
             NJOutputMapping *c = [[NJOutputMapping alloc] init];
-            c.mapping = mappingsController[mappingPopup.indexOfSelectedItem];
+            c.mapping = mappingsController.mappings[mappingPopup.indexOfSelectedItem];
             return c;
         }
         case 3: {
index a645f948e1a66da56f726cad364696a00ee2d430..78a6a1afb8ad0cbc4f5a4600275f9bb3e46a3d51 100644 (file)
@@ -46,7 +46,7 @@
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>540</string>
+       <string>548</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>