From de00a42f02dfef16e83b6309cc5edd36bcd8b445 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 24 Feb 2014 23:27:05 +0100 Subject: [PATCH] broke commit --- MacPass/MPDocumentSearchService.h | 8 ++++++-- MacPass/MPDocumentSearchService.m | 28 ++++++++++++++++++++++++++++ MacPass/MPToolbarDelegate.h | 2 -- MacPass/MPToolbarDelegate.m | 2 +- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/MacPass/MPDocumentSearchService.h b/MacPass/MPDocumentSearchService.h index e7e6f04e..e41a2282 100644 --- a/MacPass/MPDocumentSearchService.h +++ b/MacPass/MPDocumentSearchService.h @@ -10,8 +10,9 @@ @class MPDocument; -FOUNDATION_EXTERN NSString *const MPSearchServiceSearchDidChangeNotification; -FOUNDATION_EXTERN NSString *const MPSearchServiceSearchWasClearedNotification; +FOUNDATION_EXTERN NSString *const MPDocumentSearchServiceDidChangeSearchNotification; +FOUNDATION_EXTERN NSString *const MPDocumentSearchServiceDidClearSearchNotification; +FOUNDATION_EXTERN NSString *const MPDocumentSearchServiceDidExitSearchNotification; typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) { MPEntrySearchNone = 0, @@ -27,11 +28,14 @@ typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) { @property (nonatomic, assign) MPEntrySearchFlags activeFlags; @property (nonatomic, copy) NSString *searchString; +@property (nonatomic, weak) NSSearchField *searchField; + (instancetype)sharedService; - (NSArray *)entriesInDocument:(MPDocument *)document matching:(NSString *)string usingSearchMode:(MPEntrySearchFlags)mode; - (NSArray *)optionsEnabledInMode:(MPEntrySearchFlags)mode; +/* Should be called by the NSSearchTextField to update the search string */ +- (IBAction)updateSearch:(id)sender; /* Clears the search string, but doesn't exit searching */ - (IBAction)clearSearch:(id)sender; /* exits searching mode */ diff --git a/MacPass/MPDocumentSearchService.m b/MacPass/MPDocumentSearchService.m index d1c3c441..d129e36a 100644 --- a/MacPass/MPDocumentSearchService.m +++ b/MacPass/MPDocumentSearchService.m @@ -12,6 +12,10 @@ #import "KPKEntry.h" #import "MPFlagsHelper.h" +NSString *const MPDocumentSearchServiceDidChangeSearchNotification = @"com.hicknhack.macpass.MPDocumentSearchServiceDidChangeSearchNotification"; +NSString *const MPDocumentSearchServiceDidClearSearchNotification = @"com.hicknhack.macpass.MPDocumentSearchServiceDidClearSearchNotification"; +NSString *const MPDocumentSearchServiceDidExitSearchNotification = @"com.hicknhack.macpass.MPDocumentSearchServiceDidExitSearchNotification"; + @implementation MPDocumentSearchService static MPDocumentSearchService *_kMPSearchServiceInstance; @@ -33,6 +37,30 @@ static MPDocumentSearchService *_kMPSearchServiceInstance; return self; } +#pragma mark Actions +- (void)updateSearch:(id)sender { + if(sender != self.searchField) { + return; // Wrong sender + } + self.searchString = [self.searchField stringValue]; + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentSearchServiceDidChangeSearchNotification object:self]; +} + +- (void)clearSearch:(id)sender { + if(sender != self.searchField) { + return; // Wrong sender + } + [self.searchField setStringValue:@""]; + self.searchString = nil; + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentSearchServiceDidClearSearchNotification object:self]; +} + +- (void)exitSearch:(id)sender { + [self.searchField setStringValue:@""]; + self.searchString = nil; + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentSearchServiceDidExitSearchNotification object:self]; +} + - (NSArray *)entriesInDocument:(MPDocument *)document matching:(NSString *)string usingSearchMode:(MPEntrySearchFlags)mode { /* Filter double passwords */ if(MPTestFlagInOptions(MPEntrySearchDoublePasswords, mode)) { diff --git a/MacPass/MPToolbarDelegate.h b/MacPass/MPToolbarDelegate.h index c68ade84..76433117 100644 --- a/MacPass/MPToolbarDelegate.h +++ b/MacPass/MPToolbarDelegate.h @@ -26,6 +26,4 @@ @interface MPToolbarDelegate : NSObject -@property (weak, readonly) NSSearchField *searchField; - @end diff --git a/MacPass/MPToolbarDelegate.m b/MacPass/MPToolbarDelegate.m index 2d1ad315..8c7be1a5 100644 --- a/MacPass/MPToolbarDelegate.m +++ b/MacPass/MPToolbarDelegate.m @@ -32,6 +32,7 @@ #import "MPIconHelper.h" #import "MPDocumentWindowController.h" +#import "MPDocumentSearchService.h" NSString *const MPToolbarItemLock = @"TOOLBAR_LOCK"; NSString *const MPToolbarItemAddGroup = @"TOOLBAR_ADD_GROUP"; @@ -137,7 +138,6 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH"; NSSearchFieldCell *cell = [searchField cell]; [[cell cancelButtonCell] setAction:@selector(cancelSearch:)]; [[cell cancelButtonCell] setTarget:nil]; - self.searchField = searchField; [item setView:searchField]; } else {