mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 21:13:35 +00:00
Fixed sorting and selection of database icons (issue #118)
This commit is contained in:
@@ -78,4 +78,10 @@ typedef NS_ENUM(NSUInteger, MPIconType) {
|
|||||||
*/
|
*/
|
||||||
+ (NSArray *)databaseIcons;
|
+ (NSArray *)databaseIcons;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of all available DatabaseIcons as MPIconType. Sorted by IconIndex
|
||||||
|
* @return Array of Names as NSNumber objects
|
||||||
|
*/
|
||||||
|
+ (NSArray *)databaseIconType;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -29,7 +29,12 @@
|
|||||||
dispatch_once(&onceToken, ^{
|
dispatch_once(&onceToken, ^{
|
||||||
NSDictionary *imageNames = [MPIconHelper availableIconNames];
|
NSDictionary *imageNames = [MPIconHelper availableIconNames];
|
||||||
NSMutableArray *mutableIcons = [[NSMutableArray alloc] initWithCapacity:[imageNames count]];
|
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) {
|
if([iconNumber integerValue] > MPCustomIconTypeBegin) {
|
||||||
continue; // Skip all non-db Keys
|
continue; // Skip all non-db Keys
|
||||||
}
|
}
|
||||||
@@ -41,6 +46,30 @@
|
|||||||
return icons;
|
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 {
|
+ (NSDictionary *)availableIconNames {
|
||||||
static NSDictionary *imageNames;
|
static NSDictionary *imageNames;
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ NSInteger const kMPDefaultIcon = -1;
|
|||||||
NSButton *button = sender;
|
NSButton *button = sender;
|
||||||
NSImage *image = [button image];
|
NSImage *image = [button image];
|
||||||
NSUInteger buttonIndex = [[self.iconCollectionView content] indexOfObject: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];
|
[self.popover performClose:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user