Adopted new KeePassKit API, modernized Object-C syntax, optimized MPIconHelper

Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
michael starke
2015-08-05 15:34:03 +02:00
parent f1db1d4df5
commit a1a3017ef4
4 changed files with 19 additions and 22 deletions

View File

@@ -460,6 +460,7 @@
4C10412B178CDD44001B5239 /* NSDate+Humanized.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+Humanized.m"; sourceTree = "<group>"; }; 4C10412B178CDD44001B5239 /* NSDate+Humanized.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+Humanized.m"; sourceTree = "<group>"; };
4C13904C17ADD1A300A62934 /* KPKTreeCrypting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KPKTreeCrypting.h; sourceTree = "<group>"; }; 4C13904C17ADD1A300A62934 /* KPKTreeCrypting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KPKTreeCrypting.h; sourceTree = "<group>"; };
4C13904D17ADD3BE00A62934 /* KPKTreeWriting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KPKTreeWriting.h; sourceTree = "<group>"; }; 4C13904D17ADD3BE00A62934 /* KPKTreeWriting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KPKTreeWriting.h; sourceTree = "<group>"; };
4C13C3CF1B7241550085C291 /* KPKIconTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KPKIconTypes.h; sourceTree = "<group>"; };
4C15B74518BCA3B1003F8008 /* MPDocument+Search.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPDocument+Search.m"; sourceTree = "<group>"; }; 4C15B74518BCA3B1003F8008 /* MPDocument+Search.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPDocument+Search.m"; sourceTree = "<group>"; };
4C17D8E317A1C780006C8C1E /* MPDocumentWindowDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDocumentWindowDelegate.h; sourceTree = "<group>"; }; 4C17D8E317A1C780006C8C1E /* MPDocumentWindowDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDocumentWindowDelegate.h; sourceTree = "<group>"; };
4C17D8E417A1C780006C8C1E /* MPDocumentWindowDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDocumentWindowDelegate.m; sourceTree = "<group>"; }; 4C17D8E417A1C780006C8C1E /* MPDocumentWindowDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDocumentWindowDelegate.m; sourceTree = "<group>"; };
@@ -1173,6 +1174,7 @@
4C0104BF17C37DFC00173EF3 /* KPKTypes.h */, 4C0104BF17C37DFC00173EF3 /* KPKTypes.h */,
4CC6DB7B17D23DCE002C6091 /* KPKUTIs.h */, 4CC6DB7B17D23DCE002C6091 /* KPKUTIs.h */,
4CC6DB7C17D23DCE002C6091 /* KPKUTIs.m */, 4CC6DB7C17D23DCE002C6091 /* KPKUTIs.m */,
4C13C3CF1B7241550085C291 /* KPKIconTypes.h */,
); );
path = Utilites; path = Utilites;
sourceTree = "<group>"; sourceTree = "<group>";

View File

@@ -541,7 +541,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(group == self.trash) { if(group == self.trash) {
return; //Group is trash! return; //Group is trash!
} }
[group moveToGroup:self.trash atIndex:[self.trash.groups count]]; [group moveToGroup:self.trash];
[[self undoManager] setActionName:NSLocalizedString(@"TRASH_GROUP", "Move Group to Trash")]; [[self undoManager] setActionName:NSLocalizedString(@"TRASH_GROUP", "Move Group to Trash")];
} }
else { else {

View File

@@ -28,17 +28,17 @@
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
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];
NSArray *sortedImageNames = [[imageNames allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { NSArray *sortedImageNames = [imageNames.allKeys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [[imageNames objectForKey:obj1] compare:[imageNames objectForKey:obj2]]; return [imageNames[obj1] compare:imageNames[obj2]];
}]; }];
for(NSNumber *iconNumber in sortedImageNames) { 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
} }
MPIconType iconType = (MPIconType)[iconNumber integerValue]; MPIconType iconType = (MPIconType)iconNumber.integerValue;
[mutableIcons addObject:[MPIconHelper icon:iconType]]; [mutableIcons addObject:[MPIconHelper icon:iconType]];
} }
icons = [mutableIcons copy]; icons = [mutableIcons copy];
@@ -52,19 +52,14 @@
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
NSDictionary *imageNames = [MPIconHelper availableIconNames]; NSDictionary *imageNames = [MPIconHelper availableIconNames];
NSMutableArray *mutableIcons = [[NSMutableArray alloc] initWithCapacity:[imageNames count]];
NSArray *sortedImageNames = [[imageNames allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { NSArray *sortedImageNames = [[imageNames allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [[imageNames objectForKey:obj1] compare:[imageNames objectForKey:obj2]]; return [[imageNames objectForKey:obj1] compare:[imageNames objectForKey:obj2]];
}]; }];
iconTypes = [sortedImageNames filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
for(NSNumber *iconNumber in sortedImageNames) { NSNumber *iconNumber = (NSNumber *)evaluatedObject;
if([iconNumber integerValue] > MPCustomIconTypeBegin) { return (iconNumber.integerValue < MPCustomIconTypeBegin);
continue; // Skip all non-db Keys }]];
}
[mutableIcons addObject:iconNumber];
}
iconTypes = [mutableIcons copy];
}); });
return iconTypes; return iconTypes;
} }

View File

@@ -41,10 +41,10 @@ NSInteger const kMPDefaultIcon = -1;
- (void)didLoadView { - (void)didLoadView {
//[[self.imageButton cell] setBackgroundStyle:NSBackgroundStyleLowered]; //[[self.imageButton cell] setBackgroundStyle:NSBackgroundStyleLowered];
[self.iconCollectionView setBackgroundColors:@[[NSColor clearColor]]]; self.iconCollectionView.backgroundColors = @[[NSColor clearColor]];
[self.iconCollectionView setSelectable:YES]; self.iconCollectionView.selectable = YES;
[self.iconCollectionView setAllowsMultipleSelection:NO]; self.iconCollectionView.allowsMultipleSelection = NO;
[self.iconCollectionView setContent:[MPIconHelper databaseIcons]]; self.iconCollectionView.content = [MPIconHelper databaseIcons];
} }
- (IBAction)useDefault:(id)sender { - (IBAction)useDefault:(id)sender {
@@ -66,9 +66,9 @@ NSInteger const kMPDefaultIcon = -1;
- (IBAction)_selectImage:(id)sender { - (IBAction)_selectImage:(id)sender {
self.didCancel = NO; self.didCancel = NO;
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 databaseIconTypes] [buttonIndex] integerValue]; self.selectedIcon = ((NSNumber *)[MPIconHelper databaseIconTypes][buttonIndex]).integerValue;
[self.popover performClose:self]; [self.popover performClose:self];
} }