From 6d3a021cb629d1b874754cffb2c3eacf5599e836 Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 30 Sep 2015 18:55:01 +0200 Subject: [PATCH] Using new KeePassKit API for Tags Signed-off-by: michael starke --- MacPass.xcodeproj/project.pbxproj | 6 ++++++ MacPass/MPDocument+Autotype.m | 3 +-- MacPass/MPTagsTokenFieldDelegate.h | 13 +++++++++++++ MacPass/MPTagsTokenFieldDelegate.m | 30 ++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 MacPass/MPTagsTokenFieldDelegate.h create mode 100644 MacPass/MPTagsTokenFieldDelegate.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 8441bf65..9b177e29 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -311,6 +311,7 @@ 4CE39ABF16ECE34A000FE29D /* MPIconSelectViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE39ABE16ECE34A000FE29D /* MPIconSelectViewController.m */; }; 4CE39AC416ECE4F7000FE29D /* MPPopupImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE39AC316ECE4F7000FE29D /* MPPopupImageView.m */; }; 4CE3E62617AB0D2D00D9E4B4 /* MPAttachmentTableDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE3E62517AB0D2D00D9E4B4 /* MPAttachmentTableDataSource.m */; }; + 4CE501341BBC47F500FB819D /* MPTagsTokenFieldDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE501331BBC47F500FB819D /* MPTagsTokenFieldDelegate.m */; settings = {ASSET_TAGS = (); }; }; 4CE5B54B173AFBA700207B39 /* MPDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE5B549173AFBA700207B39 /* MPDocument.m */; }; 4CE76DAD17B3AD010043B82B /* KPKHashedDataTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE76DAC17B3AD010043B82B /* KPKHashedDataTest.m */; }; 4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8246E16E2E93400573141 /* MPOverlayWindowController.m */; }; @@ -919,6 +920,8 @@ 4CE3E62517AB0D2D00D9E4B4 /* MPAttachmentTableDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAttachmentTableDataSource.m; sourceTree = ""; }; 4CE5012C1BBC13C100FB819D /* KPKWindowAssociation+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KPKWindowAssociation+Private.h"; sourceTree = ""; }; 4CE5012F1BBC15B600FB819D /* KPKAutotype+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KPKAutotype+Private.h"; sourceTree = ""; }; + 4CE501321BBC47F500FB819D /* MPTagsTokenFieldDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPTagsTokenFieldDelegate.h; sourceTree = ""; }; + 4CE501331BBC47F500FB819D /* MPTagsTokenFieldDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPTagsTokenFieldDelegate.m; sourceTree = ""; }; 4CE5B548173AFBA700207B39 /* MPDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDocument.h; sourceTree = ""; }; 4CE5B549173AFBA700207B39 /* MPDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = MPDocument.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 4CE76DAC17B3AD010043B82B /* KPKHashedDataTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKHashedDataTest.m; sourceTree = ""; }; @@ -1266,6 +1269,8 @@ 4C89B70F19B4B4A300DC0A6A /* MPTreeDelegate.m */, 4CA0F3EB1A3074B50067C0E5 /* MPWindowTitleComboBoxDelegate.h */, 4CA0F3EC1A3074B50067C0E5 /* MPWindowTitleComboBoxDelegate.m */, + 4CE501321BBC47F500FB819D /* MPTagsTokenFieldDelegate.h */, + 4CE501331BBC47F500FB819D /* MPTagsTokenFieldDelegate.m */, ); name = Delegates; sourceTree = ""; @@ -2502,6 +2507,7 @@ 4C32B0E71A1D4436007E12F1 /* KPKFormat+MPUTIDetection.m in Sources */, 4C5CD35A17D15DBD000B7F38 /* NSString+Hexdata.m in Sources */, 4C5CD36117D15DCA000B7F38 /* KPKArc4RandomStream.m in Sources */, + 4CE501341BBC47F500FB819D /* MPTagsTokenFieldDelegate.m in Sources */, 4C5CD36217D15DCA000B7F38 /* KPKRandomStream.m in Sources */, 4C31FEB31B57CDDB008E7CE3 /* MPPluginManager.m in Sources */, 4C5CD36317D15DCA000B7F38 /* KPKSalsa20RandomStream.m in Sources */, diff --git a/MacPass/MPDocument+Autotype.m b/MacPass/MPDocument+Autotype.m index 4549008d..059ad049 100644 --- a/MacPass/MPDocument+Autotype.m +++ b/MacPass/MPDocument+Autotype.m @@ -91,8 +91,7 @@ } /* test for tags */ if(matchTags && !foundMatch) { - NSArray *tags = [entry.tags componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@".:;"]]; - for(NSString *tag in tags) { + for(NSString *tag in entry.tags) { foundMatch = ([windowTitle rangeOfString:tag options:NSCaseInsensitiveSearch].length != 0); if(foundMatch) { break; diff --git a/MacPass/MPTagsTokenFieldDelegate.h b/MacPass/MPTagsTokenFieldDelegate.h new file mode 100644 index 00000000..b4d86396 --- /dev/null +++ b/MacPass/MPTagsTokenFieldDelegate.h @@ -0,0 +1,13 @@ +// +// MPTagsTokenFieldDelegate.h +// MacPass +// +// Created by Michael Starke on 30/09/15. +// Copyright © 2015 HicknHack Software GmbH. All rights reserved. +// + +#import + +@interface MPTagsTokenFieldDelegate : NSObject + +@end diff --git a/MacPass/MPTagsTokenFieldDelegate.m b/MacPass/MPTagsTokenFieldDelegate.m new file mode 100644 index 00000000..5d311575 --- /dev/null +++ b/MacPass/MPTagsTokenFieldDelegate.m @@ -0,0 +1,30 @@ +// +// MPTagsTokenFieldDelegate.m +// MacPass +// +// Created by Michael Starke on 30/09/15. +// Copyright © 2015 HicknHack Software GmbH. All rights reserved. +// + +#import "MPTagsTokenFieldDelegate.h" + +@implementation MPTagsTokenFieldDelegate + +// Each element in the array should be an NSString or an array of NSStrings. +// substring is the partial string that is being completed. tokenIndex is the index of the token being completed. +// selectedIndex allows you to return by reference an index specifying which of the completions should be selected initially. +// The default behavior is not to have any completions. +//- (nullable NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(nullable NSInteger *)selectedIndex; + +// return an array of represented objects you want to add. +// If you want to reject the add, return an empty array. +// returning nil will cause an error. +//- (NSArray *)tokenField:(NSTokenField *)tokenField shouldAddObjects:(NSArray *)tokens atIndex:(NSUInteger)index; + +// If you return nil or don't implement these delegate methods, we will assume +// editing string = display string = represented object +//- (nullable NSString *)tokenField:(NSTokenField *)tokenField displayStringForRepresentedObject:(id)representedObject; +//- (nullable NSString *)tokenField:(NSTokenField *)tokenField editingStringForRepresentedObject:(id)representedObject; +//- (id)tokenField:(NSTokenField *)tokenField representedObjectForEditingString: (NSString *)editingString; + +@end