From e976398a5e69d4f797d3af16320e8f5f9c800066 Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 17 Feb 2014 21:45:06 +0100 Subject: [PATCH] Selection Dialog for multiple matching entries sketched --- MacPass.xcodeproj/project.pbxproj | 4 + MacPass/AutotypeCandidateSelectionWindow.xib | 97 ++++++++++++++++++++ MacPass/MPAutotypeDaemon.h | 10 ++ MacPass/MPAutotypeDaemon.m | 22 ++++- MacPass/MPDocument+Autotype.m | 3 + 5 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 MacPass/AutotypeCandidateSelectionWindow.xib diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index c8c2ba4f..37498dee 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 4C0728BF17B68ED0005A7DD9 /* SavePanelAccessoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0728BE17B68ED0005A7DD9 /* SavePanelAccessoryView.xib */; }; 4C08C3AE17B3022400BBBC95 /* KPKLegacyHeaderWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C08C3AD17B3022400BBBC95 /* KPKLegacyHeaderWriter.m */; }; 4C0C59F118B17F10009C7B76 /* DDHotKeyUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0C59EF18B17F10009C7B76 /* DDHotKeyUtilities.m */; }; + 4C0DD6C618B2A44700FCB193 /* AutotypeCandidateSelectionWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0DD6C518B2A44700FCB193 /* AutotypeCandidateSelectionWindow.xib */; }; 4C0F647817B6B65E00D9522A /* MPSheetWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0F647717B6B65E00D9522A /* MPSheetWindowController.m */; }; 4C0F647B17B6BC9C00D9522A /* MPSavePanelAccessoryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0F647A17B6BC9C00D9522A /* MPSavePanelAccessoryViewController.m */; }; 4C10412C178CDD44001B5239 /* NSDate+Humanized.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C10412B178CDD44001B5239 /* NSDate+Humanized.m */; }; @@ -364,6 +365,7 @@ 4C08C3AF17B3036500BBBC95 /* KPKLegacyFormat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = KPKLegacyFormat.h; path = Format/KPKLegacyFormat.h; sourceTree = ""; }; 4C0C59EF18B17F10009C7B76 /* DDHotKeyUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DDHotKeyUtilities.m; path = DDHotKey/DDHotKeyUtilities.m; sourceTree = ""; }; 4C0C59F018B17F10009C7B76 /* DDHotKeyUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DDHotKeyUtilities.h; path = DDHotKey/DDHotKeyUtilities.h; sourceTree = ""; }; + 4C0DD6C518B2A44700FCB193 /* AutotypeCandidateSelectionWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AutotypeCandidateSelectionWindow.xib; sourceTree = ""; }; 4C0F647617B6B65E00D9522A /* MPSheetWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSheetWindowController.h; sourceTree = ""; }; 4C0F647717B6B65E00D9522A /* MPSheetWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSheetWindowController.m; sourceTree = ""; }; 4C0F647917B6BC9C00D9522A /* MPSavePanelAccessoryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSavePanelAccessoryViewController.h; sourceTree = ""; }; @@ -1762,6 +1764,7 @@ 4CD5D701177A5EE400100649 /* DatabaseSettingsWindow.xib */, 4C0728B917B5B7A4005A7DD9 /* PasswordEditWindow.xib */, 4C68456E17BC2A0700FCDBFC /* WelcomeWindow.xib */, + 4C0DD6C518B2A44700FCB193 /* AutotypeCandidateSelectionWindow.xib */, ); name = Windows; sourceTree = ""; @@ -2008,6 +2011,7 @@ 4C7ABA4917BAEC6700FF5799 /* 16_BrowserTemplate.pdf in Resources */, 4C7ABA4A17BAEC6700FF5799 /* 17_CDRomTemplate.pdf in Resources */, 4C7ABA4B17BAEC6700FF5799 /* 19_EmailTemplate.pdf in Resources */, + 4C0DD6C618B2A44700FCB193 /* AutotypeCandidateSelectionWindow.xib in Resources */, 4C7ABA4C17BAEC6700FF5799 /* 20_MiscTemplate.pdf in Resources */, 4C7ABA4E17BAEC7000FF5799 /* addEntryTemplate.pdf in Resources */, 4C53A7A51864C39D000DFF0D /* KPKLocalizeable.strings in Resources */, diff --git a/MacPass/AutotypeCandidateSelectionWindow.xib b/MacPass/AutotypeCandidateSelectionWindow.xib new file mode 100644 index 00000000..dd0427a1 --- /dev/null +++ b/MacPass/AutotypeCandidateSelectionWindow.xib @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MacPass/MPAutotypeDaemon.h b/MacPass/MPAutotypeDaemon.h index e8a628c9..e3408f5d 100644 --- a/MacPass/MPAutotypeDaemon.h +++ b/MacPass/MPAutotypeDaemon.h @@ -15,6 +15,16 @@ */ @interface MPAutotypeDaemon : NSObject +@property (strong) IBOutlet NSWindow *matchSelectionWindow; +@property (weak) IBOutlet NSPopUpButton *matchSelectionButton; +@property (weak) IBOutlet NSButton *performAutotypeButton; + - (void)exectureAutotypeForEntry:(KPKEntry *)entry withWindowTitle:(NSString *)title; +/** + * Called by the selection window to start the autotype sequence + * + * @param sender sender of the action. + */ +- (IBAction)executeAutotypeWithSelectedMatch:(id)sender; @end diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index 484e652e..261ea0bc 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -34,6 +34,11 @@ NSString *const kMPApplciationNameKey = @"applicationName"; NSAssert(NO,@"Not Implemented"); } +- (void)executeAutotypeWithSelectedMatch:(id)sender { + NSMenuItem *item = [self.matchSelectionButton selectedItem]; + MPAutotypeContext *context = [item representedObject]; +} + - (void)_didPressHotKey { NSArray *documents = [NSApp orderedDocuments]; MPDocument *currentDocument = nil; @@ -59,14 +64,14 @@ NSString *const kMPApplciationNameKey = @"applicationName"; Query the document to generate a autotype command list for the window title We do not care where this came form, just get the autotype commands */ - NSArray *autotypeCandidates = [[currentDocument autotypContextsForWindowTitle:windowTitle] lastObject]; + NSArray *autotypeCandidates = [currentDocument autotypContextsForWindowTitle:windowTitle]; NSUInteger candiates = [autotypeCandidates count]; if(candiates == 0) { return; // No Entries found. } - if(candiates > 1) { - // open Dialog to select from possible entries + [self _presentSelectionWindow]; + 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! */ [self _orderApplicationToFront:applicationName]; @@ -113,6 +118,16 @@ NSString *const kMPApplciationNameKey = @"applicationName"; return nil; } +- (void)_presentSelectionWindow { + if(!self.matchSelectionWindow) { + [[NSBundle mainBundle] loadNibNamed:@"AutotypeCandidateSelectionWindow" owner:self topLevelObjects:nil]; + [self.performAutotypeButton setTarget:self]; + [self.performAutotypeButton setAction:@selector(executeAutotypeWithSelectedMatch:)]; + } + [self.matchSelectionWindow makeKeyAndOrderFront:self]; + /* Setup Items in Popup */ +} + - (void)_orderApplicationToFront:(NSString *)applicationName { NSString *appleScript = [[NSString alloc] initWithFormat:@"activate application %@", applicationName]; NSAppleScript *script = [[NSAppleScript alloc] initWithSource:appleScript]; @@ -120,4 +135,5 @@ NSString *const kMPApplciationNameKey = @"applicationName"; [script executeAndReturnError:&error]; } + @end diff --git a/MacPass/MPDocument+Autotype.m b/MacPass/MPDocument+Autotype.m index d2fe9186..f73079d3 100644 --- a/MacPass/MPDocument+Autotype.m +++ b/MacPass/MPDocument+Autotype.m @@ -31,6 +31,9 @@ @implementation MPDocument (Autotype) - (NSArray *)autotypContextsForWindowTitle:(NSString *)windowTitle { + if(!windowTitle) { + return nil; + } NSArray *autotypeEntries = [self.root autotypeableChildEntries]; NSMutableArray *contexts = [[NSMutableArray alloc] initWithCapacity:ceil([autotypeEntries count] / 4.0)]; for(KPKEntry *entry in autotypeEntries) {