From aa340305ba7da5e3c015e6a183b8f9ae7d023315 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 15 Dec 2014 14:47:44 +0100 Subject: [PATCH] Fixed issue resutling in singel hotkey combination not being properly processed --- MacPass.xcodeproj/project.pbxproj | 6 ++ MacPass/Base.lproj/IntegrationSettings.xib | 72 ++++++++++++++-------- MacPass/MPAutotypeCommand.m | 18 ++++-- MacPass/MPAutotypeDaemon.m | 9 ++- MacPass/MPIntegrationSettingsController.h | 17 ++++- MacPass/MPIntegrationSettingsController.m | 16 +++-- MacPassTests/KPKTestAutotype.m | 16 +++++ MacPassTests/KPKTextXMLUtilities.m | 6 +- 8 files changed, 118 insertions(+), 42 deletions(-) diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index ec76fdf5..0f939a75 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -225,6 +225,7 @@ 4C96D15417A12E4F00D931FA /* 99_CreatedTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C96D15317A12E4F00D931FA /* 99_CreatedTemplate.pdf */; }; 4C978E0619AE53FE003067DF /* HNHCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C978E0519AE53FE003067DF /* HNHCommon.m */; }; 4C978E0D19AE54AB003067DF /* MPFlagsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C978E0C19AE54AB003067DF /* MPFlagsHelper.m */; }; + 4C9B38CF1A3EFCA100CD21C3 /* NSString+XMLUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C9B38CE1A3EFCA100CD21C3 /* NSString+XMLUtilities.m */; }; 4C9D6AA917615199001C660C /* HNHRoundedSecureTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C9D6AA817615199001C660C /* HNHRoundedSecureTextFieldCell.m */; }; 4CA08DA017A831B200A6544B /* MPAddEntryContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA08D9F17A831B200A6544B /* MPAddEntryContextMenuDelegate.m */; }; 4CA0B2ED15BCADAC00654E32 /* SettingsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CA0B2EC15BCADAC00654E32 /* SettingsWindow.xib */; }; @@ -788,6 +789,8 @@ 4C96D15317A12E4F00D931FA /* 99_CreatedTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = 99_CreatedTemplate.pdf; path = Icons/99_CreatedTemplate.pdf; sourceTree = ""; }; 4C978E0519AE53FE003067DF /* HNHCommon.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHCommon.m; sourceTree = ""; }; 4C978E0C19AE54AB003067DF /* MPFlagsHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPFlagsHelper.m; sourceTree = ""; }; + 4C9B38CD1A3EFCA100CD21C3 /* NSString+XMLUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+XMLUtilities.h"; sourceTree = ""; }; + 4C9B38CE1A3EFCA100CD21C3 /* NSString+XMLUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+XMLUtilities.m"; sourceTree = ""; }; 4C9D6AA717615199001C660C /* HNHRoundedSecureTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHRoundedSecureTextFieldCell.h; sourceTree = ""; }; 4C9D6AA817615199001C660C /* HNHRoundedSecureTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHRoundedSecureTextFieldCell.m; sourceTree = ""; }; 4CA08D9E17A831B200A6544B /* MPAddEntryContextMenuDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAddEntryContextMenuDelegate.h; sourceTree = ""; }; @@ -1879,6 +1882,8 @@ 4C5CD35417D15DBD000B7F38 /* NSString+Hexdata.m */, 4C89F51F182F9FDD0069C73C /* NSString+Commands.h */, 4C89F520182F9FDD0069C73C /* NSString+Commands.m */, + 4C9B38CD1A3EFCA100CD21C3 /* NSString+XMLUtilities.h */, + 4C9B38CE1A3EFCA100CD21C3 /* NSString+XMLUtilities.m */, 4C1842BE179B5BFD00E2F5BC /* NSData+CommonCrypto.h */, 4C1842BF179B5BFD00E2F5BC /* NSData+CommonCrypto.m */, 4C2724D51778FF1A00FD8456 /* NSUUID+KeePassKit.h */, @@ -2448,6 +2453,7 @@ 4C245BF0176E1E3D0086100E /* ContextFilterLogFormatter.m in Sources */, 4C245BF1176E1E3D0086100E /* DispatchQueueLogFormatter.m in Sources */, 4CF78057176E5CFD0032EE71 /* MPConnection.m in Sources */, + 4C9B38CF1A3EFCA100CD21C3 /* NSString+XMLUtilities.m in Sources */, 4CF7805A176E6D5F0032EE71 /* HNHTableRowView.m in Sources */, 4CF7805D176E71170032EE71 /* MPServerDaemon.m in Sources */, 4CF78064176E75AD0032EE71 /* MPIntegrationSettingsController.m in Sources */, diff --git a/MacPass/Base.lproj/IntegrationSettings.xib b/MacPass/Base.lproj/IntegrationSettings.xib index f426521c..e37de59e 100644 --- a/MacPass/Base.lproj/IntegrationSettings.xib +++ b/MacPass/Base.lproj/IntegrationSettings.xib @@ -7,21 +7,25 @@ - - - + + + + + + + - + - + @@ -44,13 +48,13 @@ - + - + - + @@ -61,14 +65,14 @@ - + @@ -76,7 +80,7 @@ - + @@ -84,26 +88,41 @@ + + + + + + + + + @@ -112,37 +131,42 @@ + - + + + - - + + + + - + - + - + @@ -152,8 +176,8 @@ - - + + @@ -176,7 +200,7 @@ - + diff --git a/MacPass/MPAutotypeCommand.m b/MacPass/MPAutotypeCommand.m index 968e9639..71027e1b 100644 --- a/MacPass/MPAutotypeCommand.m +++ b/MacPass/MPAutotypeCommand.m @@ -147,12 +147,20 @@ static CGKeyCode kMPFunctionKeyCodes[] = { kVK_F1, kVK_F2, kVK_F3, kVK_F4, kVK_F } /* Collect any part that isn't a command or if onyl paste is used */ if(lastLocation < [context.evaluatedCommand length]) { - NSRange pasteRange = NSMakeRange(lastLocation, [context.evaluatedCommand length] - lastLocation); - if(pasteRange.length > 0) { - NSString *pasteValue = [context.evaluatedCommand substringWithRange:pasteRange]; - [self appendAppropriatePasteCommandForEntry:context.entry withContent:pasteValue toCommands:commands]; + /* We might have some dangling modifiers */ + NSRange lastRange = NSMakeRange(lastLocation, [context.evaluatedCommand length] - lastLocation); + if(lastRange.length > 0) { + NSString *modifiedKey = [context.evaluatedCommand substringWithRange:NSMakeRange(lastLocation, 1)]; + MPAutotypeKeyPress *press = [[MPAutotypeKeyPress alloc] initWithModifierMask:collectedModifers character:modifiedKey]; + if(press) { + [commands addObject:press]; + } + if(lastRange.length > 1) { + NSRange pasteRange = NSMakeRange(lastRange.location + 1, lastRange.length - 1); + NSString *pasteValue = [context.evaluatedCommand substringWithRange:pasteRange]; + [self appendAppropriatePasteCommandForEntry:context.entry withContent:pasteValue toCommands:commands]; + } } - } return commands; } diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index be8ee8ee..0c3c2b20 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -133,6 +133,11 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey"; } MPAutotypeContext *context = [self _autotypeContextInDocument:document forWindowTitle:self.targetWindowTitle]; + if(useCurrentWindowAndApplication) { + NSImage *appIcon = [[NSApplication sharedApplication] applicationIconImage]; + NSString *label = context ? NSLocalizedString(@"AUTOTYPE_OVERLAY_SINGLE_MATCH", "") : NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_MATCH", ""); + [[MPOverlayWindowController sharedController] displayOverlayImage:appIcon label:label atView:nil]; + } [self _performAutotypeForContext:context]; } @@ -162,11 +167,9 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey"; NSArray *autotypeCandidates = [document autotypContextsForWindowTitle:windowTitle]; NSUInteger candidates = [autotypeCandidates count]; if(candidates == 0) { - [[MPOverlayWindowController sharedController] displayOverlayImage:[NSImage imageNamed:NSImageNameCaution] label:NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_MATCH", "") atView:nil]; return nil; } if(candidates == 1 ) { - [[MPOverlayWindowController sharedController] displayOverlayImage:[NSImage imageNamed:NSImageNameActionTemplate] label:NSLocalizedString(@"AUTOTYPE_OVERLAY_SINGLE_MATCH", "") atView:nil]; return [autotypeCandidates lastObject]; } [self _presentSelectionWindow:autotypeCandidates]; @@ -251,7 +254,7 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey"; NSArray *attributes = (context.entry.username.length > 0 ) ? @[ context.entry.username, context.command ] : @[ context.command ]; - + for(NSString *value in attributes) { NSMenuItem *valueItem = [[NSMenuItem alloc] initWithTitle:value action:NULL keyEquivalent:@""]; [valueItem setIndentationLevel:1]; diff --git a/MacPass/MPIntegrationSettingsController.h b/MacPass/MPIntegrationSettingsController.h index 75476e82..9430a137 100644 --- a/MacPass/MPIntegrationSettingsController.h +++ b/MacPass/MPIntegrationSettingsController.h @@ -13,10 +13,21 @@ @interface MPIntegrationSettingsController : MPViewController -@property (weak) IBOutlet NSButton *enableServerCheckbutton; -@property (weak) IBOutlet NSButton *enableGlobalAutotypeCheckbutton; -@property (weak) IBOutlet NSButton *enableQuicklookCheckbutton; +/* Keepass HTTP */ +@property (weak) IBOutlet NSButton *enableServerCheckBox; + +/* Autotype */ +@property (weak) IBOutlet NSButton *enableGlobalAutotypeCheckBox; @property (weak) IBOutlet DDHotKeyTextField *hotKeyTextField; @property (weak) IBOutlet NSTextField *hotkeyWarningTextField; +@property (weak) IBOutlet NSButton *matchURLCheckBox; +@property (weak) IBOutlet NSButton *matchHostCheckBox; +@property (weak) IBOutlet NSButton *matchTagsCheckBox; + +@property (weak) IBOutlet NSButton *sendCommandForControlCheckBox; + +/* Preview */ +@property (weak) IBOutlet NSButton *enableQuicklookCheckBox; + @end diff --git a/MacPass/MPIntegrationSettingsController.m b/MacPass/MPIntegrationSettingsController.m index bc01b5e3..94b4759f 100644 --- a/MacPass/MPIntegrationSettingsController.m +++ b/MacPass/MPIntegrationSettingsController.m @@ -43,13 +43,21 @@ NSString *serverKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableHttpServer]; NSString *enableGlobalAutotypeKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableGlobalAutotype]; NSString *quicklookKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableQuicklookPreview]; - [self.enableServerCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:serverKeyPath options:nil]; - [self.enableServerCheckbutton setEnabled:NO]; - [self.enableGlobalAutotypeCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:enableGlobalAutotypeKeyPath options:nil]; - [self.enableQuicklookCheckbutton bind:NSValueBinding toObject:defaultsController withKeyPath:quicklookKeyPath options:nil]; + [self.enableServerCheckBox bind:NSValueBinding toObject:defaultsController withKeyPath:serverKeyPath options:nil]; + [self.enableServerCheckBox setEnabled:NO]; + [self.enableGlobalAutotypeCheckBox bind:NSValueBinding toObject:defaultsController withKeyPath:enableGlobalAutotypeKeyPath options:nil]; + [self.enableQuicklookCheckBox bind:NSValueBinding toObject:defaultsController withKeyPath:quicklookKeyPath options:nil]; [self.hotKeyTextField bind:NSEnabledBinding toObject:defaultsController withKeyPath:enableGlobalAutotypeKeyPath options:nil]; self.hotKeyTextField.delegate = self; + /* + [self.matchHostCheckBox bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyAutotypeMatchHost] options:nil]; + [self.matchTagsCheckBox bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyAutotypeMatchTags] options:nil]; + [self.matchURLCheckBox bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyAutotypeMatchURL] options:nil]; + */ + + [self.sendCommandForControlCheckBox bind:NSValueBinding toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeySendCommandForControlKey] options:nil]; + [self _showWarning:NO]; } diff --git a/MacPassTests/KPKTestAutotype.m b/MacPassTests/KPKTestAutotype.m index a59f1815..e1a7c614 100644 --- a/MacPassTests/KPKTestAutotype.m +++ b/MacPassTests/KPKTestAutotype.m @@ -238,5 +238,21 @@ keyPress = commands[4]; XCTAssertEqual(keyPress.keyCode, kVK_Return); XCTAssertEqual(keyPress.modifierMask, 0); + + + /* Command 3 */ + context = [[MPAutotypeContext alloc] initWithEntry:self.entry andSequence:@"^T"]; + commands = [MPAutotypeCommand commandsForContext:context]; + XCTAssertTrue(commands.count == 1); + XCTAssertTrue([commands[0] isKindOfClass:[MPAutotypeKeyPress class]]); + + /*^T*/ + keyPress = commands[0]; + XCTAssertEqualObjects(@"t", [MPKeyMapper stringForKey:keyPress.keyCode]); + /* TODO - Respect user settings? */ + XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskCommand); + /*XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskControl);*/ + + } @end diff --git a/MacPassTests/KPKTextXMLUtilities.m b/MacPassTests/KPKTextXMLUtilities.m index d81c95c2..943c416f 100644 --- a/MacPassTests/KPKTextXMLUtilities.m +++ b/MacPassTests/KPKTextXMLUtilities.m @@ -9,7 +9,7 @@ #import #import -#import "KPKXmlUtilities.h" +#import "NSString+XMLUtilities.h" @interface KPKTextXMLUtilities : XCTestCase @@ -26,8 +26,8 @@ } - (void)testExample { - NSString *safe = stripUnsafeCharacterForXMLFromString(@"*EORDIE\x10\x16\x12\x10"); - XCTAssertEqualObjects(@"*EORDIE", safe); + NSString *unsave = @"*EORDIE\x10\x16\x12\x10"; + XCTAssertEqualObjects(@"*EORDIE", unsave.XMLCompatibleString); } @end