Merge pull request #1902 from ahankinson/fix-issue1899

Fixed: Removing an item from a menu also removes its highlight state
This commit is contained in:
aparajita
2013-04-18 13:17:24 -07:00
4 changed files with 56 additions and 2 deletions
+3 -1
View File
@@ -355,7 +355,7 @@ var _CPMenuBarVisible = NO,
while (count--)
[_items[count] setMenu:nil];
_highlightedIndex = CPNotFound;
[self _highlightItemAtIndex:CPNotFound];
// Because we are changing _items directly, be sure to notify KVO
[self willChangeValueForKey:@"items"];
@@ -1151,6 +1151,7 @@ var _CPMenuBarVisible = NO,
return;
[aMenuItem setMenu:self];
[self _highlightItemAtIndex:CPNotFound];
[_items insertObject:aMenuItem atIndex:anIndex];
[[CPNotificationCenter defaultCenter]
@@ -1165,6 +1166,7 @@ var _CPMenuBarVisible = NO,
return;
[[_items objectAtIndex:anIndex] setMenu:nil];
[self _highlightItemAtIndex:CPNotFound];
[_items removeObjectAtIndex:anIndex];
[[CPNotificationCenter defaultCenter]
@@ -336,6 +336,11 @@
}
}
- (BOOL)isHighlighted
{
return _highlighted;
}
@end
@implementation _CPMenuItemSubmenuIndicatorView : CPView
+1 -1
View File
@@ -34,7 +34,7 @@
@implementation _CPMenuItemView : CPView
{
CPMenuItem _menuItem;
CPView _view;
CPView _view @accessors(property=view, readonly);
CPFont _font;
CPColor _textColor;
+47
View File
@@ -15,6 +15,8 @@
BOOL saveDocumentWasCalled;
BOOL saveDocumentAsWasCalled;
BOOL undoWasCalled;
CPMenuItem anInstantiatedMenuItem;
}
- (void)setUp
@@ -67,6 +69,10 @@
[menu addItem:editMenuItem];
[menu addItem:[CPMenuItem separatorItem]];
// Test Issue 1899
anInstantiatedMenuItem = [[CPMenuItem alloc] initWithTitle:@"Highlight" action:nil keyEquivalent:@""];
[menu addItem:anInstantiatedMenuItem];
}
- (void)_retarget:(CPMenuItem)aMenu
@@ -82,6 +88,47 @@
}
}
- (void)testRemoveAllItemsHighlighting
{
// hack it so that this menu item is highlighted
[menu _highlightItemAtIndex:[menu indexOfItem:anInstantiatedMenuItem]];
// test both the public isHighlighted method, as well as the underlying view highlighting
[self assertTrue:[anInstantiatedMenuItem isHighlighted]];
[self assertTrue:[[[anInstantiatedMenuItem _menuItemView] view] isHighlighted] message:@"Underlying view was not highlighted in removeAll"];
[menu removeAllItems];
[self assertFalse:[anInstantiatedMenuItem isHighlighted]];
[self assertFalse:[[[anInstantiatedMenuItem _menuItemView] view] isHighlighted] message:@"Underlying view was still highlighted after removeAll"];
}
- (void)testRemoveOneItemHighlighting
{
[menu _highlightItemAtIndex:[menu indexOfItem:anInstantiatedMenuItem]];
[self assertTrue:[anInstantiatedMenuItem isHighlighted]];
[self assertTrue:[[[anInstantiatedMenuItem _menuItemView] view] isHighlighted] message:@"Underlying view was not highlighted in removeItem"];
[menu removeItem:anInstantiatedMenuItem];
[self assertFalse:[anInstantiatedMenuItem isHighlighted]];
[self assertFalse:[[[anInstantiatedMenuItem _menuItemView] view] isHighlighted] message:@"Underlying view was still highlighted after removeItem"];
}
- (void)testRemoveOneItemByIndexHighlighting
{
[menu _highlightItemAtIndex:[menu indexOfItem:anInstantiatedMenuItem]];
[self assertTrue:[anInstantiatedMenuItem isHighlighted]];
[self assertTrue:[[[anInstantiatedMenuItem _menuItemView] view] isHighlighted] message:@"Underlying view was not highlighted in removeItemAtIndex"];
[menu removeItemAtIndex:[menu indexOfItem:anInstantiatedMenuItem]];
[self assertFalse:[anInstantiatedMenuItem isHighlighted]];
[self assertFalse:[[[anInstantiatedMenuItem _menuItemView] view] isHighlighted] message:@"Underlying view was still highlighted after removeItemAtIndex"];
}
- (void)testKeyEquivalent
{
[self _retarget:menu];