diff --git a/KeePassKit b/KeePassKit index 737a69a2..7a4de622 160000 --- a/KeePassKit +++ b/KeePassKit @@ -1 +1 @@ -Subproject commit 737a69a26ef1c64de063313c76b3812d4ae08f9a +Subproject commit 7a4de6220e0ce98a458391610a6835043f4785f6 diff --git a/MacPass/AutotypeCandidateSelectionWindow.xib b/MacPass/AutotypeCandidateSelectionWindow.xib index dd0427a1..a680b3e1 100644 --- a/MacPass/AutotypeCandidateSelectionWindow.xib +++ b/MacPass/AutotypeCandidateSelectionWindow.xib @@ -9,12 +9,13 @@ + - - + + @@ -43,12 +44,12 @@ Gw - + - + diff --git a/MacPass/MPAutotypeCommand.m b/MacPass/MPAutotypeCommand.m index 6b3604f9..9f5cca46 100644 --- a/MacPass/MPAutotypeCommand.m +++ b/MacPass/MPAutotypeCommand.m @@ -7,17 +7,32 @@ // #import "MPAutotypeCommand.h" -#import "NSString+Commands.h" +#import "MPAutotypeContext.h" #import "MPKeyMapper.h" +#import "NSString+Commands.h" + #import @implementation MPAutotypeCommand + (NSArray *)commandsForContext:(MPAutotypeContext *)context { - NSError *error; - NSRegularExpression *regularExpression = [[NSRegularExpression alloc] initWithPattern:@"" options:0 error:&error]; + if([context isValid]) { + return nil; + } + BOOL outsideCommand = YES; + NSInteger currentIndex; + while(YES) { + if(outsideCommand) { + NSRange openingBracketRange = [context.normalizedCommand rangeOfString:@"{"]; + if(openingBracketRange.location != NSNotFound && openingBracketRange.length == 1) { + } + } + else { + } + + } return nil; } diff --git a/MacPass/MPAutotypeContext.h b/MacPass/MPAutotypeContext.h index 2c61ae74..5844227f 100644 --- a/MacPass/MPAutotypeContext.h +++ b/MacPass/MPAutotypeContext.h @@ -22,9 +22,10 @@ */ @property (nonatomic, strong) KPKEntry *entry; /** - * The command in normalized (see NSString+Commands) + * The Autotype command as it's supplied by the entry */ @property (nonatomic, copy) NSString *command; +@property (nonatomic, copy) NSString *normalizedCommand; /** * Designated initializer @@ -37,5 +38,11 @@ - (instancetype)initWithEntry:(KPKEntry *)entry andSequence:(NSString *)sequence; - (instancetype)initWithDefaultSequenceForEntry:(KPKEntry *)entry; - (instancetype)initWithWindowAssociation:(KPKWindowAssociation *)association; +/** + * Returns YES if the given sequence is valid (currentyl only bracke missmatch is regarded as invalid + * + * @return YES if valid, NO otherwise + */ +- (BOOL)isValid; @end diff --git a/MacPass/MPAutotypeContext.m b/MacPass/MPAutotypeContext.m index 98ee3fed..63864206 100644 --- a/MacPass/MPAutotypeContext.m +++ b/MacPass/MPAutotypeContext.m @@ -28,8 +28,9 @@ - (instancetype)initWithEntry:(KPKEntry *)entry andSequence:(NSString *)sequence { self = [super init]; if(self) { - _command = [[sequence normalizedAutotypeSequence] copy]; + _command = [sequence copy]; _entry = entry; + _normalizedCommand = [[sequence normalizedAutotypeSequence] copy]; } return self; } @@ -39,4 +40,8 @@ return copy; } +- (BOOL)isValid { + return (self.normalizedCommand != nil); +} + @end diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index 01bd952d..bfab8e3f 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -7,15 +7,19 @@ // #import "MPAutotypeDaemon.h" -#import "DDHotKeyCenter.h" -#import "MPPasteBoardController.h" #import "MPDocument.h" + #import "MPDocument+Autotype.h" #import "MPAutotypeCommand.h" +#import "MPAutotypeContext.h" + +#import "MPPasteBoardController.h" #import "MPSettingsHelper.h" + #import "KPKEntry.h" +#import "DDHotKeyCenter.h" #import NSString *const kMPWindowTitleKey = @"windowTitle"; @@ -33,11 +37,18 @@ NSString *const kMPApplciationNameKey = @"applicationName"; self = [super init]; if (self) { _enabled = NO; - [[NSUserDefaults standardUserDefaults] bind:kMPSettingsKeyEnableGlobalAutotype toObject:self withKeyPath:@"enabled" options:nil]; + [self bind:@"enabled" + toObject:[NSUserDefaultsController sharedUserDefaultsController] + withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableGlobalAutotype] + options:nil]; } return self; } +- (void)dealloc { + [self unbind:@"enabled"]; +} + #pragma mark Properties - (void)setEnabled:(BOOL)enabled { if(_enabled != enabled) { @@ -53,6 +64,8 @@ NSString *const kMPApplciationNameKey = @"applicationName"; - (void)executeAutotypeWithSelectedMatch:(id)sender { NSMenuItem *item = [self.matchSelectionButton selectedItem]; MPAutotypeContext *context = [item representedObject]; + [self.matchSelectionWindow orderOut:self]; + } - (void)_didPressHotKey { @@ -86,7 +99,7 @@ NSString *const kMPApplciationNameKey = @"applicationName"; return; // No Entries found. } if(candiates > 1) { - [self _presentSelectionWindow]; + [self _presentSelectionWindow:autotypeCandidates]; return; // Nothing to do, we get called back by the window } /* Just in case it's not there anymore, order the app for the window we want to autotype back to the foreground! */ @@ -138,12 +151,24 @@ NSString *const kMPApplciationNameKey = @"applicationName"; return nil; } -- (void)_presentSelectionWindow { +- (void)_presentSelectionWindow:(NSArray *)candidates { if(!self.matchSelectionWindow) { [[NSBundle mainBundle] loadNibNamed:@"AutotypeCandidateSelectionWindow" owner:self topLevelObjects:nil]; [self.performAutotypeButton setTarget:self]; [self.performAutotypeButton setAction:@selector(executeAutotypeWithSelectedMatch:)]; + [self.matchSelectionWindow setLevel:NSFloatingWindowLevel]; } + NSMenu *associationMenu = [[NSMenu alloc] init]; + [associationMenu addItemWithTitle:NSLocalizedString(@"SELECT_AUTOTYPE_CANDIDATE", "") action:NULL keyEquivalent:@""]; + [associationMenu addItem:[NSMenuItem separatorItem]]; + [associationMenu setAutoenablesItems:NO]; + for(MPAutotypeContext *context in candidates) { + NSString *title = [[NSString alloc] initWithFormat:@"%@: %@", context.entry.title, context.command]; + NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:title action:0 keyEquivalent:@""]; + [item setRepresentedObject:context]; + [associationMenu addItem:item]; + } + [self.matchSelectionButton setMenu:associationMenu]; [self.matchSelectionWindow makeKeyAndOrderFront:self]; /* Setup Items in Popup */ } diff --git a/MacPass/MPDocument+Autotype.m b/MacPass/MPDocument+Autotype.m index f73079d3..7c4d6c70 100644 --- a/MacPass/MPDocument+Autotype.m +++ b/MacPass/MPDocument+Autotype.m @@ -48,7 +48,7 @@ KPKWindowAssociation *association = [entry.autotype windowAssociationMatchingWindowTitle:windowTitle]; context = [[MPAutotypeContext alloc] initWithWindowAssociation:association]; } - if(context) { + if([context isValid]) { [contexts addObject:context]; } } diff --git a/MacPass/en.lproj/Localizable.strings b/MacPass/en.lproj/Localizable.strings index b57c9013..04334531 100644 Binary files a/MacPass/en.lproj/Localizable.strings and b/MacPass/en.lproj/Localizable.strings differ