broke commit

This commit is contained in:
michael starke
2014-02-24 23:27:05 +01:00
parent 81dc24d9b2
commit de00a42f02
4 changed files with 35 additions and 5 deletions

View File

@@ -10,8 +10,9 @@
@class MPDocument; @class MPDocument;
FOUNDATION_EXTERN NSString *const MPSearchServiceSearchDidChangeNotification; FOUNDATION_EXTERN NSString *const MPDocumentSearchServiceDidChangeSearchNotification;
FOUNDATION_EXTERN NSString *const MPSearchServiceSearchWasClearedNotification; FOUNDATION_EXTERN NSString *const MPDocumentSearchServiceDidClearSearchNotification;
FOUNDATION_EXTERN NSString *const MPDocumentSearchServiceDidExitSearchNotification;
typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) { typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
MPEntrySearchNone = 0, MPEntrySearchNone = 0,
@@ -27,11 +28,14 @@ typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
@property (nonatomic, assign) MPEntrySearchFlags activeFlags; @property (nonatomic, assign) MPEntrySearchFlags activeFlags;
@property (nonatomic, copy) NSString *searchString; @property (nonatomic, copy) NSString *searchString;
@property (nonatomic, weak) NSSearchField *searchField;
+ (instancetype)sharedService; + (instancetype)sharedService;
- (NSArray *)entriesInDocument:(MPDocument *)document matching:(NSString *)string usingSearchMode:(MPEntrySearchFlags)mode; - (NSArray *)entriesInDocument:(MPDocument *)document matching:(NSString *)string usingSearchMode:(MPEntrySearchFlags)mode;
- (NSArray *)optionsEnabledInMode:(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 */ /* Clears the search string, but doesn't exit searching */
- (IBAction)clearSearch:(id)sender; - (IBAction)clearSearch:(id)sender;
/* exits searching mode */ /* exits searching mode */

View File

@@ -12,6 +12,10 @@
#import "KPKEntry.h" #import "KPKEntry.h"
#import "MPFlagsHelper.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 @implementation MPDocumentSearchService
static MPDocumentSearchService *_kMPSearchServiceInstance; static MPDocumentSearchService *_kMPSearchServiceInstance;
@@ -33,6 +37,30 @@ static MPDocumentSearchService *_kMPSearchServiceInstance;
return self; 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 { - (NSArray *)entriesInDocument:(MPDocument *)document matching:(NSString *)string usingSearchMode:(MPEntrySearchFlags)mode {
/* Filter double passwords */ /* Filter double passwords */
if(MPTestFlagInOptions(MPEntrySearchDoublePasswords, mode)) { if(MPTestFlagInOptions(MPEntrySearchDoublePasswords, mode)) {

View File

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

View File

@@ -32,6 +32,7 @@
#import "MPIconHelper.h" #import "MPIconHelper.h"
#import "MPDocumentWindowController.h" #import "MPDocumentWindowController.h"
#import "MPDocumentSearchService.h"
NSString *const MPToolbarItemLock = @"TOOLBAR_LOCK"; NSString *const MPToolbarItemLock = @"TOOLBAR_LOCK";
NSString *const MPToolbarItemAddGroup = @"TOOLBAR_ADD_GROUP"; NSString *const MPToolbarItemAddGroup = @"TOOLBAR_ADD_GROUP";
@@ -137,7 +138,6 @@ NSString *const MPToolbarItemSearch = @"TOOLBAR_SEARCH";
NSSearchFieldCell *cell = [searchField cell]; NSSearchFieldCell *cell = [searchField cell];
[[cell cancelButtonCell] setAction:@selector(cancelSearch:)]; [[cell cancelButtonCell] setAction:@selector(cancelSearch:)];
[[cell cancelButtonCell] setTarget:nil]; [[cell cancelButtonCell] setTarget:nil];
self.searchField = searchField;
[item setView:searchField]; [item setView:searchField];
} }
else { else {