diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index c97c8244..e4a3531c 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 4C0728BD17B5B7F7005A7DD9 /* MPPasswordEditWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0728BC17B5B7F7005A7DD9 /* MPPasswordEditWindowController.m */; }; 4C0728BF17B68ED0005A7DD9 /* SavePanelAccessoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0728BE17B68ED0005A7DD9 /* SavePanelAccessoryView.xib */; }; 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 */; }; 4C0B038D18E36DA400B9F9C9 /* FixAutotypeWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0B038B18E36DA400B9F9C9 /* FixAutotypeWindow.xib */; }; 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 = ""; }; 4C08C3AD17B3022400BBBC95 /* KPKLegacyHeaderWriter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKLegacyHeaderWriter.m; sourceTree = ""; }; 4C08C3AF17B3036500BBBC95 /* KPKLegacyFormat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = KPKLegacyFormat.h; path = Format/KPKLegacyFormat.h; sourceTree = ""; }; + 4C0AF62D195C1F2B009E658D /* MPEntrySearchContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntrySearchContext.h; sourceTree = ""; }; + 4C0AF62E195C1F2B009E658D /* MPEntrySearchContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntrySearchContext.m; sourceTree = ""; }; 4C0B038918E36DA400B9F9C9 /* MPFixAutotypeWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPFixAutotypeWindowController.h; sourceTree = ""; }; 4C0B038A18E36DA400B9F9C9 /* MPFixAutotypeWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPFixAutotypeWindowController.m; sourceTree = ""; }; 4C0B038B18E36DA400B9F9C9 /* FixAutotypeWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FixAutotypeWindow.xib; sourceTree = ""; }; @@ -1366,6 +1369,8 @@ 4C94A0711938DDC20040ABAB /* MPDocument+EditingSession.m */, 4C94A06D1938DC8C0040ABAB /* MPEditSession.h */, 4C94A06E1938DC8C0040ABAB /* MPEditSession.m */, + 4C0AF62D195C1F2B009E658D /* MPEntrySearchContext.h */, + 4C0AF62E195C1F2B009E658D /* MPEntrySearchContext.m */, ); name = Model; sourceTree = ""; @@ -2304,6 +2309,7 @@ 4C8EB8C118D399FD00438B08 /* KPKTag.m in Sources */, 4C94A06F1938DC8C0040ABAB /* MPEditSession.m in Sources */, 4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */, + 4C0AF62F195C1F2B009E658D /* MPEntrySearchContext.m in Sources */, 4C888C9316EB6F5E003D34A1 /* MPToolbarItem.m in Sources */, 4C888C9716EB754B003D34A1 /* MPActionHelper.m in Sources */, 4C811C8316ECD06E00C4BAC6 /* MPKeyfilePathControlDelegate.m in Sources */, diff --git a/MacPass/MPContextBarViewController.m b/MacPass/MPContextBarViewController.m index fe08badd..75538098 100644 --- a/MacPass/MPContextBarViewController.m +++ b/MacPass/MPContextBarViewController.m @@ -7,13 +7,15 @@ // #import "MPContextBarViewController.h" -#import "HNHGradientView.h" #import "KPKEntry.h" + #import "MPDocument+HistoryBrowsing.h" #import "MPDocument+Search.h" +#import "MPFlagsHelper.h" +#import "MPEntrySearchContext.h" #import "NSButton+HNHTextColor.h" -#import "MPFlagsHelper.h" +#import "HNHGradientView.h" #import "HNHCommon.h" NSUInteger const MPContextBarViewControllerActiveFilterMenuItemTag = 1000; @@ -122,12 +124,13 @@ typedef NS_ENUM(NSUInteger, MPContextTab) { - (void)_updateFilterButtons { MPDocument *document = [[self windowController] document]; - [self.duplicatePasswordsButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchDoublePasswords, document.activeFlags))]; - [self.notesButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchNotes, document.activeFlags))]; - [self.passwordButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchPasswords, document.activeFlags))]; - [self.titleButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchTitles, document.activeFlags))]; - [self.urlButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchUrls, document.activeFlags))]; - [self.usernameButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchUsernames, document.activeFlags))]; + MPEntrySearchFlags currentFlags = document.searchContext.searchFlags; + [self.duplicatePasswordsButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchDoublePasswords, currentFlags))]; + [self.notesButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchNotes, currentFlags))]; + [self.passwordButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchPasswords, currentFlags))]; + [self.titleButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchTitles, currentFlags))]; + [self.urlButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchUrls, currentFlags))]; + [self.usernameButton setState:HNHStateForBool(MPTestFlagInOptions(MPEntrySearchUsernames, currentFlags))]; } @end diff --git a/MacPass/MPDocument+Search.h b/MacPass/MPDocument+Search.h index c5a76cf1..f290c4f7 100644 --- a/MacPass/MPDocument+Search.h +++ b/MacPass/MPDocument+Search.h @@ -8,6 +8,8 @@ #import "MPDocument.h" +@class MPEntrySearchContext; + FOUNDATION_EXTERN NSString *const MPDocumentDidEnterSearchNotification; FOUNDATION_EXTERN NSString *const MPDocumentDidChangeSearchFlags; FOUNDATION_EXTERN NSString *const MPDocumentDidExitSearchNotification; @@ -30,4 +32,6 @@ FOUNDATION_EXTERN NSString *const kMPDocumentSearchResultsKey; /* called by the filter toggle buttons */ - (IBAction)toggleSearchFlags:(id)sender; +- (NSArray *)entriesMatchingSearch:(MPEntrySearchContext *)search; + @end diff --git a/MacPass/MPDocument+Search.m b/MacPass/MPDocument+Search.m index cb9460ee..078520fc 100644 --- a/MacPass/MPDocument+Search.m +++ b/MacPass/MPDocument+Search.m @@ -30,13 +30,17 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul - (void)performFindPanelAction:(id)sender { self.hasSearch = YES; + /* the search context is loaded via defaults */ + self.searchContext = [[MPEntrySearchContext alloc] init]; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidEnterSearchNotification object:self]; [self updateSearch:self]; } - (void)updateSearch:(id)sender { 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) { [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidEnterSearchNotification object:self]; } @@ -53,8 +57,10 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul } - (void)exitSearch:(id)sender { - self.searchString = nil; + self.searchContext = nil; + /*self.searchString = nil; self.hasSearch = NO; + */ [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidExitSearchNotification object:self]; } @@ -97,6 +103,10 @@ NSString *const kMPDocumentSearchResultsKey = @"kMPDocumentSearchResul } } +- (NSArray *)entriesMatchingSearch:(MPEntrySearchContext *)search { + return nil; +} + #pragma mark Search - (NSArray *)_findEntriesMatchingCurrentSearch { /* Filter double passwords */ diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index ad256add..443d9a7a 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -22,6 +22,7 @@ #import #import "KPKVersion.h" +#import "MPEntrySearchContext.h" /** * Posted when a new group was added to the document. @@ -58,24 +59,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; @class KPKNode; @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 @property (nonatomic, readonly, assign) BOOL encrypted; @@ -102,9 +85,8 @@ typedef NS_OPTIONS(NSUInteger, MPEntrySearchFlags) { /* Search - see MPDocument+Search for further details */ -@property (nonatomic, assign) MPEntrySearchFlags activeFlags; -@property (nonatomic, copy) NSString *searchString; -@property (nonatomic, assign) BOOL hasSearch; +@property (nonatomic, readonly, assign) BOOL hasSearch; +@property (nonatomic, copy) MPEntrySearchContext *searchContext; @property (nonatomic, strong) NSArray *searchResult; /* diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index fdd496a5..51843699 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -123,9 +123,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey _encryptedData = nil; _didLockFile = NO; _readOnly = NO; - _activeFlags = MPEntrySearchTitles; - _hasSearch = NO; - _unlockCount = 0; self.tree = [KPKTree templateTree]; self.tree.metaData.rounds = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordRounds]; } diff --git a/MacPass/MPEntrySearchContext.h b/MacPass/MPEntrySearchContext.h new file mode 100644 index 00000000..8f1c7ef2 --- /dev/null +++ b/MacPass/MPEntrySearchContext.h @@ -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 + +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 + ++ (instancetype)defaultContext; +- (instancetype)initWithString:(NSString *)searchString flags:(MPEntrySearchFlags)flags; + +@property (readonly, assign) NSInteger searchFlags; +@property (readonly, copy) NSString *searchString; + +@end diff --git a/MacPass/MPEntrySearchContext.m b/MacPass/MPEntrySearchContext.m new file mode 100644 index 00000000..19fabc54 --- /dev/null +++ b/MacPass/MPEntrySearchContext.m @@ -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 diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index a87014c9..ffb0acd8 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -51,7 +51,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyEnableGlobalAutotype; // APPKIT_EXTERN NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey; // The stored Data for the useder defined global autotype key /* Search */ -APPKIT_EXTERN NSString *const kMPSettingsKeyEntrySearchFilterMode; +APPKIT_EXTERN NSString *const kMPSettingsKeyEntrySearchFilterContext; /* Quicklook */ APPKIT_EXTERN NSString *const kMPSettingsKeyEnableQuicklookPreview; diff --git a/MacPass/MPSettingsHelper.m b/MacPass/MPSettingsHelper.m index 0c54315b..3e6240ed 100644 --- a/MacPass/MPSettingsHelper.m +++ b/MacPass/MPSettingsHelper.m @@ -37,7 +37,7 @@ NSString *const kMPSettingsKeySendCommandForControlKey = @"SendCo NSString *const kMPSettingsKeyEnableGlobalAutotype = @"EnableGlobalAutotype"; NSString *const kMPSettingsKeyGlobalAutotypeKeyDataKey = @"GlobalAutotypeKeyDataKey"; -NSString *const kMPSettingsKeyEntrySearchFilterMode = @"EntrySearchFilterMode"; +NSString *const kMPSettingsKeyEntrySearchFilterContext = @"EntrySearchFilterContext"; NSString *const kMPSettingsKeyEnableQuicklookPreview = @"EnableQuicklookPreview"; @@ -49,6 +49,7 @@ NSString *const kMPSettingsKeyPasswordCharacterFlags = @"Passwo NSString *const kMPSettingsKeyPasswordUseCustomString = @"PasswordUseCustomString"; NSString *const kMPSettingsKeyPasswordCustomString = @"PasswordCustomString"; +/* Depricated */ NSString *const kMPSettingsKeyDoubleClickURLAction = @"DoubleClickURLAction"; NSString *const kMPSettingsKeyDoubleClickTitleAction = @"DoubleClickTitleAction";