From ea6db31d030f86fd99828c91f792ee90a0955283 Mon Sep 17 00:00:00 2001 From: Dennis Bolio Date: Tue, 15 Apr 2014 00:01:26 +0200 Subject: [PATCH] Fixed sorting and selection of database icons (issue #118) --- MacPass/MPIconHelper.h | 6 ++++++ MacPass/MPIconHelper.m | 31 +++++++++++++++++++++++++++- MacPass/MPIconSelectViewController.m | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/MacPass/MPIconHelper.h b/MacPass/MPIconHelper.h index c4f45ba2..52beeab1 100644 --- a/MacPass/MPIconHelper.h +++ b/MacPass/MPIconHelper.h @@ -78,4 +78,10 @@ typedef NS_ENUM(NSUInteger, MPIconType) { */ + (NSArray *)databaseIcons; +/** + * List of all available DatabaseIcons as MPIconType. Sorted by IconIndex + * @return Array of Names as NSNumber objects + */ ++ (NSArray *)databaseIconType; + @end diff --git a/MacPass/MPIconHelper.m b/MacPass/MPIconHelper.m index c757e9cb..70ecbf17 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 *)databaseIconType { + 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..a613e587 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 databaseIconType] [buttonIndex] integerValue]; [self.popover performClose:self]; }