Created
May 28, 2013 18:10
-
-
Save swillits/5664805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSMenu (SeparatorAdditions) | |
- (void)removeExtraSeparatorItems; | |
@end | |
@implementation NSMenu (SeparatorAdditions) | |
- (void)removeExtraSeparatorItems; | |
{ | |
// Remove separator at index 0 | |
while (self.itemArray.count > 0) { | |
NSMenuItem * item = [self.itemArray objectAtIndex:0]; | |
if (item.isSeparatorItem) { | |
[self removeItem:item]; | |
} else { | |
break; | |
} | |
} | |
// Remove separator at last index | |
while (self.itemArray.count > 0) { | |
NSMenuItem * item = [self.itemArray lastObject]; | |
if (item.isSeparatorItem) { | |
[self removeItem:item]; | |
} else { | |
break; | |
} | |
} | |
// Remove separator preceded by separator | |
BOOL prevIsSeparator = NO; | |
NSUInteger index = 0; | |
while (index < self.itemArray.count) { | |
NSMenuItem * item = [self.itemArray objectAtIndex:index]; | |
if (item.isSeparatorItem) { | |
if (prevIsSeparator) { | |
[self removeItem:item]; | |
continue; | |
} else { | |
prevIsSeparator = YES; | |
} | |
} else { | |
prevIsSeparator = NO; | |
} | |
index++; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment