From efa2918ce91fc1841b7406deed104b934205458a Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Sun, 14 Apr 2013 15:40:35 -0400 Subject: [PATCH] Change how menu items are highlighted This replaces the previous solution with one proposed by @BlairDuncan. It uses the _highlightItemAtIndex: method to maintain the highlight state, rather than setting the _highlightIndex variable directly. --- AppKit/CPMenu/CPMenu.j | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index f7dbb5ca7..0cbf4f763 100644 --- a/AppKit/CPMenu/CPMenu.j +++ b/AppKit/CPMenu/CPMenu.j @@ -328,9 +328,6 @@ var _CPMenuBarVisible = NO, */ - (void)removeItem:(CPMenuItem)aMenuItem { - if ([aMenuItem isHighlighted]) - [[aMenuItem _menuItemView] highlight:NO]; - [self removeItemAtIndex:[_items indexOfObjectIdenticalTo:aMenuItem]]; } @@ -358,12 +355,7 @@ var _CPMenuBarVisible = NO, while (count--) [_items[count] setMenu:nil]; - // See Issue 1899. Ensure the highlight state of the underlying - // _CPMenuItemView is set to NO as well. - if (_highlightedIndex !== CPNotFound) - [[_items[_highlightedIndex] _menuItemView] highlight:NO]; - - _highlightedIndex = CPNotFound; + [self _highlightItemAtIndex:CPNotFound]; // Because we are changing _items directly, be sure to notify KVO [self willChangeValueForKey:@"items"]; @@ -1159,6 +1151,7 @@ var _CPMenuBarVisible = NO, return; [aMenuItem setMenu:self]; + [self _highlightItemAtIndex:CPNotFound]; [_items insertObject:aMenuItem atIndex:anIndex]; [[CPNotificationCenter defaultCenter] @@ -1172,10 +1165,8 @@ var _CPMenuBarVisible = NO, if (anIndex < 0 || anIndex >= [_items count]) return; - if (_highlightedIndex === anIndex) - [[[_items objectAtIndex:anIndex] _menuItemView] highlight:NO]; - [[_items objectAtIndex:anIndex] setMenu:nil]; + [self _highlightItemAtIndex:CPNotFound]; [_items removeObjectAtIndex:anIndex]; [[CPNotificationCenter defaultCenter]