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 ecb28a67834f5ae9441553fd08b5ad1deb0c5ffc..8514fcb056f5b88f95cb8abdfc6cb8a34b6447ec 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 a63f083aa1eac1715e7ea4c2f7ded23c72cdb9c8..6d1c9694ad6c94ba8c2bb176d8e278f805a5ca70 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 fd160e65af84f00995c93d36b0999ad1d8f99f83..5235837ff107e94544aff561ad1f8e86646c5e65 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 15d916eb2339a745b35b9584b2af64b3dcb4e4f8..393ccf5e6289308b0d1b5f29ce298b658494c161 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>