diff --git a/MacPass/MPIconHelper.h b/MacPass/MPIconHelper.h index c4f45ba2..ba8a4319 100644 --- a/MacPass/MPIconHelper.h +++ b/MacPass/MPIconHelper.h @@ -73,9 +73,15 @@ typedef NS_ENUM(NSUInteger, MPIconType) { + (NSDictionary *)availableIconNames; /** - * List of all availabel DatabaseIcons as Images. Sorted by IconIndex + * List of all available DatabaseIcons as an array of Images. Sorted by IconIndex. * @return Array of Icons as NSImage objects */ + (NSArray *)databaseIcons; +/** + * List of all available DatabaseIcons as an array of MPIconType. Sorted by IconIndex. + * @return Array of MPIconType as NSNumber objects + */ ++ (NSArray *)databaseIconTypes; + @end diff --git a/MacPass/MPIconHelper.m b/MacPass/MPIconHelper.m index c757e9cb..6853e4f1 100644 --- a/MacPass/MPIconHelper.m +++ b/MacPass/MPIconHelper.m @@ -29,7 +29,12 @@ dispatch_once(&onceToken, ^{ NSDictionary *imageNames = [MPIconHelper availableIconNames]; NSMutableArray *mutableIcons = [[NSMutableArray alloc] initWithCapacity:[imageNames count]]; - for(NSNumber *iconNumber in [imageNames allKeys]) { + + NSArray *sortedImageNames = [[imageNames allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { + return [[imageNames objectForKey:obj1] compare:[imageNames objectForKey:obj2]]; + }]; + + for(NSNumber *iconNumber in sortedImageNames) { if([iconNumber integerValue] > MPCustomIconTypeBegin) { continue; // Skip all non-db Keys } @@ -41,6 +46,30 @@ return icons; } + ++ (NSArray *)databaseIconTypes { + static NSArray *iconTypes; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSDictionary *imageNames = [MPIconHelper availableIconNames]; + NSMutableArray *mutableIcons = [[NSMutableArray alloc] initWithCapacity:[imageNames count]]; + + NSArray *sortedImageNames = [[imageNames allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { + return [[imageNames objectForKey:obj1] compare:[imageNames objectForKey:obj2]]; + }]; + + for(NSNumber *iconNumber in sortedImageNames) { + if([iconNumber integerValue] > MPCustomIconTypeBegin) { + continue; // Skip all non-db Keys + } + [mutableIcons addObject:iconNumber]; + } + iconTypes = mutableIcons; + }); + return iconTypes; +} + + + (NSDictionary *)availableIconNames { static NSDictionary *imageNames; static dispatch_once_t onceToken; diff --git a/MacPass/MPIconSelectViewController.m b/MacPass/MPIconSelectViewController.m index fcc62882..0a281705 100644 --- a/MacPass/MPIconSelectViewController.m +++ b/MacPass/MPIconSelectViewController.m @@ -58,7 +58,7 @@ NSInteger const kMPDefaultIcon = -1; NSButton *button = sender; NSImage *image = [button image]; NSUInteger buttonIndex = [[self.iconCollectionView content] indexOfObject:image]; - self.selectedIcon = [[[MPIconHelper availableIconNames] allKeys][buttonIndex] integerValue]; + self.selectedIcon = [[MPIconHelper databaseIconTypes] [buttonIndex] integerValue]; [self.popover performClose:self]; }