Use identity rather than equality when looking for equivalent mappings.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Sun, 17 Mar 2013 21:25:42 +0000 (22:25 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Sun, 17 Mar 2013 21:25:42 +0000 (22:25 +0100)
Categories/NSMenu+RepresentedObjectAccessors.h
Categories/NSMenu+RepresentedObjectAccessors.m
Classes/NJOutputController.m
Info.plist

index ecb28a6..8514fcb 100644 (file)
     // Helpers for using represented objects in menu items.
 
 - (NSMenuItem *)itemWithRepresentedObject:(id)object;
+- (NSMenuItem *)itemWithIdenticalRepresentedObject:(id)object;
     // Returns the first menu item in the receiver that has a given
     // represented object.
 
-- (void)removeItemWithRepresentedObject:(id)object;
-    // Removes the first menu item representing the given object in the
-    // receiver.
-    //
-    // After it removes the menu item, this method posts an
-    // NSMenuDidRemoveItemNotification.
-
 - (NSMenuItem *)lastItem;
     // Return the last menu item in the receiver, or nil if the menu
     // has no items.
 @interface NSPopUpButton (RepresentedObjectAccessors)
 
 - (NSMenuItem *)itemWithRepresentedObject:(id)object;
+- (NSMenuItem *)itemWithIdenticalRepresentedObject:(id)object;
     // Returns the first item in the receiver's menu that has a given
     // represented object.
 
 - (void)selectItemWithRepresentedObject:(id)object;
+- (void)selectItemWithIdenticalRepresentedObject:(id)object;
     // Selects the first item in the receiver's menu that has a give
     // represented object.
 
index a63f083..6d1c969 100644 (file)
     return nil;
 }
 
-- (void)removeItemWithRepresentedObject:(id)object {
-    NSInteger idx = [self indexOfItemWithRepresentedObject:object];
-    if (idx != -1)
-        [self removeItemAtIndex:idx];
+- (NSMenuItem *)itemWithIdenticalRepresentedObject:(id)object {
+    for (NSMenuItem *item in self.itemArray)
+        if (item.representedObject == object)
+            return item;
+    return nil;
 }
 
 - (NSMenuItem *)lastItem {
     return [self.menu itemWithRepresentedObject:object];
 }
 
+- (NSMenuItem *)itemWithIdenticalRepresentedObject:(id)object {
+    return [self.menu itemWithIdenticalRepresentedObject:object];
+}
+
 - (void)selectItemWithRepresentedObject:(id)object {
     [self selectItemAtIndex:[self indexOfItemWithRepresentedObject:object]];
 }
 
+- (void)selectItemWithIdenticalRepresentedObject:(id)object {
+    NSMenuItem *item = [self.menu itemWithIdenticalRepresentedObject:object];
+    [self selectItem:item];
+}
+
 
 @end
index fd160e6..5235837 100644 (file)
         keyInput.keyCode = [(NJOutputKeyPress*)output keyCode];
     } else if ([output isKindOfClass:NJOutputMapping.class]) {
         [radioButtons selectCellAtRow:2 column:0];
-        NSMenuItem *item = [mappingPopup itemWithRepresentedObject:[(NJOutputMapping *)output mapping]];
+        NSMenuItem *item = [mappingPopup itemWithIdenticalRepresentedObject:[(NJOutputMapping *)output mapping]];
         [mappingPopup selectItem:item];
         unknownMapping.hidden = !!item;
         unknownMapping.title = [(NJOutputMapping *)output mappingName];
         item.representedObject = mapping;
         [mappingPopup.menu addItem:item];
     }
-    [mappingPopup selectItemWithRepresentedObject:current];
+    [mappingPopup selectItemWithIdenticalRepresentedObject:current];
 }
 
 - (void)mappingDidChange:(NSNotification *)note {
index 15d916e..393ccf5 100644 (file)
@@ -46,7 +46,7 @@
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>479</string>
+       <string>482</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>