Broken commit - refactoring search

This commit is contained in:
michael starke
2014-02-24 12:05:41 +01:00
parent c084d49d95
commit 81dc24d9b2
12 changed files with 118 additions and 165 deletions

View File

@@ -199,7 +199,7 @@
4C8A173D1790AA41008B5C17 /* NSData+Keyfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8A173C1790AA41008B5C17 /* NSData+Keyfile.m */; }; 4C8A173D1790AA41008B5C17 /* NSData+Keyfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8A173C1790AA41008B5C17 /* NSData+Keyfile.m */; };
4C8B36AB17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8B36AA17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m */; }; 4C8B36AB17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8B36AA17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m */; };
4C8FECC816D57E3200BF26CF /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C8FECC716D57E3200BF26CF /* QuartzCore.framework */; }; 4C8FECC816D57E3200BF26CF /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C8FECC716D57E3200BF26CF /* QuartzCore.framework */; };
4C94DFCB1892860400F42F18 /* MPEntryFilterHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C94DFCA1892860400F42F18 /* MPEntryFilterHelper.m */; }; 4C94DFCB1892860400F42F18 /* MPDocumentSearchService.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C94DFCA1892860400F42F18 /* MPDocumentSearchService.m */; };
4C96D15417A12E4F00D931FA /* 99_CreatedTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C96D15317A12E4F00D931FA /* 99_CreatedTemplate.pdf */; }; 4C96D15417A12E4F00D931FA /* 99_CreatedTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C96D15317A12E4F00D931FA /* 99_CreatedTemplate.pdf */; };
4C9D6AA917615199001C660C /* HNHRoundedSecureTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C9D6AA817615199001C660C /* HNHRoundedSecureTextFieldCell.m */; }; 4C9D6AA917615199001C660C /* HNHRoundedSecureTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C9D6AA817615199001C660C /* HNHRoundedSecureTextFieldCell.m */; };
4CA08DA017A831B200A6544B /* MPAddEntryContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA08D9F17A831B200A6544B /* MPAddEntryContextMenuDelegate.m */; }; 4CA08DA017A831B200A6544B /* MPAddEntryContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA08D9F17A831B200A6544B /* MPAddEntryContextMenuDelegate.m */; };
@@ -690,8 +690,8 @@
4C8B36A917A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineContextMenuDelegate.h; sourceTree = "<group>"; }; 4C8B36A917A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineContextMenuDelegate.h; sourceTree = "<group>"; };
4C8B36AA17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOutlineContextMenuDelegate.m; sourceTree = "<group>"; }; 4C8B36AA17A6ED4B005E1FF1 /* MPOutlineContextMenuDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOutlineContextMenuDelegate.m; sourceTree = "<group>"; };
4C8FECC716D57E3200BF26CF /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 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 = "<group>"; }; 4C94DFC91892860400F42F18 /* MPDocumentSearchService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDocumentSearchService.h; sourceTree = "<group>"; };
4C94DFCA1892860400F42F18 /* MPEntryFilterHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryFilterHelper.m; sourceTree = "<group>"; }; 4C94DFCA1892860400F42F18 /* MPDocumentSearchService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDocumentSearchService.m; sourceTree = "<group>"; };
4C96D15317A12E4F00D931FA /* 99_CreatedTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = 99_CreatedTemplate.pdf; path = Icons/99_CreatedTemplate.pdf; sourceTree = "<group>"; }; 4C96D15317A12E4F00D931FA /* 99_CreatedTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = 99_CreatedTemplate.pdf; path = Icons/99_CreatedTemplate.pdf; sourceTree = "<group>"; };
4C9D6AA717615199001C660C /* HNHRoundedSecureTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHRoundedSecureTextFieldCell.h; sourceTree = "<group>"; }; 4C9D6AA717615199001C660C /* HNHRoundedSecureTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHRoundedSecureTextFieldCell.h; sourceTree = "<group>"; };
4C9D6AA817615199001C660C /* HNHRoundedSecureTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHRoundedSecureTextFieldCell.m; sourceTree = "<group>"; }; 4C9D6AA817615199001C660C /* HNHRoundedSecureTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHRoundedSecureTextFieldCell.m; sourceTree = "<group>"; };
@@ -1166,8 +1166,6 @@
4C4B7EF717A4B335000234C7 /* MPUniqueCharactersFormatter.m */, 4C4B7EF717A4B335000234C7 /* MPUniqueCharactersFormatter.m */,
4C224B4017DFCB2300FF6AEE /* MPNumericalInputFormatter.h */, 4C224B4017DFCB2300FF6AEE /* MPNumericalInputFormatter.h */,
4C224B4117DFCB2400FF6AEE /* MPNumericalInputFormatter.m */, 4C224B4117DFCB2400FF6AEE /* MPNumericalInputFormatter.m */,
4C94DFC91892860400F42F18 /* MPEntryFilterHelper.h */,
4C94DFCA1892860400F42F18 /* MPEntryFilterHelper.m */,
4CB63A6018986530002DEC4C /* MPFlagsHelper.h */, 4CB63A6018986530002DEC4C /* MPFlagsHelper.h */,
); );
name = Helper; name = Helper;
@@ -1211,6 +1209,8 @@
4C37A84215B8B495005EF8EE /* Model */ = { 4C37A84215B8B495005EF8EE /* Model */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
4C94DFC91892860400F42F18 /* MPDocumentSearchService.h */,
4C94DFCA1892860400F42F18 /* MPDocumentSearchService.m */,
4C37A83E15B8B474005EF8EE /* MPOutlineDataSource.h */, 4C37A83E15B8B474005EF8EE /* MPOutlineDataSource.h */,
4C37A83F15B8B474005EF8EE /* MPOutlineDataSource.m */, 4C37A83F15B8B474005EF8EE /* MPOutlineDataSource.m */,
4C569D9F17652BFE00595B62 /* MPEntryTableDataSource.h */, 4C569D9F17652BFE00595B62 /* MPEntryTableDataSource.h */,
@@ -2260,7 +2260,7 @@
4CC6DB7A17D23719002C6091 /* KPKNode+IconImage.m in Sources */, 4CC6DB7A17D23719002C6091 /* KPKNode+IconImage.m in Sources */,
4CC6DB7D17D23DCE002C6091 /* KPKUTIs.m in Sources */, 4CC6DB7D17D23DCE002C6091 /* KPKUTIs.m in Sources */,
4CEED1C617D7BD0E007180F1 /* NSError+Messages.m in Sources */, 4CEED1C617D7BD0E007180F1 /* NSError+Messages.m in Sources */,
4C94DFCB1892860400F42F18 /* MPEntryFilterHelper.m in Sources */, 4C94DFCB1892860400F42F18 /* MPDocumentSearchService.m in Sources */,
4C00E33817D8FA3500F37192 /* DDHotKeyCenter.m in Sources */, 4C00E33817D8FA3500F37192 /* DDHotKeyCenter.m in Sources */,
4C224B4217DFCB2400FF6AEE /* MPNumericalInputFormatter.m in Sources */, 4C224B4217DFCB2400FF6AEE /* MPNumericalInputFormatter.m in Sources */,
); );

View File

@@ -7,7 +7,7 @@
// //
#import "MPViewController.h" #import "MPViewController.h"
#import "MPEntryFilterHelper.h" #import "MPDocumentSearchService.h"
@protocol MPContextBarDelegate <NSObject> @protocol MPContextBarDelegate <NSObject>
@@ -22,13 +22,10 @@
@interface MPContextBarViewController : MPViewController @interface MPContextBarViewController : MPViewController
@property (nonatomic, assign) MPFilterMode filterMode;
@property (nonatomic, readonly) BOOL hasFilter; @property (nonatomic, readonly) BOOL hasFilter;
@property (nonatomic, weak) id<MPContextBarDelegate> delegate; @property (nonatomic, weak) id<MPContextBarDelegate> delegate;
@property (weak) NSView *nextKeyView; @property (weak) NSView *nextKeyView;
- (NSString *)filterString;
- (IBAction)toggleFilterSpace:(id)sender; - (IBAction)toggleFilterSpace:(id)sender;
- (IBAction)exitFilter:(id)sender; - (IBAction)exitFilter:(id)sender;

View File

@@ -9,7 +9,7 @@
#import "MPContextBarViewController.h" #import "MPContextBarViewController.h"
#import "HNHGradientView.h" #import "HNHGradientView.h"
#import "KPKEntry.h" #import "KPKEntry.h"
#import "MPEntryFilterHelper.h" #import "MPDocumentSearchService.h"
#import "NSButton+HNHTextColor.h" #import "NSButton+HNHTextColor.h"
@@ -34,10 +34,8 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
@property (nonatomic, assign) BOOL hasFilter; @property (nonatomic, assign) BOOL hasFilter;
/* Filter */ /* Filter */
@property (weak) IBOutlet NSPopUpButton *filterTypePopupButton;
@property (weak) IBOutlet NSButton *filterDoneButton; @property (weak) IBOutlet NSButton *filterDoneButton;
@property (weak) IBOutlet NSTextField *filterLabelTextField; @property (weak) IBOutlet NSTextField *filterLabelTextField;
@property (weak) IBOutlet NSSearchField *filterSearchField;
/* History */ /* History */
@property (weak) IBOutlet HNHGradientView *historyBar; @property (weak) IBOutlet HNHGradientView *historyBar;
@property (weak) IBOutlet NSTextField *historyLabel; @property (weak) IBOutlet NSTextField *historyLabel;
@@ -59,7 +57,6 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) { if (self) {
_hasFilter = NO; _hasFilter = NO;
_filterMode = MPFilterTitles;
_delegateRespondsToDidExitFilter = NO; _delegateRespondsToDidExitFilter = NO;
_delegateRespondsToDidExitHistory = NO; _delegateRespondsToDidExitHistory = NO;
_delegateRespondsToShouldEmptyTrash = NO; _delegateRespondsToShouldEmptyTrash = NO;
@@ -71,10 +68,6 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
- (void)didLoadView { - (void)didLoadView {
[[self.filterLabelTextField cell] setBackgroundStyle:NSBackgroundStyleRaised]; [[self.filterLabelTextField cell] setBackgroundStyle:NSBackgroundStyleRaised];
[self.filterTypePopupButton setMenu:[self _allocFilterMenu]];
[self.filterSearchField setAction:@selector(_didChangeFilter)];
[[self.filterSearchField cell] setSendsSearchStringImmediately:NO];
self.historyBar.activeGradient = [[NSGradient alloc] initWithStartingColor:[NSColor redColor] endingColor:[NSColor greenColor]]; self.historyBar.activeGradient = [[NSGradient alloc] initWithStartingColor:[NSColor redColor] endingColor:[NSColor greenColor]];
@@ -96,14 +89,13 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
[self.emptyTrashButton setNextKeyView:self.nextKeyView]; [self.emptyTrashButton setNextKeyView:self.nextKeyView];
[self.filterDoneButton setNextKeyView:self.nextKeyView]; [self.filterDoneButton setNextKeyView:self.nextKeyView];
} }
[self _updateFilterButtons];
[self _updateFilterMenu];
} }
#pragma mark Properties #pragma mark Properties
- (void)setFilterMode:(MPFilterMode)newFilterMode { - (void)setFilterMode:(MPFilterMode)newFilterMode {
if(_filterMode != newFilterMode) { if(_filterMode != newFilterMode) {
if(newFilterMode == MPFilterNone) { if(newFilterMode == MPEntrySearchNone) {
newFilterMode = MPFilterTitles; newFilterMode = MPFilterTitles;
} }
_filterMode = newFilterMode; _filterMode = newFilterMode;
@@ -123,7 +115,6 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
} }
- (void)disable { - (void)disable {
[self.filterSearchField setEnabled:NO];
} }
- (void)enable { - (void)enable {
@@ -145,22 +136,6 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
} }
} }
#pragma mark Actions
- (void)toggleFilterSpace:(id)sender {
if(![sender isKindOfClass:[NSMenuItem class]]) {
return; // Wrong sender
}
MPFilterMode toggledMode = [sender tag];
if(toggledMode & self.filterMode) {
/* Disable enabled flag */
self.filterMode ^= toggledMode;
}
else {
/* Enable disabled flag */
self.filterMode |= toggledMode;
}
}
- (void)exitFilter:(id)sender { - (void)exitFilter:(id)sender {
if(!self.hasFilter) { if(!self.hasFilter) {
return; // Nothing to do; return; // Nothing to do;
@@ -231,74 +206,4 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
// only the entry view has to be bound, the rest not // only the entry view has to be bound, the rest not
} }
- (NSMenu *)_allocFilterMenu {
NSMenu *searchMenu = [[NSMenu alloc] init];
NSMenuItem *activeFilterItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SEARCH_IN", "") action:NULL keyEquivalent:@""];
[activeFilterItem setTag:MPContextBarViewControllerActiveFilterMenuItemTag];
[searchMenu addItem:activeFilterItem];
[searchMenu addItem:[NSMenuItem separatorItem]];
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(@"DUPLICTE_PASSWORDS", "") action:NULL keyEquivalent:@""];
[doublePasswordsItem setTag:MPFilterDoublePasswords];
[searchMenu addItem:doublePasswordsItem];
return searchMenu;
}
- (void)_updateFilterMenu {
NSMenu *menu = [self.filterTypePopupButton menu];
NSArray *allItems = [menu itemArray];
NSArray *enabledItems = [self _filterItemsForMode:self.filterMode];
for(NSMenuItem *item in allItems) {
BOOL isSelected = [enabledItems containsObject:item];
[item setState:(isSelected ? NSOnState : NSOffState)];
}
NSMenuItem *activeFilterItem = [menu itemWithTag:MPContextBarViewControllerActiveFilterMenuItemTag];
__block NSMutableString *activeFilterTitle;
[enabledItems enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if(activeFilterTitle == nil) {
activeFilterTitle = [[NSMutableString alloc] initWithString:[obj title]];
}
else {
[activeFilterTitle appendFormat:@", %@", [obj title]];
}
}];
[activeFilterItem setTitle:activeFilterTitle];
[self.filterTypePopupButton selectItem:activeFilterItem];
}
- (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;
}
@end @end

View File

@@ -0,0 +1,40 @@
//
// MPSearchHelper.h
// MacPass
//
// Created by Michael Starke on 24/01/14.
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@class MPDocument;
FOUNDATION_EXTERN NSString *const MPSearchServiceSearchDidChangeNotification;
FOUNDATION_EXTERN NSString *const MPSearchServiceSearchWasClearedNotification;
typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
MPEntrySearchNone = 0,
MPEntrySearchUrls = (1<<0),
MPEntrySearchUsernames = (1<<1),
MPEntrySearchTitles = (1<<2),
MPEntrySearchPasswords = (1<<3),
MPEntrySearchNotes = (1<<4),
MPEntrySearchDoublePasswords = (1<<5)
};
@interface MPDocumentSearchService : NSObject
@property (nonatomic, assign) MPEntrySearchFlags activeFlags;
@property (nonatomic, copy) NSString *searchString;
+ (instancetype)sharedService;
- (NSArray *)entriesInDocument:(MPDocument *)document matching:(NSString *)string usingSearchMode:(MPEntrySearchFlags)mode;
- (NSArray *)optionsEnabledInMode:(MPEntrySearchFlags)mode;
/* Clears the search string, but doesn't exit searching */
- (IBAction)clearSearch:(id)sender;
/* exits searching mode */
- (IBAction)exitSearch:(id)sender;
@end

View File

@@ -6,17 +6,36 @@
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. // Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
// //
#import "MPEntryFilterHelper.h" #import "MPDocumentSearchService.h"
#import "MPDocument.h" #import "MPDocument.h"
#import "KPKGroup.h" #import "KPKGroup.h"
#import "KPKEntry.h" #import "KPKEntry.h"
#import "MPFlagsHelper.h" #import "MPFlagsHelper.h"
@implementation MPEntryFilterHelper @implementation MPDocumentSearchService
+ (NSArray *)entriesInDocument:(MPDocument *)document matching:(NSString *)filter usingFilterMode:(MPFilterMode)mode { static MPDocumentSearchService *_kMPSearchServiceInstance;
+ (instancetype)sharedService {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_kMPSearchServiceInstance = [[MPDocumentSearchService alloc] init];
});
return _kMPSearchServiceInstance;
}
- (instancetype)init {
NSAssert(_kMPSearchServiceInstance == nil, @"only one shared instance allowed");
self = [super init];
if(self) {
_activeFlags = MPEntrySearchTitles; // Default search is set to titles
}
return self;
}
- (NSArray *)entriesInDocument:(MPDocument *)document matching:(NSString *)string usingSearchMode:(MPEntrySearchFlags)mode {
/* Filter double passwords */ /* Filter double passwords */
if(MPTestFlagInOptions(MPFilterDoublePasswords, mode)) { if(MPTestFlagInOptions(MPEntrySearchDoublePasswords, mode)) {
__block NSMutableDictionary *passwordToEntryMap; __block NSMutableDictionary *passwordToEntryMap;
/* Build up a usage map */ /* Build up a usage map */
[[document.root childEntries] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [[document.root childEntries] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
@@ -41,7 +60,7 @@
return doublePasswords; return doublePasswords;
} }
/* Filter using predicates */ /* Filter using predicates */
NSArray *predicates = [self _filterPredicatesForMode:mode withFilter:filter]; NSArray *predicates = [self _filterPredicatesForMode:mode withString:string];
if(predicates) { if(predicates) {
NSPredicate *fullFilter = [NSCompoundPredicate orPredicateWithSubpredicates:predicates]; NSPredicate *fullFilter = [NSCompoundPredicate orPredicateWithSubpredicates:predicates];
return [[document.root childEntries] filteredArrayUsingPredicate:fullFilter]; return [[document.root childEntries] filteredArrayUsingPredicate:fullFilter];
@@ -50,35 +69,35 @@
return [document.root childEntries]; return [document.root childEntries];
} }
+ (NSArray *)optionsEnabledInMode:(MPFilterMode)mode { - (NSArray *)optionsEnabledInMode:(MPEntrySearchFlags)mode {
NSArray *allOptions = @[ @(MPFilterUrls), @(MPFilterUsernames), NSArray *allOptions = @[ @(MPEntrySearchUrls), @(MPEntrySearchUsernames),
@(MPFilterTitles), @(MPFilterPasswords) , @(MPEntrySearchTitles), @(MPEntrySearchPasswords) ,
@(MPFilterNotes), @(MPFilterDoublePasswords) ]; @(MPEntrySearchNotes), @(MPEntrySearchDoublePasswords) ];
NSIndexSet *indexes = [allOptions indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { NSIndexSet *indexes = [allOptions indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
MPFilterMode flag = [obj integerValue]; MPEntrySearchFlags flag = [obj integerValue];
return MPTestFlagInOptions(flag, mode); return MPTestFlagInOptions(flag, mode);
}]; }];
return [allOptions objectsAtIndexes:indexes]; return [allOptions objectsAtIndexes:indexes];
} }
+ (NSArray *)_filterPredicatesForMode:(MPFilterMode)mode withFilter:(NSString *)filter{ - (NSArray *)_filterPredicatesForMode:(MPEntrySearchFlags)mode withString:(NSString *)string{
NSMutableArray *prediactes = [[NSMutableArray alloc] initWithCapacity:4]; NSMutableArray *prediactes = [[NSMutableArray alloc] initWithCapacity:4];
if(MPTestFlagInOptions(MPFilterTitles, mode)) { if(MPTestFlagInOptions(MPEntrySearchTitles, mode)) {
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.title CONTAINS[cd] %@", filter]]; [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.title CONTAINS[cd] %@", string]];
} }
if(MPTestFlagInOptions(MPFilterUsernames, mode)) { if(MPTestFlagInOptions(MPEntrySearchUsernames, mode)) {
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.username CONTAINS[cd] %@", filter]]; [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.username CONTAINS[cd] %@", string]];
} }
if(MPTestFlagInOptions(MPFilterUrls, mode)) { if(MPTestFlagInOptions(MPEntrySearchUrls, mode)) {
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.url CONTAINS[cd] %@", filter]]; [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.url CONTAINS[cd] %@", string]];
} }
if(MPTestFlagInOptions(MPFilterPasswords, mode)) { if(MPTestFlagInOptions(MPEntrySearchPasswords, mode)) {
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.password CONTAINS[cd] %@", filter]]; [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.password CONTAINS[cd] %@", string]];
} }
if(MPTestFlagInOptions(MPFilterNotes, mode)) { if(MPTestFlagInOptions(MPEntrySearchNotes, mode)) {
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.notes CONTAINS[cd] %@", filter]]; [prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.notes CONTAINS[cd] %@", string]];
} }
return prediactes; return prediactes;
} }

View File

@@ -14,6 +14,7 @@
@class MPInspectorViewController; @class MPInspectorViewController;
@class MPPasswordInputController; @class MPPasswordInputController;
@class MPOutlineViewController; @class MPOutlineViewController;
@class MPToolbarDelegate;
@interface MPDocumentWindowController : NSWindowController <MPPasswordEditWindowDelegate> @interface MPDocumentWindowController : NSWindowController <MPPasswordEditWindowDelegate>
@@ -21,10 +22,12 @@
@property (readonly, strong) MPEntryViewController *entryViewController; @property (readonly, strong) MPEntryViewController *entryViewController;
@property (readonly, strong) MPOutlineViewController *outlineViewController; @property (readonly, strong) MPOutlineViewController *outlineViewController;
@property (readonly, strong) MPInspectorViewController *inspectorViewController; @property (readonly, strong) MPInspectorViewController *inspectorViewController;
@property (readonly, strong) MPToolbarDelegate *toolbarDelegate;
- (void)showEntries; - (void)showEntries;
- (void)showPasswordInput; - (void)showPasswordInput;
- (void)performFindPanelAction:(id)sender; - (IBAction)performFindPanelAction:(id)sender;
- (IBAction)cancelSearch:(id)sender;
- (IBAction)saveDocument:(id)sender; - (IBAction)saveDocument:(id)sender;

View File

@@ -46,7 +46,6 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
@property (strong) MPDatabaseSettingsWindowController *documentSettingsWindowController; @property (strong) MPDatabaseSettingsWindowController *documentSettingsWindowController;
@property (strong) MPDocumentWindowDelegate *documentWindowDelegate; @property (strong) MPDocumentWindowDelegate *documentWindowDelegate;
@property (strong) MPPasswordEditWindowController *passwordEditWindowController; @property (strong) MPPasswordEditWindowController *passwordEditWindowController;
@property (strong) MPToolbarDelegate *toolbarDelegate; @property (strong) MPToolbarDelegate *toolbarDelegate;
@end @end
@@ -222,6 +221,10 @@ typedef NS_ENUM(NSUInteger, MPAlertContext) {
[self.entryViewController showFilter:sender]; [self.entryViewController showFilter:sender];
} }
- (void)cancelSearch:(id)sender {
[self.entryViewController clearFilter:sender];
}
- (void)showPasswordInput { - (void)showPasswordInput {
if(!self.passwordInputController) { if(!self.passwordInputController) {
self.passwordInputController = [[MPPasswordInputController alloc] init]; self.passwordInputController = [[MPPasswordInputController alloc] init];

View File

@@ -1,27 +0,0 @@
//
// MPSearchHelper.h
// MacPass
//
// Created by Michael Starke on 24/01/14.
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@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

View File

@@ -37,6 +37,7 @@ typedef NS_ENUM( NSUInteger, MPCopyContentTypeTag) {
/* Clear the Search filter*/ /* Clear the Search filter*/
- (void)showFilter:(id)sender; - (void)showFilter:(id)sender;
- (void)clearFilter:(id)sender;
/* Copy/Paste */ /* Copy/Paste */
- (void)copyUsername:(id)sender; - (void)copyUsername:(id)sender;

View File

@@ -15,7 +15,7 @@
#import "MPPasteBoardController.h" #import "MPPasteBoardController.h"
#import "MPOverlayWindowController.h" #import "MPOverlayWindowController.h"
#import "MPContextBarViewController.h" #import "MPContextBarViewController.h"
#import "MPEntryFilterHelper.h" #import "MPDocumentSearchService.h"
#import "MPContextMenuHelper.h" #import "MPContextMenuHelper.h"
#import "MPActionHelper.h" #import "MPActionHelper.h"
@@ -335,7 +335,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
dispatch_async(backgroundQueue, ^{ dispatch_async(backgroundQueue, ^{
MPDocument *document = [[self windowController] document]; MPDocument *document = [[self windowController] document];
self.filteredEntries = [MPEntryFilterHelper entriesInDocument:document self.filteredEntries = [MPDocumentSearchService entriesInDocument:document
matching:self.contextBarViewController.filterString matching:self.contextBarViewController.filterString
usingFilterMode:self.contextBarViewController.filterMode]; usingFilterMode:self.contextBarViewController.filterMode];
@@ -353,6 +353,10 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
[self _showContextBar]; [self _showContextBar];
} }
- (void)clearFilter:(id)sender {
[self.contextBarViewController exitFilter:sender];
}
#pragma mark ContextBar #pragma mark ContextBar
- (void)_showTrashBar { - (void)_showTrashBar {
[self.contextBarViewController showTrash]; [self.contextBarViewController showTrash];

View File

@@ -26,6 +26,6 @@
@interface MPToolbarDelegate : NSObject <NSToolbarDelegate> @interface MPToolbarDelegate : NSObject <NSToolbarDelegate>
@property (weak) NSToolbarItem *searchItem; @property (weak, readonly) NSSearchField *searchField;
@end @end

View File

@@ -21,15 +21,18 @@
// //
#import "MPToolbarDelegate.h" #import "MPToolbarDelegate.h"
#import "MPIconHelper.h"
#import "MPAppDelegate.h"
#import "MPToolbarButton.h" #import "MPToolbarButton.h"
#import "MPToolbarItem.h" #import "MPToolbarItem.h"
#import "MPActionHelper.h"
#import "MPContextMenuHelper.h"
#import "MPContextToolbarButton.h" #import "MPContextToolbarButton.h"
#import "MPAddEntryContextMenuDelegate.h" #import "MPAddEntryContextMenuDelegate.h"
#import "MPActionHelper.h"
#import "MPContextMenuHelper.h"
#import "MPIconHelper.h"
#import "MPDocumentWindowController.h"
NSString *const MPToolbarItemLock = @"TOOLBAR_LOCK"; NSString *const MPToolbarItemLock = @"TOOLBAR_LOCK";
NSString *const MPToolbarItemAddGroup = @"TOOLBAR_ADD_GROUP"; NSString *const MPToolbarItemAddGroup = @"TOOLBAR_ADD_GROUP";
NSString *const MPToolbarItemAddEntry = @"TOOLBAR_ADD_ENTRY"; NSString *const MPToolbarItemAddEntry = @"TOOLBAR_ADD_ENTRY";
@@ -45,6 +48,7 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
@property (strong) NSMutableDictionary *toolbarItems; @property (strong) NSMutableDictionary *toolbarItems;
@property (strong) NSArray *toolbarIdentifiers; @property (strong) NSArray *toolbarIdentifiers;
@property (strong) NSDictionary *toolbarImages; @property (strong) NSDictionary *toolbarImages;
@property (weak) NSSearchField *searchField;
- (NSString *)_localizedLabelForToolbarItemIdentifier:(NSString *)identifier; - (NSString *)_localizedLabelForToolbarItemIdentifier:(NSString *)identifier;
- (SEL)_actionForToolbarItemIdentifier:(NSString *)identifier; - (SEL)_actionForToolbarItemIdentifier:(NSString *)identifier;
@@ -130,6 +134,10 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
else if( [itemIdentifier isEqualToString:MPToolbarItemSearch]){ else if( [itemIdentifier isEqualToString:MPToolbarItemSearch]){
NSSearchField *searchField = [[NSSearchField alloc] init]; NSSearchField *searchField = [[NSSearchField alloc] init];
[searchField setAction:@selector(performFindPanelAction:)]; [searchField setAction:@selector(performFindPanelAction:)];
NSSearchFieldCell *cell = [searchField cell];
[[cell cancelButtonCell] setAction:@selector(cancelSearch:)];
[[cell cancelButtonCell] setTarget:nil];
self.searchField = searchField;
[item setView:searchField]; [item setView:searchField];
} }
else { else {