Extracted search into own class

This commit is contained in:
michael starke
2014-08-27 12:13:24 +02:00
parent 554da9dfc7
commit 0286ed4e5c
10 changed files with 135 additions and 36 deletions

View File

@@ -16,6 +16,7 @@
4C0728BD17B5B7F7005A7DD9 /* MPPasswordEditWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0728BC17B5B7F7005A7DD9 /* MPPasswordEditWindowController.m */; }; 4C0728BD17B5B7F7005A7DD9 /* MPPasswordEditWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0728BC17B5B7F7005A7DD9 /* MPPasswordEditWindowController.m */; };
4C0728BF17B68ED0005A7DD9 /* SavePanelAccessoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0728BE17B68ED0005A7DD9 /* SavePanelAccessoryView.xib */; }; 4C0728BF17B68ED0005A7DD9 /* SavePanelAccessoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0728BE17B68ED0005A7DD9 /* SavePanelAccessoryView.xib */; };
4C08C3AE17B3022400BBBC95 /* KPKLegacyHeaderWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C08C3AD17B3022400BBBC95 /* KPKLegacyHeaderWriter.m */; }; 4C08C3AE17B3022400BBBC95 /* KPKLegacyHeaderWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C08C3AD17B3022400BBBC95 /* KPKLegacyHeaderWriter.m */; };
4C0AF62F195C1F2B009E658D /* MPEntrySearchContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0AF62E195C1F2B009E658D /* MPEntrySearchContext.m */; };
4C0B038C18E36DA400B9F9C9 /* MPFixAutotypeWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0B038A18E36DA400B9F9C9 /* MPFixAutotypeWindowController.m */; }; 4C0B038C18E36DA400B9F9C9 /* MPFixAutotypeWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0B038A18E36DA400B9F9C9 /* MPFixAutotypeWindowController.m */; };
4C0B038D18E36DA400B9F9C9 /* FixAutotypeWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0B038B18E36DA400B9F9C9 /* FixAutotypeWindow.xib */; }; 4C0B038D18E36DA400B9F9C9 /* FixAutotypeWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0B038B18E36DA400B9F9C9 /* FixAutotypeWindow.xib */; };
4C0C59F118B17F10009C7B76 /* DDHotKeyUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0C59EF18B17F10009C7B76 /* DDHotKeyUtilities.m */; }; 4C0C59F118B17F10009C7B76 /* DDHotKeyUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0C59EF18B17F10009C7B76 /* DDHotKeyUtilities.m */; };
@@ -384,6 +385,8 @@
4C08C3AC17B3022400BBBC95 /* KPKLegacyHeaderWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KPKLegacyHeaderWriter.h; sourceTree = "<group>"; }; 4C08C3AC17B3022400BBBC95 /* KPKLegacyHeaderWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KPKLegacyHeaderWriter.h; sourceTree = "<group>"; };
4C08C3AD17B3022400BBBC95 /* KPKLegacyHeaderWriter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKLegacyHeaderWriter.m; sourceTree = "<group>"; }; 4C08C3AD17B3022400BBBC95 /* KPKLegacyHeaderWriter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKLegacyHeaderWriter.m; sourceTree = "<group>"; };
4C08C3AF17B3036500BBBC95 /* KPKLegacyFormat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = KPKLegacyFormat.h; path = Format/KPKLegacyFormat.h; sourceTree = "<group>"; }; 4C08C3AF17B3036500BBBC95 /* KPKLegacyFormat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = KPKLegacyFormat.h; path = Format/KPKLegacyFormat.h; sourceTree = "<group>"; };
4C0AF62D195C1F2B009E658D /* MPEntrySearchContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntrySearchContext.h; sourceTree = "<group>"; };
4C0AF62E195C1F2B009E658D /* MPEntrySearchContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntrySearchContext.m; sourceTree = "<group>"; };
4C0B038918E36DA400B9F9C9 /* MPFixAutotypeWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPFixAutotypeWindowController.h; sourceTree = "<group>"; }; 4C0B038918E36DA400B9F9C9 /* MPFixAutotypeWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPFixAutotypeWindowController.h; sourceTree = "<group>"; };
4C0B038A18E36DA400B9F9C9 /* MPFixAutotypeWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPFixAutotypeWindowController.m; sourceTree = "<group>"; }; 4C0B038A18E36DA400B9F9C9 /* MPFixAutotypeWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPFixAutotypeWindowController.m; sourceTree = "<group>"; };
4C0B038B18E36DA400B9F9C9 /* FixAutotypeWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FixAutotypeWindow.xib; sourceTree = "<group>"; }; 4C0B038B18E36DA400B9F9C9 /* FixAutotypeWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FixAutotypeWindow.xib; sourceTree = "<group>"; };
@@ -1366,6 +1369,8 @@
4C94A0711938DDC20040ABAB /* MPDocument+EditingSession.m */, 4C94A0711938DDC20040ABAB /* MPDocument+EditingSession.m */,
4C94A06D1938DC8C0040ABAB /* MPEditSession.h */, 4C94A06D1938DC8C0040ABAB /* MPEditSession.h */,
4C94A06E1938DC8C0040ABAB /* MPEditSession.m */, 4C94A06E1938DC8C0040ABAB /* MPEditSession.m */,
4C0AF62D195C1F2B009E658D /* MPEntrySearchContext.h */,
4C0AF62E195C1F2B009E658D /* MPEntrySearchContext.m */,
); );
name = Model; name = Model;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -2304,6 +2309,7 @@
4C8EB8C118D399FD00438B08 /* KPKTag.m in Sources */, 4C8EB8C118D399FD00438B08 /* KPKTag.m in Sources */,
4C94A06F1938DC8C0040ABAB /* MPEditSession.m in Sources */, 4C94A06F1938DC8C0040ABAB /* MPEditSession.m in Sources */,
4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */, 4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */,
4C0AF62F195C1F2B009E658D /* MPEntrySearchContext.m in Sources */,
4C888C9316EB6F5E003D34A1 /* MPToolbarItem.m in Sources */, 4C888C9316EB6F5E003D34A1 /* MPToolbarItem.m in Sources */,
4C888C9716EB754B003D34A1 /* MPActionHelper.m in Sources */, 4C888C9716EB754B003D34A1 /* MPActionHelper.m in Sources */,
4C811C8316ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.m in Sources */, 4C811C8316ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.m in Sources */,

View File

@@ -7,13 +7,15 @@
// //
#import "MPContextBarViewController.h" #import "MPContextBarViewController.h"
#import "HNHGradientView.h"
#import "KPKEntry.h" #import "KPKEntry.h"
#import "MPDocument+HistoryBrowsing.h" #import "MPDocument+HistoryBrowsing.h"
#import "MPDocument+Search.h" #import "MPDocument+Search.h"
#import "MPFlagsHelper.h"
#import "MPEntrySearchContext.h"
#import "NSButton+HNHTextColor.h" #import "NSButton+HNHTextColor.h"
#import "MPFlagsHelper.h" #import "HNHGradientView.h"
#import "HNHCommon.h" #import "HNHCommon.h"
NSUInteger const MPContextBarViewControllerActiveFilterMenuItemTag = 1000; NSUInteger const MPContextBarViewControllerActiveFilterMenuItemTag = 1000;
@@ -122,12 +124,13 @@ typedef NS_ENUM(NSUInteger, MPContextTab) {
- (void)_updateFilterButtons { - (void)_updateFilterButtons {
MPDocument *document = [[self windowController] document]; MPDocument *document = [[self windowController] document];
[self.duplicatePasswordsButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchDoublePasswords, document.activeFlags))]; MPEntrySearchFlags currentFlags = document.searchContext.searchFlags;
[self.notesButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchNotes, document.activeFlags))]; [self.duplicatePasswordsButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchDoublePasswords, currentFlags))];
[self.passwordButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchPasswords, document.activeFlags))]; [self.notesButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchNotes, currentFlags))];
[self.titleButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchTitles, document.activeFlags))]; [self.passwordButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchPasswords, currentFlags))];
[self.urlButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchUrls, document.activeFlags))]; [self.titleButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchTitles, currentFlags))];
[self.usernameButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchUsernames, document.activeFlags))]; [self.urlButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchUrls, currentFlags))];
[self.usernameButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchUsernames, currentFlags))];
} }
@end @end

View File

@@ -8,6 +8,8 @@
#import "MPDocument.h" #import "MPDocument.h"
@class MPEntrySearchContext;
FOUNDATION_EXTERN NSString *const MPDocumentDidEnterSearchNotification; FOUNDATION_EXTERN NSString *const MPDocumentDidEnterSearchNotification;
FOUNDATION_EXTERN NSString *const MPDocumentDidChangeSearchFlags; FOUNDATION_EXTERN NSString *const MPDocumentDidChangeSearchFlags;
FOUNDATION_EXTERN NSString *const MPDocumentDidExitSearchNotification; FOUNDATION_EXTERN NSString *const MPDocumentDidExitSearchNotification;
@@ -30,4 +32,6 @@ FOUNDATION_EXTERN NSString *const kMPDocumentSearchResultsKey;
/* called by the filter toggle buttons */ /* called by the filter toggle buttons */
- (IBAction)toggleSearchFlags:(id)sender; - (IBAction)toggleSearchFlags:(id)sender;
- (NSArray *)entriesMatchingSearch:(MPEntrySearchContext *)search;
@end @end

View File

@@ -30,13 +30,17 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul
- (void)performFindPanelAction:(id)sender { - (void)performFindPanelAction:(id)sender {
self.hasSearch = YES; self.hasSearch = YES;
/* the search context is loaded via defaults */
self.searchContext = [[MPEntrySearchContext alloc] init];
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidEnterSearchNotification object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidEnterSearchNotification object:self];
[self updateSearch:self]; [self updateSearch:self];
} }
- (void)updateSearch:(id)sender { - (void)updateSearch:(id)sender {
MPDocumentWindowController *windowController = [self windowControllers][0]; MPDocumentWindowController *windowController = [self windowControllers][0];
self.searchString = [windowController.searchField stringValue]; NSString *searchString = [windowController.searchField stringValue];
/* Update the search string */
self.searchContext = [[MPEntrySearchContext alloc] initWithString:searchString flags:self.searchContext.searchFlags];
if(NO == self.hasSearch) { if(NO == self.hasSearch) {
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidEnterSearchNotification object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidEnterSearchNotification object:self];
} }
@@ -53,8 +57,10 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul
} }
- (void)exitSearch:(id)sender { - (void)exitSearch:(id)sender {
self.searchString = nil; self.searchContext = nil;
/*self.searchString = nil;
self.hasSearch = NO; self.hasSearch = NO;
*/
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidExitSearchNotification object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidExitSearchNotification object:self];
} }
@@ -97,6 +103,10 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul
} }
} }
- (NSArray *)entriesMatchingSearch:(MPEntrySearchContext *)search {
return nil;
}
#pragma mark Search #pragma mark Search
- (NSArray *)_findEntriesMatchingCurrentSearch { - (NSArray *)_findEntriesMatchingCurrentSearch {
/* Filter double passwords */ /* Filter double passwords */

View File

@@ -22,6 +22,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "KPKVersion.h" #import "KPKVersion.h"
#import "MPEntrySearchContext.h"
/** /**
* Posted when a new group was added to the document. * Posted when a new group was added to the document.
@@ -58,24 +59,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@class KPKNode; @class KPKNode;
@class MPEditSession; @class MPEditSession;
typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
MPEntrySearchNone = 0,
MPEntrySearchUrls = (1<<0),
MPEntrySearchUsernames = (1<<1),
MPEntrySearchTitles = (1<<2),
MPEntrySearchPasswords = (1<<3),
MPEntrySearchNotes = (1<<4),
MPEntrySearchAllAttributes = (1<<5),
MPEntrySearchDoublePasswords = (1<<6), // Unused in GUI for now
MPEntrySearchAllFlags = (MPEntrySearchDoublePasswords |
MPEntrySearchNotes |
MPEntrySearchPasswords |
MPEntrySearchTitles |
MPEntrySearchUrls |
MPEntrySearchUsernames |
MPEntrySearchAllAttributes )
};
@interface MPDocument : NSDocument @interface MPDocument : NSDocument
@property (nonatomic, readonly, assign) BOOL encrypted; @property (nonatomic, readonly, assign) BOOL encrypted;
@@ -102,9 +85,8 @@ typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
/* /*
Search - see MPDocument+Search for further details Search - see MPDocument+Search for further details
*/ */
@property (nonatomic, assign) MPEntrySearchFlags activeFlags; @property (nonatomic, readonly, assign) BOOL hasSearch;
@property (nonatomic, copy) NSString *searchString; @property (nonatomic, copy) MPEntrySearchContext *searchContext;
@property (nonatomic, assign) BOOL hasSearch;
@property (nonatomic, strong) NSArray *searchResult; @property (nonatomic, strong) NSArray *searchResult;
/* /*

View File

@@ -123,9 +123,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
_encryptedData = nil; _encryptedData = nil;
_didLockFile = NO; _didLockFile = NO;
_readOnly = NO; _readOnly = NO;
_activeFlags = MPEntrySearchTitles;
_hasSearch = NO;
_unlockCount = 0;
self.tree = [KPKTree templateTree]; self.tree = [KPKTree templateTree];
self.tree.metaData.rounds = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordRounds]; self.tree.metaData.rounds = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordRounds];
} }

View File

@@ -0,0 +1,41 @@
//
// MPEntrySearch.h
// MacPass
//
// Created by Michael Starke on 26.06.14.
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) {
MPEntrySearchNone = 0,
MPEntrySearchUrls = (1<<0),
MPEntrySearchUsernames = (1<<1),
MPEntrySearchTitles = (1<<2),
MPEntrySearchPasswords = (1<<3),
MPEntrySearchNotes = (1<<4),
MPEntrySearchAllAttributes = (1<<5),
MPEntrySearchDoublePasswords = (1<<6), // Unused in GUI for now
MPEntrySearchExpiredEntries = (1<<7), // Unused for now
MPEntrySearchAllFlags = (MPEntrySearchDoublePasswords |
MPEntrySearchExpiredEntries |
MPEntrySearchNotes |
MPEntrySearchPasswords |
MPEntrySearchTitles |
MPEntrySearchUrls |
MPEntrySearchUsernames |
MPEntrySearchAllAttributes )
};
/* Wrap serach criteria to be able to store them */
@interface MPEntrySearchContext : NSObject <NSSecureCoding>
+ (instancetype)defaultContext;
- (instancetype)initWithString:(NSString *)searchString flags:(MPEntrySearchFlags)flags;
@property (readonly, assign) NSInteger searchFlags;
@property (readonly, copy) NSString *searchString;
@end

View File

@@ -0,0 +1,55 @@
//
// MPEntrySearch.m
// MacPass
//
// Created by Michael Starke on 26.06.14.
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
//
#import "MPEntrySearchContext.h"
@interface MPEntrySearchContext ()
@property (assign) NSInteger searchFlags;
@property (copy) NSString *searchString;
@end
@implementation MPEntrySearchContext
+ (BOOL)supportsSecureCoding {
return YES;
}
+ (instancetype)defaultContext {
}
- (instancetype)init {
self = [self initWithString:nil flags:MPEntrySearchNone];
return self;
}
- (instancetype)initWithString:(NSString *)searchString flags:(MPEntrySearchFlags)flags {
self = [super init];
if(self) {
self.searchFlags = flags;
self.searchString = searchString;
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeInteger:self.searchFlags forKey:NSStringFromSelector(@selector(searchFlags))];
[aCoder encodeObject:self.searchString forKey:NSStringFromSelector(@selector(searchString))];
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [self init];
self.searchString = [aDecoder decodeObjectOfClass:[NSString class] forKey:NSStringFromSelector(@selector(searchString))];
self.searchFlags = [aDecoder decodeIntegerForKey:NSStringFromSelector(@selector(searchFlags))];
return self;
}
@end

View File

@@ -51,7 +51,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyEnableGlobalAutotype; //
APPKIT_EXTERN NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey; // The stored Data for the useder defined global autotype key APPKIT_EXTERN NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey; // The stored Data for the useder defined global autotype key
/* Search */ /* Search */
APPKIT_EXTERN NSString *const kMPSettingsKeyEntrySearchFilterMode; APPKIT_EXTERN NSString *const kMPSettingsKeyEntrySearchFilterContext;
/* Quicklook */ /* Quicklook */
APPKIT_EXTERN NSString *const kMPSettingsKeyEnableQuicklookPreview; APPKIT_EXTERN NSString *const kMPSettingsKeyEnableQuicklookPreview;

View File

@@ -37,7 +37,7 @@ NSString *const kMPSettingsKeySendCommandForControlKey = @"SendCo
NSString *const kMPSettingsKeyEnableGlobalAutotype = @"EnableGlobalAutotype"; NSString *const kMPSettingsKeyEnableGlobalAutotype = @"EnableGlobalAutotype";
NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey = @"GlobalAutotypeKeyDataKey"; NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey = @"GlobalAutotypeKeyDataKey";
NSString *const kMPSettingsKeyEntrySearchFilterMode = @"EntrySearchFilterMode"; NSString *const kMPSettingsKeyEntrySearchFilterContext = @"EntrySearchFilterContext";
NSString *const kMPSettingsKeyEnableQuicklookPreview = @"EnableQuicklookPreview"; NSString *const kMPSettingsKeyEnableQuicklookPreview = @"EnableQuicklookPreview";
@@ -49,6 +49,7 @@ NSString *const kMPSettingsKeyPasswordCharacterFlags = @"Passwo
NSString *const kMPSettingsKeyPasswordUseCustomString = @"PasswordUseCustomString"; NSString *const kMPSettingsKeyPasswordUseCustomString = @"PasswordUseCustomString";
NSString *const kMPSettingsKeyPasswordCustomString = @"PasswordCustomString"; NSString *const kMPSettingsKeyPasswordCustomString = @"PasswordCustomString";
/* Depricated */
NSString *const kMPSettingsKeyDoubleClickURLAction = @"DoubleClickURLAction"; NSString *const kMPSettingsKeyDoubleClickURLAction = @"DoubleClickURLAction";
NSString *const kMPSettingsKeyDoubleClickTitleAction = @"DoubleClickTitleAction"; NSString *const kMPSettingsKeyDoubleClickTitleAction = @"DoubleClickTitleAction";