From 30947f178cfe375c8580c844cd9c9a96e7e4fa2f Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Sun, 17 Mar 2013 22:25:42 +0100 Subject: [PATCH] Use identity rather than equality when looking for equivalent mappings. --- Categories/NSMenu+RepresentedObjectAccessors.h | 10 +++------- Categories/NSMenu+RepresentedObjectAccessors.m | 18 ++++++++++++++---- Classes/NJOutputController.m | 4 ++-- Info.plist | 2 +- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Categories/NSMenu+RepresentedObjectAccessors.h b/Categories/NSMenu+RepresentedObjectAccessors.h index ecb28a6..8514fcb 100644 --- a/Categories/NSMenu+RepresentedObjectAccessors.h +++ b/Categories/NSMenu+RepresentedObjectAccessors.h @@ -12,16 +12,10 @@ // 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. @@ -37,10 +31,12 @@ @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. diff --git a/Categories/NSMenu+RepresentedObjectAccessors.m b/Categories/NSMenu+RepresentedObjectAccessors.m index a63f083..6d1c969 100644 --- a/Categories/NSMenu+RepresentedObjectAccessors.m +++ b/Categories/NSMenu+RepresentedObjectAccessors.m @@ -17,10 +17,11 @@ 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 { @@ -40,9 +41,18 @@ 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 diff --git a/Classes/NJOutputController.m b/Classes/NJOutputController.m index fd160e6..5235837 100644 --- a/Classes/NJOutputController.m +++ b/Classes/NJOutputController.m @@ -243,7 +243,7 @@ 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]; @@ -295,7 +295,7 @@ item.representedObject = mapping; [mappingPopup.menu addItem:item]; } - [mappingPopup selectItemWithRepresentedObject:current]; + [mappingPopup selectItemWithIdenticalRepresentedObject:current]; } - (void)mappingDidChange:(NSNotification *)note { diff --git a/Info.plist b/Info.plist index 15d916e..393ccf5 100644 --- a/Info.plist +++ b/Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 479 + 482 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright -- 2.30.2