From 1bd68d01947427815974eac0bb1a999288b4c793 Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 29 Jan 2014 12:20:16 +0100 Subject: [PATCH] Fixed problem with tab order when another tab was displayed in the context bar Began reworking filter selection in context bar --- MacPass.xcodeproj/project.pbxproj | 8 ++ MacPass/ContextBar.xib | 82 ++++----------- MacPass/MPContextBarViewController.h | 14 +-- MacPass/MPContextBarViewController.m | 151 ++++++++++++++------------- MacPass/MPEntryFilterHelper.h | 27 +++++ MacPass/MPEntryFilterHelper.m | 86 +++++++++++++++ MacPass/MPEntryViewController.m | 15 ++- MacPass/MPFlagsHelper.h | 27 +++++ 8 files changed, 257 insertions(+), 153 deletions(-) create mode 100644 MacPass/MPEntryFilterHelper.h create mode 100644 MacPass/MPEntryFilterHelper.m create mode 100644 MacPass/MPFlagsHelper.h diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 68c82b74..fc9452a4 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -195,6 +195,7 @@ 4C8A173D1790AA41008B5C17 /* NSData+Keyfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8A173C1790AA41008B5C17 /* NSData+Keyfile.m */; }; 4C8B36AB17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8B36AA17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m */; }; 4C8FECC816D57E3200BF26CF /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C8FECC716D57E3200BF26CF /* QuartzCore.framework */; }; + 4C94DFCB1892860400F42F18 /* MPEntryFilterHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C94DFCA1892860400F42F18 /* MPEntryFilterHelper.m */; }; 4C96D15417A12E4F00D931FA /* 99_CreatedTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C96D15317A12E4F00D931FA /* 99_CreatedTemplate.pdf */; }; 4C9D6AA917615199001C660C /* HNHRoundedSecureTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C9D6AA817615199001C660C /* HNHRoundedSecureTextFieldCell.m */; }; 4CA08DA017A831B200A6544B /* MPAddEntryContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA08D9F17A831B200A6544B /* MPAddEntryContextMenuDelegate.m */; }; @@ -630,6 +631,8 @@ 4C8B36A917A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineContextMenuDelegate.h; sourceTree = ""; }; 4C8B36AA17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOutlineContextMenuDelegate.m; sourceTree = ""; }; 4C8FECC716D57E3200BF26CF /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + 4C94DFC91892860400F42F18 /* MPEntryFilterHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryFilterHelper.h; sourceTree = ""; }; + 4C94DFCA1892860400F42F18 /* MPEntryFilterHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryFilterHelper.m; sourceTree = ""; }; 4C96D15317A12E4F00D931FA /* 99_CreatedTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = 99_CreatedTemplate.pdf; path = Icons/99_CreatedTemplate.pdf; sourceTree = ""; }; 4C9D6AA717615199001C660C /* HNHRoundedSecureTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHRoundedSecureTextFieldCell.h; sourceTree = ""; }; 4C9D6AA817615199001C660C /* HNHRoundedSecureTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHRoundedSecureTextFieldCell.m; sourceTree = ""; }; @@ -667,6 +670,7 @@ 4CAF62FA1763604000CD7084 /* HNHBadgedTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHBadgedTextFieldCell.h; sourceTree = ""; }; 4CAF62FB1763604000CD7084 /* HNHBadgedTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHBadgedTextFieldCell.m; sourceTree = ""; }; 4CB4AA0C17C2274200454CAD /* KeePass1_native_test.kdb */ = {isa = PBXFileReference; lastKnownFileType = file; name = KeePass1_native_test.kdb; path = Databases/KeePass1_native_test.kdb; sourceTree = ""; }; + 4CB63A6018986530002DEC4C /* MPFlagsHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPFlagsHelper.h; sourceTree = ""; }; 4CB9339816D3A0DD00A13B5D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = ""; }; 4CBA2AB617074B59006D8139 /* MPSettingsHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSettingsHelper.h; sourceTree = ""; }; 4CBA2AB917074C07006D8139 /* MPSettingsHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSettingsHelper.m; sourceTree = ""; }; @@ -1093,6 +1097,9 @@ 4C4B7EF717A4B335000234C7 /* MPUniqueCharactersFormatter.m */, 4C224B4017DFCB2300FF6AEE /* MPNumericalInputFormatter.h */, 4C224B4117DFCB2400FF6AEE /* MPNumericalInputFormatter.m */, + 4C94DFC91892860400F42F18 /* MPEntryFilterHelper.h */, + 4C94DFCA1892860400F42F18 /* MPEntryFilterHelper.m */, + 4CB63A6018986530002DEC4C /* MPFlagsHelper.h */, ); name = Helper; sourceTree = ""; @@ -2096,6 +2103,7 @@ 4CC6DB7A17D23719002C6091 /* KPKNode+IconImage.m in Sources */, 4CC6DB7D17D23DCE002C6091 /* KPKUTIs.m in Sources */, 4CEED1C617D7BD0E007180F1 /* NSError+Messages.m in Sources */, + 4C94DFCB1892860400F42F18 /* MPEntryFilterHelper.m in Sources */, 4C00E33817D8FA3500F37192 /* DDHotKeyCenter.m in Sources */, 4C224B4217DFCB2400FF6AEE /* MPNumericalInputFormatter.m in Sources */, ); diff --git a/MacPass/ContextBar.xib b/MacPass/ContextBar.xib index 8d47374b..c2133548 100644 --- a/MacPass/ContextBar.xib +++ b/MacPass/ContextBar.xib @@ -11,11 +11,8 @@ - - - - + @@ -38,18 +35,7 @@ - - + @@ -58,28 +44,6 @@ - - @@ -103,36 +70,22 @@ - + + + + + + - - - - - - - - - - - - @@ -143,6 +96,9 @@ + + + @@ -179,6 +135,9 @@ + + + @@ -224,6 +183,9 @@ + + + diff --git a/MacPass/MPContextBarViewController.h b/MacPass/MPContextBarViewController.h index 7aca70e5..9e4876b1 100644 --- a/MacPass/MPContextBarViewController.h +++ b/MacPass/MPContextBarViewController.h @@ -7,6 +7,7 @@ // #import "MPViewController.h" +#import "MPEntryFilterHelper.h" @protocol MPContextBarDelegate @@ -17,33 +18,24 @@ - (void)contextBarShouldEmptyTrash; @end -typedef NS_OPTIONS(NSUInteger, MPFilterModeType) { - MPFilterNone = 0, - MPFilterUrls = (1<<0), - MPFilterUsernames = (1<<1), - MPFilterTitles = (1<<2), - MPFilterPasswords = (1<<3), -}; - @class HNHGradientView; @interface MPContextBarViewController : MPViewController -@property (nonatomic, assign) MPFilterModeType filterMode; +@property (nonatomic, assign) MPFilterMode filterMode; @property (nonatomic, readonly) BOOL hasFilter; @property (nonatomic, weak) id delegate; @property (weak) NSView *nextKeyView; - (NSString *)filterString; -- (NSArray *)filterPredicates; - (IBAction)toggleFilterSpace:(id)sender; +- (IBAction)exitFilter:(id)sender; - (BOOL)showsFilter; - (BOOL)showsHistory; - (BOOL)showsTrash; -- (void)exitFilter; - (void)showFilter; - (void)showHistory; diff --git a/MacPass/MPContextBarViewController.m b/MacPass/MPContextBarViewController.m index 5dcaa807..732e4aba 100644 --- a/MacPass/MPContextBarViewController.m +++ b/MacPass/MPContextBarViewController.m @@ -8,6 +8,8 @@ #import "MPContextBarViewController.h" #import "HNHGradientView.h" +#import "KPKEntry.h" +#import "MPEntryFilterHelper.h" typedef NS_ENUM(NSUInteger, MPContextTab) { MPContextTabFilter, @@ -27,11 +29,8 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { @property (nonatomic, assign) BOOL hasFilter; /* Filter */ +@property (weak) IBOutlet NSPopUpButton *filterTypePopupButton; @property (weak) IBOutlet NSButton *filterDoneButton; -@property (weak) IBOutlet NSButton *filterTitleButton; -@property (weak) IBOutlet NSButton *filterUsernameButton; -@property (weak) IBOutlet NSButton *filterURLButton; -@property (weak) IBOutlet NSButton *filterPasswordButton; @property (weak) IBOutlet NSTextField *filterLabelTextField; @property (weak) IBOutlet NSSearchField *filterSearchField; /* History */ @@ -65,14 +64,10 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { } - (void)didLoadView { - [self.filterURLButton setTag:MPFilterUrls]; - [self.filterUsernameButton setTag:MPFilterUsernames]; - [self.filterTitleButton setTag:MPFilterTitles]; - [self.filterPasswordButton setTag:MPFilterPasswords]; + [[self.filterLabelTextField cell] setBackgroundStyle:NSBackgroundStyleRaised]; - [self.filterDoneButton setAction:@selector(exitFilter)]; - [self.filterDoneButton setTarget:self]; - + [self.filterTypePopupButton setMenu:[self _allocFilterMenu]]; + [self.filterSearchField setAction:@selector(_didChangeFilter)]; [[self.filterSearchField cell] setSendsSearchStringImmediately:NO]; @@ -97,13 +92,13 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { } #pragma mark Properties -- (void)setFilterMode:(MPFilterModeType)newFilterMode { +- (void)setFilterMode:(MPFilterMode)newFilterMode { if(_filterMode != newFilterMode) { if(newFilterMode == MPFilterNone) { newFilterMode = MPFilterTitles; } _filterMode = newFilterMode; - [self _updateFilterButtons]; + [self _updateFilterMenu]; [self _didChangeFilter]; } } @@ -141,33 +136,13 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { } } -- (NSArray *)filterPredicates { - if(![self hasFilter]) { - return nil; - } - NSMutableArray *prediactes = [[NSMutableArray alloc] initWithCapacity:4]; - if([self _shouldFilterTitles]) { - [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.title CONTAINS[cd] %@", [self filterString]]]; - } - if([self _shouldFilterUsernames]) { - [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.username CONTAINS[cd] %@", [self filterString]]]; - } - if([self _shouldFilterURLs]) { - [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.url CONTAINS[cd] %@", [self filterString]]]; - } - if([self _shouldFilterPasswords]) { - [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.password CONTAINS[cd] %@", [self filterString]]]; - } - return prediactes; -} - -- (IBAction)toggleFilterSpace:(id)sender { - if(![sender isKindOfClass:[NSButton class]]) { +#pragma mark Actions +- (void)toggleFilterSpace:(id)sender { + if(![sender isKindOfClass:[NSMenuItem class]]) { return; // Wrong sender } - NSButton *button = sender; - MPFilterModeType toggledMode = [button tag]; - switch ([button state]) { + MPFilterMode toggledMode = [sender tag]; + switch ([sender state]) { case NSOnState: self.filterMode |= toggledMode; break; @@ -181,6 +156,20 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { } } +- (void)exitFilter:(id)sender { + if(!self.hasFilter) { + return; // Nothing to do; + } + if(![self showsFilter]) { + return; // We arent displaying the filter view + } + self.hasFilter = NO; + [self.filterSearchField setStringValue:@""]; + if(_delegateRespondsToDidExitFilter) { + [self.delegate contextBarDidExitFilter]; + } +} + - (void)showFilter { self.hasFilter = YES; /* Select text if already visible */ @@ -188,17 +177,17 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { [self.filterSearchField selectText:self]; } self.activeTab = MPContextTabFilter; - [self _updateFilterButtons]; + [self _updateFilterMenu]; } - (void)showHistory { - [self exitFilter]; + [self exitFilter:self]; self.activeTab = MPContextTabHistory; [self _updateBindings]; } - (void)showTrash { - [self exitFilter]; + [self exitFilter:self]; self.activeTab = MPContextTabTrash; [self _updateBindings]; } @@ -226,52 +215,68 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { return NO; } -- (void)exitFilter { - if(!self.hasFilter) { - return; // Nothing to do; - } - if(![self showsFilter]) { - return; // We arent displaying the filter view - } - self.hasFilter = NO; - [self.filterSearchField setStringValue:@""]; - if(_delegateRespondsToDidExitFilter) { - [self.delegate contextBarDidExitFilter]; - } -} - - (void)_didChangeFilter { if(_delegateRespondsToDidChangeFilter) { [self.delegate contextBarDidChangeFilter]; } } +#pragma mark UI Helper - (void)_updateBindings { // only the entry view has to be bound, the rest not } -- (void)_updateFilterButtons { - [self.filterTitleButton setState:[self _shouldFilterTitles] ? NSOnState : NSOffState]; - [self.filterURLButton setState:[self _shouldFilterURLs] ? NSOnState : NSOffState ]; - [self.filterUsernameButton setState:[self _shouldFilterUsernames] ? NSOnState : NSOffState]; - [self.filterPasswordButton setState:[self _shouldFilterPasswords] ? NSOnState : NSOffState]; +- (NSMenu *)_allocFilterMenu { + NSMenu *searchMenu = [[NSMenu alloc] init]; + + NSArray *titles = @[NSLocalizedString(@"TITLE", ""), + NSLocalizedString(@"PASSWORD", ""), + NSLocalizedString(@"URL", ""), + NSLocalizedString(@"USERNAME", "") + ]; + NSArray *tags = @[ @(MPFilterTitles), + @(MPFilterPasswords), + @(MPFilterUrls), + @(MPFilterUsernames) ]; + /* Attributes */ + for(NSUInteger index = 0; index < [tags count]; index++) { + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:titles[index] action:@selector(toggleFilterSpace:) keyEquivalent:@""]; + [item setTag:[tags[index] integerValue]]; + [item setTarget:self]; + [searchMenu addItem:item]; + } + [searchMenu addItem:[NSMenuItem separatorItem]]; + /* Special Search */ + NSMenuItem *doublePasswordsItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"", "") action:NULL keyEquivalent:@""]; + [doublePasswordsItem setTag:MPFilterDoublePasswords]; + + [searchMenu addItem:doublePasswordsItem]; + + return searchMenu; } -- (BOOL)_shouldFilterTitles { - return (MPFilterNone != (self.filterMode & MPFilterTitles)); +- (void)_updateFilterMenu { + NSMenu *menu = [self.filterTypePopupButton menu]; + NSArray *allItems = [menu itemArray]; + NSArray *enabledItems = [self _filterItemsForMode:self.filterMode]; + for(NSMenuItem *item in allItems) { + BOOL isEnabeld = [enabledItems containsObject:item]; + [item setEnabled:isEnabeld]; + } } -- (BOOL)_shouldFilterURLs { - return (MPFilterNone != (self.filterMode & MPFilterUrls)); +- (NSArray *)_filterItemsForMode:(MPFilterMode)mode { + NSArray *options = [MPEntryFilterHelper optionsEnabledInMode:mode]; + NSMenu *menu = [self.filterTypePopupButton menu]; + NSMutableArray *menuItems = [[NSMutableArray alloc] initWithCapacity:[[menu itemArray] count]]; + for(NSNumber *number in options) { + MPFilterMode flag = [number integerValue]; + NSMenuItem *flagItem = [menu itemWithTag:flag]; + if(flagItem) { + [menuItems addObject:flagItem]; + } + } + return menuItems; } -- (BOOL)_shouldFilterUsernames { - return (MPFilterNone != (self.filterMode & MPFilterUsernames)); -} - -- (BOOL)_shouldFilterPasswords { - return (MPFilterNone != (self.filterMode & MPFilterPasswords)); -} - - @end diff --git a/MacPass/MPEntryFilterHelper.h b/MacPass/MPEntryFilterHelper.h new file mode 100644 index 00000000..3d9a700a --- /dev/null +++ b/MacPass/MPEntryFilterHelper.h @@ -0,0 +1,27 @@ +// +// MPSearchHelper.h +// MacPass +// +// Created by Michael Starke on 24/01/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#import + +@class MPDocument; + +typedef NS_OPTIONS(NSUInteger, MPFilterMode) { + MPFilterNone = 0, + MPFilterUrls = (1<<0), + MPFilterUsernames = (1<<1), + MPFilterTitles = (1<<2), + MPFilterPasswords = (1<<3), + MPFilterNotes = (1<<4), + MPFilterDoublePasswords = (1<<5) +}; + +@interface MPEntryFilterHelper : NSObject + ++ (NSArray *)entriesInDocument:(MPDocument *)document matching:(NSString *)filter usingFilterMode:(MPFilterMode)mode; ++ (NSArray *)optionsEnabledInMode:(MPFilterMode)mode; +@end diff --git a/MacPass/MPEntryFilterHelper.m b/MacPass/MPEntryFilterHelper.m new file mode 100644 index 00000000..aa82bc9f --- /dev/null +++ b/MacPass/MPEntryFilterHelper.m @@ -0,0 +1,86 @@ +// +// MPSearchHelper.m +// MacPass +// +// Created by Michael Starke on 24/01/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#import "MPEntryFilterHelper.h" +#import "MPDocument.h" +#import "KPKGroup.h" +#import "KPKEntry.h" +#import "MPFlagsHelper.h" + +@implementation MPEntryFilterHelper + ++ (NSArray *)entriesInDocument:(MPDocument *)document matching:(NSString *)filter usingFilterMode:(MPFilterMode)mode { + /* Filter double passwords */ + if(MPTestFlagInOptions(MPFilterDoublePasswords, mode)) { + __block NSMutableDictionary *passwordToEntryMap; + /* Build up a usage map */ + [[document.root childEntries] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + KPKEntry *entry = obj; + NSMutableSet *entrySet = passwordToEntryMap[entry.password]; + if(entrySet) { + [entrySet addObject:entry]; + } + else { + passwordToEntryMap[entry.password] = [NSMutableSet setWithObject:entry]; + } + }]; + /* check for usage count */ + __block NSMutableArray *doublePasswords = [[NSMutableArray alloc] init]; + [[passwordToEntryMap allKeys] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + NSSet *entrySet = passwordToEntryMap[obj]; + KPKEntry *entry = [entrySet anyObject]; + if(entry) { + [doublePasswords addObject:entry]; + } + }]; + return doublePasswords; + } + /* Filter using predicates */ + NSArray *predicates = [self _filterPredicatesForMode:mode withFilter:filter]; + if(predicates) { + NSPredicate *fullFilter = [NSCompoundPredicate orPredicateWithSubpredicates:predicates]; + return [[document.root childEntries] filteredArrayUsingPredicate:fullFilter]; + } + /* No filter, just return everything */ + return [document.root childEntries]; +} + ++ (NSArray *)optionsEnabledInMode:(MPFilterMode)mode { + NSArray *allOptions = @[ @(MPFilterUrls), @(MPFilterUsernames), + @(MPFilterTitles), @(MPFilterPasswords) , + @(MPFilterNotes), @(MPFilterDoublePasswords) ]; + + NSIndexSet *indexes = [allOptions indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { + MPFilterMode flag = [obj integerValue]; + return MPTestFlagInOptions(flag, mode); + }]; + return [allOptions objectsAtIndexes:indexes]; +} + ++ (NSArray *)_filterPredicatesForMode:(MPFilterMode)mode withFilter:(NSString *)filter{ + NSMutableArray *prediactes = [[NSMutableArray alloc] initWithCapacity:4]; + + if(MPTestFlagInOptions(MPFilterTitles, mode)) { + [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.title CONTAINS[cd] %@", filter]]; + } + if(MPTestFlagInOptions(MPFilterUsernames, mode)) { + [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.username CONTAINS[cd] %@", filter]]; + } + if(MPTestFlagInOptions(MPFilterUrls, mode)) { + [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.url CONTAINS[cd] %@", filter]]; + } + if(MPTestFlagInOptions(MPFilterPasswords, mode)) { + [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.password CONTAINS[cd] %@", filter]]; + } + if(MPTestFlagInOptions(MPFilterNotes, mode)) { + [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.notes CONTAINS[cd] %@", filter]]; + } + return prediactes; +} + +@end diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 99f9c3d5..caf2aba4 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -15,6 +15,7 @@ #import "MPPasteBoardController.h" #import "MPOverlayWindowController.h" #import "MPContextBarViewController.h" +#import "MPEntryFilterHelper.h" #import "MPContextMenuHelper.h" #import "MPActionHelper.h" @@ -299,7 +300,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; if(document.selectedItem == document.selectedGroup) { /* If we change to a group selection, we should clear the filter */ if(_isDisplayingContextBar) { - [self.contextBarViewController exitFilter]; + [self.contextBarViewController exitFilter:self]; } else if([[self.entryArrayController content] count] > 0) { KPKEntry *entry = [[self.entryArrayController content] lastObject]; @@ -333,14 +334,10 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(backgroundQueue, ^{ MPDocument *document = [[self windowController] document]; - NSArray *predicates = [self.contextBarViewController filterPredicates]; - if(predicates) { - NSPredicate *fullFilter = [NSCompoundPredicate orPredicateWithSubpredicates:predicates]; - self.filteredEntries = [[document.root childEntries] filteredArrayUsingPredicate:fullFilter]; - } - else { - self.filteredEntries = [document.root childEntries]; - } + + self.filteredEntries = [MPEntryFilterHelper entriesInDocument:document + matching:self.contextBarViewController.filterString + usingFilterMode:self.contextBarViewController.filterMode]; dispatch_sync(dispatch_get_main_queue(), ^{ document.selectedEntry = nil; diff --git a/MacPass/MPFlagsHelper.h b/MacPass/MPFlagsHelper.h new file mode 100644 index 00000000..af0bc1d9 --- /dev/null +++ b/MacPass/MPFlagsHelper.h @@ -0,0 +1,27 @@ +// +// MPFlagsHelper.h +// MacPass +// +// Created by Michael Starke on 28/01/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#ifndef MacPass_MPFlagsHelper_h +#define MacPass_MPFlagsHelper_h + +#include +/** + * Tests if the given flag is set in the mode options. + * The test operatats on bit flag leve. Hence it will return YES + * if only one single bit is common in both parameters! + * + * @param options single flag to test for + * @param flag options to test for flag + * + * @return YES if any bit of flag is set in mode + */ +static BOOL MPTestFlagInOptions(const NSUInteger flag, const NSUInteger options ) { + return (0 != (options & flag)); +} + +#endif