Push notifications out with more idiomatic semantics - controller as object, paramete...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Mon, 11 Mar 2013 01:01:08 +0000 (02:01 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Mon, 11 Mar 2013 01:01:08 +0000 (02:01 +0100)
Classes/EnjoyableApplicationDelegate.m
Classes/NJMappingsController.m
Classes/NJOutputController.m
Info.plist

index 634f362..c66cf6b 100644 (file)
     [self.mappingsController mappingPressed:sender];
 }
 
     [self.mappingsController mappingPressed:sender];
 }
 
-- (void)addMappingsToMenu:(NSMenu *)menu withKeys:(BOOL)withKeys atIndex:(NSInteger)index {
+- (void)addMappings:(NSArray *)mappings
+             toMenu:(NSMenu *)menu
+           withKeys:(BOOL)withKeys
+            atIndex:(NSInteger)index {
     static const NSUInteger MAXIMUM_ITEMS = 15;
     int added = 0;
     static const NSUInteger MAXIMUM_ITEMS = 15;
     int added = 0;
-    for (NJMapping *mapping in self.mappingsController) {
+    for (NJMapping *mapping in mappings) {
         NSString *keyEquiv = (++added < 10 && withKeys) ? @(added).stringValue : @"";
         NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name
                                                       action:@selector(chooseMapping:)
         NSString *keyEquiv = (++added < 10 && withKeys) ? @(added).stringValue : @"";
         NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:mapping.name
                                                       action:@selector(chooseMapping:)
                                                   keyEquivalent:@""];
             // There must be a represented object here so the item gets
             // removed correctly when the menus are regenerated.
                                                   keyEquivalent:@""];
             // There must be a represented object here so the item gets
             // removed correctly when the menus are regenerated.
-            end.representedObject = self.mappingsController.mappings;
+            end.representedObject = mappings;
             end.target = self;
             [menu insertItem:end atIndex:index++];
             break;
             end.target = self;
             [menu insertItem:end atIndex:index++];
             break;
 }
 
 - (void)mappingListDidChange:(NSNotification *)note {
 }
 
 - (void)mappingListDidChange:(NSNotification *)note {
+    NSArray *mappings = note.userInfo[@"mappings"];
     while (mappingsMenu.lastItem.representedObject)
         [mappingsMenu removeLastItem];
     while (mappingsMenu.lastItem.representedObject)
         [mappingsMenu removeLastItem];
-    [self addMappingsToMenu:mappingsMenu withKeys:YES atIndex:mappingsMenu.numberOfItems];
+    [self addMappings:mappings
+               toMenu:mappingsMenu
+             withKeys:YES
+              atIndex:mappingsMenu.numberOfItems];
     while ([statusItemMenu itemAtIndex:2].representedObject)
         [statusItemMenu removeItemAtIndex:2];
     while ([statusItemMenu itemAtIndex:2].representedObject)
         [statusItemMenu removeItemAtIndex:2];
-    [self addMappingsToMenu:statusItemMenu withKeys:NO atIndex:2];
+    [self addMappings:mappings toMenu:statusItemMenu withKeys:NO atIndex:2];
 }
 
 - (void)mappingDidChange:(NSNotification *)note {
 }
 
 - (void)mappingDidChange:(NSNotification *)note {
-    NJMapping *current = note.object;
+    NJMapping *current = note.userInfo[@"mapping"];
     for (NSMenuItem *item in mappingsMenu.itemArray)
         if (item.representedObject)
             item.state = item.representedObject == current;
     for (NSMenuItem *item in mappingsMenu.itemArray)
         if (item.representedObject)
             item.state = item.representedObject == current;
 - (NSMenu *)applicationDockMenu:(NSApplication *)sender {
     while (dockMenu.lastItem.representedObject)
         [dockMenu removeLastItem];
 - (NSMenu *)applicationDockMenu:(NSApplication *)sender {
     while (dockMenu.lastItem.representedObject)
         [dockMenu removeLastItem];
-    [self addMappingsToMenu:dockMenu withKeys:NO atIndex:dockMenu.numberOfItems];
+    [self addMappings:self.mappingsController.mappings
+               toMenu:dockMenu
+             withKeys:NO
+              atIndex:dockMenu.numberOfItems];
     return dockMenu;
 }
 
     return dockMenu;
 }
 
index 5d86186..ad88d73 100644 (file)
@@ -51,7 +51,8 @@
     [self updateInterfaceForCurrentMapping];
     [NSNotificationCenter.defaultCenter
         postNotificationName:NJEventMappingListChanged
     [self updateInterfaceForCurrentMapping];
     [NSNotificationCenter.defaultCenter
         postNotificationName:NJEventMappingListChanged
-        object:_mappings];
+                      object:self
+                    userInfo:@{ @"mappings": _mappings }];
 }
 
 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
 }
 
 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
     _manualMapping = mapping;
     _currentMapping = mapping;
     [self updateInterfaceForCurrentMapping];
     _manualMapping = mapping;
     _currentMapping = mapping;
     [self updateInterfaceForCurrentMapping];
-    [NSNotificationCenter.defaultCenter postNotificationName:NJEventMappingChanged
-                                                      object:_currentMapping];
+    [NSNotificationCenter.defaultCenter
+         postNotificationName:NJEventMappingChanged
+         object:self
+         userInfo:@{ @"mapping": _currentMapping }];
 }
 
 - (IBAction)addPressed:(id)sender {
 }
 
 - (IBAction)addPressed:(id)sender {
index 5d90bee..cf758e6 100644 (file)
 }
 
 - (void)mappingListDidChange:(NSNotification *)note {
 }
 
 - (void)mappingListDidChange:(NSNotification *)note {
-    NSArray *mappings = note.object;
+    NSArray *mappings = note.userInfo[@"mappings"];
     NJMapping *current = mappingPopup.selectedItem.representedObject;
     [mappingPopup.menu removeAllItems];
     for (NJMapping *mapping in mappings) {
     NJMapping *current = mappingPopup.selectedItem.representedObject;
     [mappingPopup.menu removeAllItems];
     for (NJMapping *mapping in mappings) {
index 9d3612e..ebc0a1d 100644 (file)
@@ -46,7 +46,7 @@
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>108</string>
+       <string>109</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>