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 634f3621ab9ce5f4eaeb02d65d6534971dbb5f24..c66cf6b9aecb6d47a465a0c528599c7cf9399887 100644 (file)
     [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;
-    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:)
                                                   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;
 }
 
 - (void)mappingListDidChange:(NSNotification *)note {
+    NSArray *mappings = note.userInfo[@"mappings"];
     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];
-    [self addMappingsToMenu:statusItemMenu withKeys:NO atIndex:2];
+    [self addMappings:mappings toMenu:statusItemMenu withKeys:NO atIndex:2];
 }
 
 - (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;
 - (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;
 }
 
index 5d861868ea572afe7493ce06ff773546369654af..ad88d73d9740c1fc9fd8be4c1c52b688ff25cb38 100644 (file)
@@ -51,7 +51,8 @@
     [self updateInterfaceForCurrentMapping];
     [NSNotificationCenter.defaultCenter
         postNotificationName:NJEventMappingListChanged
-        object:_mappings];
+                      object:self
+                    userInfo:@{ @"mappings": _mappings }];
 }
 
 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
     _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 {
index 5d90bee67a896d14c82a05c80671e1b06a10e859..cf758e6e399ab2acaa4fabea8f1613eeb2732304 100644 (file)
 }
 
 - (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) {
index 9d3612e9c4c326f2ca9b2f874490aaae244ea806..ebc0a1d4a6e52c6909ca6e5f1929eb351a1c8bea 100644 (file)
@@ -46,7 +46,7 @@
        <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>