From d6f44113137efba5e26370b4a0d833de01605d56 Mon Sep 17 00:00:00 2001 From: michael starke Date: Thu, 26 Oct 2017 19:34:09 +0200 Subject: [PATCH] began extracting Autotypecandidate selection to separate controller --- MacPass.xcodeproj/project.pbxproj | 26 +++- ...totypeCandidateSelectionViewController.xib | 133 ++++++++++++++++++ .../AutotypeCandidateSelectionWindow.xib | 58 ++++---- ...AutotypeCandidateSelectionViewController.h | 15 ++ ...AutotypeCandidateSelectionViewController.m | 40 ++++++ MacPass/MPAutotypeDaemon.m | 22 ++- MacPass/PasswordCreatorWindow.xib | 9 +- 7 files changed, 265 insertions(+), 38 deletions(-) create mode 100644 MacPass/AutotypeCandidateSelectionViewController.xib rename MacPass/{ => Base.lproj}/AutotypeCandidateSelectionWindow.xib (84%) create mode 100644 MacPass/MPAutotypeCandidateSelectionViewController.h create mode 100644 MacPass/MPAutotypeCandidateSelectionViewController.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index c9b76a35..691bcb43 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -17,7 +17,6 @@ 4C0B038D18E36DA400B9F9C9 /* FixAutotypeWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0B038B18E36DA400B9F9C9 /* FixAutotypeWindow.xib */; }; 4C0C59F118B17F10009C7B76 /* DDHotKeyUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0C59EF18B17F10009C7B76 /* DDHotKeyUtilities.m */; }; 4C0DBEF51BF508DE00F9B287 /* PluginSettings.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0DBEF71BF508DE00F9B287 /* PluginSettings.xib */; }; - 4C0DD6C618B2A44700FCB193 /* AutotypeCandidateSelectionWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C0DD6C518B2A44700FCB193 /* AutotypeCandidateSelectionWindow.xib */; }; 4C0F647B17B6BC9C00D9522A /* MPSavePanelAccessoryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0F647A17B6BC9C00D9522A /* MPSavePanelAccessoryViewController.m */; }; 4C10207F1B750E2F00BFCD59 /* MPTestAutotype.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C10207E1B750E2F00BFCD59 /* MPTestAutotype.m */; }; 4C10412C178CDD44001B5239 /* NSDate+Humanized.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C10412B178CDD44001B5239 /* NSDate+Humanized.m */; }; @@ -140,6 +139,9 @@ 4C6BC6601A36717E00BDDF3D /* MPDatabaseSearch.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6BC65F1A36717E00BDDF3D /* MPDatabaseSearch.m */; }; 4C6D1D25178579570014C5A5 /* 48_FolderTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C6D1D24178579570014C5A5 /* 48_FolderTemplate.pdf */; }; 4C6DCC451FA2457900C8AD3F /* ContextBar.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C6DCC471FA2457900C8AD3F /* ContextBar.xib */; }; + 4C6DCC5B1FA24AC600C8AD3F /* AutotypeCandidateSelectionWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C6DCC5D1FA24AC600C8AD3F /* AutotypeCandidateSelectionWindow.xib */; }; + 4C6DCC611FA24C2100C8AD3F /* MPAutotypeCandidateSelectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6DCC5F1FA24C2100C8AD3F /* MPAutotypeCandidateSelectionViewController.m */; }; + 4C6DCC621FA24C2100C8AD3F /* AutotypeCandidateSelectionViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C6DCC601FA24C2100C8AD3F /* AutotypeCandidateSelectionViewController.xib */; }; 4C6F228919A4A7F90012310C /* MPAutotypeClear.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6F228819A4A7F90012310C /* MPAutotypeClear.m */; }; 4C6F228C19A4AA700012310C /* MPAutotypeDelay.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6F228B19A4AA700012310C /* MPAutotypeDelay.m */; }; 4C701CBC178618A000581B88 /* 12_RemoteTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C701CBB178618A000581B88 /* 12_RemoteTemplate.pdf */; }; @@ -320,7 +322,6 @@ 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; lineEnding = 0; name = DDHotKeyUtilities.h; path = DDHotKey/DDHotKeyUtilities.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; 4C0DBEF61BF508DE00F9B287 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PluginSettings.xib; sourceTree = ""; }; - 4C0DD6C518B2A44700FCB193 /* AutotypeCandidateSelectionWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AutotypeCandidateSelectionWindow.xib; sourceTree = ""; }; 4C0F647917B6BC9C00D9522A /* MPSavePanelAccessoryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSavePanelAccessoryViewController.h; sourceTree = ""; }; 4C0F647A17B6BC9C00D9522A /* MPSavePanelAccessoryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSavePanelAccessoryViewController.m; sourceTree = ""; }; 4C10207E1B750E2F00BFCD59 /* MPTestAutotype.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPTestAutotype.m; sourceTree = ""; }; @@ -533,6 +534,10 @@ 4C6DCC571FA2458200C8AD3F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/ContextBar.strings; sourceTree = ""; }; 4C6DCC591FA2458300C8AD3F /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/ContextBar.strings; sourceTree = ""; }; 4C6DCC5A1FA246ED00C8AD3F /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = de; path = de.lproj/Localizable.stringsdict; sourceTree = ""; }; + 4C6DCC5C1FA24AC600C8AD3F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/AutotypeCandidateSelectionWindow.xib; sourceTree = ""; }; + 4C6DCC5E1FA24C2100C8AD3F /* MPAutotypeCandidateSelectionViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPAutotypeCandidateSelectionViewController.h; sourceTree = ""; }; + 4C6DCC5F1FA24C2100C8AD3F /* MPAutotypeCandidateSelectionViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPAutotypeCandidateSelectionViewController.m; sourceTree = ""; }; + 4C6DCC601FA24C2100C8AD3F /* AutotypeCandidateSelectionViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AutotypeCandidateSelectionViewController.xib; sourceTree = ""; }; 4C6F228719A4A7F90012310C /* MPAutotypeClear.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypeClear.h; sourceTree = ""; }; 4C6F228819A4A7F90012310C /* MPAutotypeClear.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAutotypeClear.m; sourceTree = ""; }; 4C6F228A19A4AA700012310C /* MPAutotypeDelay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypeDelay.h; sourceTree = ""; }; @@ -1491,6 +1496,9 @@ 4C8990F41EE978EB0043B48D /* MPDuplicateEntryOptionsWindowController.h */, 4C8990F51EE978EB0043B48D /* MPDuplicateEntryOptionsWindowController.m */, 4CA1827A1F96523600DD4A4A /* DuplicateEntryOptionsWindow.xib */, + 4C6DCC5E1FA24C2100C8AD3F /* MPAutotypeCandidateSelectionViewController.h */, + 4C6DCC5F1FA24C2100C8AD3F /* MPAutotypeCandidateSelectionViewController.m */, + 4C6DCC601FA24C2100C8AD3F /* AutotypeCandidateSelectionViewController.xib */, ); name = "Window Controller"; sourceTree = ""; @@ -1511,9 +1519,9 @@ 4CE8247216E2E99F00573141 /* Windows */ = { isa = PBXGroup; children = ( + 4C6DCC5D1FA24AC600C8AD3F /* AutotypeCandidateSelectionWindow.xib */, 4C1DDCDC1711ECEB00C98DA3 /* PasswordCreatorWindow.xib */, 4C7F8B6A1A10B68400CCB83D /* WelcomeWindow.xib */, - 4C0DD6C518B2A44700FCB193 /* AutotypeCandidateSelectionWindow.xib */, ); name = Windows; sourceTree = ""; @@ -1745,8 +1753,9 @@ 4C7ABA4A17BAEC6700FF5799 /* 17_CDRomTemplate.pdf in Resources */, 4C7ABA4B17BAEC6700FF5799 /* 19_EmailTemplate.pdf in Resources */, 4C3826C81AD04D8E007D7D67 /* 61_ServicesTemplate.pdf in Resources */, + 4C6DCC621FA24C2100C8AD3F /* AutotypeCandidateSelectionViewController.xib in Resources */, 4C0B038D18E36DA400B9F9C9 /* FixAutotypeWindow.xib in Resources */, - 4C0DD6C618B2A44700FCB193 /* AutotypeCandidateSelectionWindow.xib in Resources */, + 4C6DCC5B1FA24AC600C8AD3F /* AutotypeCandidateSelectionWindow.xib in Resources */, 4C38267A1AD04CC6007D7D67 /* downloadTemplate.pdf in Resources */, 4C7ABA4C17BAEC6700FF5799 /* 20_MiscTemplate.pdf in Resources */, 4C7ABA4E17BAEC7000FF5799 /* addEntryTemplate.pdf in Resources */, @@ -1821,6 +1830,7 @@ 4C7B63761C0CB51F00D7038C /* TTTJSONTransformer.m in Sources */, 4C77547516E55FE800970E02 /* MPInspectorViewController.m in Sources */, 4C89F524182FB4740069C73C /* MPAutotypeCommand.m in Sources */, + 4C6DCC611FA24C2100C8AD3F /* MPAutotypeCandidateSelectionViewController.m in Sources */, 4CFC53BF16E94729007396BE /* MPShadowBox.m in Sources */, 4C0AF62F195C1F2B009E658D /* MPEntrySearchContext.m in Sources */, 4C1F7FA21E3A12E600D6A40E /* MPModifiedKey.m in Sources */, @@ -1985,6 +1995,14 @@ name = ContextBar.xib; sourceTree = ""; }; + 4C6DCC5D1FA24AC600C8AD3F /* AutotypeCandidateSelectionWindow.xib */ = { + isa = PBXVariantGroup; + children = ( + 4C6DCC5C1FA24AC600C8AD3F /* Base */, + ); + name = AutotypeCandidateSelectionWindow.xib; + sourceTree = ""; + }; 4C7155DA1A10DB6D00979307 /* IconSelection.xib */ = { isa = PBXVariantGroup; children = ( diff --git a/MacPass/AutotypeCandidateSelectionViewController.xib b/MacPass/AutotypeCandidateSelectionViewController.xib new file mode 100644 index 00000000..d66ccf74 --- /dev/null +++ b/MacPass/AutotypeCandidateSelectionViewController.xib @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MacPass/AutotypeCandidateSelectionWindow.xib b/MacPass/Base.lproj/AutotypeCandidateSelectionWindow.xib similarity index 84% rename from MacPass/AutotypeCandidateSelectionWindow.xib rename to MacPass/Base.lproj/AutotypeCandidateSelectionWindow.xib index b7dad74d..882289ee 100644 --- a/MacPass/AutotypeCandidateSelectionWindow.xib +++ b/MacPass/Base.lproj/AutotypeCandidateSelectionWindow.xib @@ -1,8 +1,9 @@ - - + + - + + @@ -15,14 +16,14 @@ - - + + - + + + + + + + + + + + + + + + + + - + @@ -59,31 +76,17 @@ DQ - - - - - - - - - - - - - - - - - - + + + + @@ -93,6 +96,7 @@ DQ + diff --git a/MacPass/MPAutotypeCandidateSelectionViewController.h b/MacPass/MPAutotypeCandidateSelectionViewController.h new file mode 100644 index 00000000..fe7d035a --- /dev/null +++ b/MacPass/MPAutotypeCandidateSelectionViewController.h @@ -0,0 +1,15 @@ +// +// MPAutotypeCandidateSelectionViewController.h +// MacPass +// +// Created by Michael Starke on 26.10.17. +// Copyright © 2017 HicknHack Software GmbH. All rights reserved. +// + +#import + +@interface MPAutotypeCandidateSelectionViewController : NSViewController + +@property (copy) NSArray *candidates; + +@end diff --git a/MacPass/MPAutotypeCandidateSelectionViewController.m b/MacPass/MPAutotypeCandidateSelectionViewController.m new file mode 100644 index 00000000..d1be88a4 --- /dev/null +++ b/MacPass/MPAutotypeCandidateSelectionViewController.m @@ -0,0 +1,40 @@ +// +// MPAutotypeCandidateSelectionViewController.m +// MacPass +// +// Created by Michael Starke on 26.10.17. +// Copyright © 2017 HicknHack Software GmbH. All rights reserved. +// + +#import "MPAutotypeCandidateSelectionViewController.h" +#import "MPAutotypeContext.h" + +#import + +@interface MPAutotypeCandidateSelectionViewController () + +@end + +@implementation MPAutotypeCandidateSelectionViewController + +- (NSNibName)nibName { + return @"AutotypeCandidateSelectionViewController"; +} + +- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { + return self.candidates.count; +} + +- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { + NSTableCellView *view = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self]; + MPAutotypeContext *context = self.candidates[row]; + view.textField.stringValue = context.entry.title; + view.imageView.image = context.entry.icon.image; + return view; +} +- (void)viewDidLoad { + [super viewDidLoad]; + // Do view setup here. +} + +@end diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index 8a75be2a..3997f800 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -32,6 +32,8 @@ #import "NSApplication+MPAdditions.h" +#import "MPAutotypeCandidateSelectionViewController.h" + #import "KeePassKit/KeePassKit.h" #import "DDHotKeyCenter.h" @@ -142,11 +144,13 @@ static MPAutotypeDaemon *_sharedInstance; NSMenuItem *item = self.matchSelectionButton.selectedItem; MPAutotypeContext *context = item.representedObject; [self.matchSelectionWindow orderOut:self]; + self.matchSelectionWindow = nil; [self _performAutotypeForContext:context]; } - (void)cancelAutotypeSelection:(id)sender { [self.matchSelectionWindow orderOut:sender]; + self.matchSelectionWindow = nil; if(self.targetPID) { [self _orderApplicationToFront:self.targetPID]; } @@ -187,6 +191,9 @@ static MPAutotypeDaemon *_sharedInstance; MPAutotypeContext *context = [self _autotypeContextForDocuments:documents forWindowTitle:self.targetWindowTitle preferredEntry:entryOrNil]; /* TODO: that's popping up if the mulit selection dialog goes up! */ + if(self.matchSelectionWindow) { + return; // we present the match selection window, just return + } if(!entryOrNil) { NSUserNotification *notification = [[NSUserNotification alloc] init]; notification.title = NSApp.applicationName; @@ -289,11 +296,18 @@ static MPAutotypeDaemon *_sharedInstance; } - (void)_presentSelectionWindow:(NSArray *)candidates { + + if(!self.matchSelectionWindow) { - [[NSBundle mainBundle] loadNibNamed:@"AutotypeCandidateSelectionWindow" owner:self topLevelObjects:nil]; - self.matchSelectionWindow.level = NSFloatingWindowLevel; + //[[NSBundle mainBundle] loadNibNamed:@"AutotypeCandidateSelectionWindow" owner:self topLevelObjects:nil]; + self.matchSelectionWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreRetained defer:YES]; + //self.matchSelectionWindow.level = NSFloatingWindowLevel; + MPAutotypeCandidateSelectionViewController *vc = [[MPAutotypeCandidateSelectionViewController alloc] init]; + vc.candidates = candidates; + self.matchSelectionWindow.contentViewController = vc; + } - NSMenu *associationMenu = [[NSMenu alloc] init]; + /*NSMenu *associationMenu = [[NSMenu alloc] init]; [associationMenu addItemWithTitle:NSLocalizedString(@"SELECT_AUTOTYPE_CANDIDATE", "Menu item for selection a single match from multiple Autotype matches") action:NULL keyEquivalent:@""]; [associationMenu addItem:[NSMenuItem separatorItem]]; associationMenu.autoenablesItems = NO; @@ -313,6 +327,8 @@ static MPAutotypeDaemon *_sharedInstance; } } self.matchSelectionButton.menu = associationMenu; + */ + [self.matchSelectionWindow center]; [self.matchSelectionWindow makeKeyAndOrderFront:self]; [NSApp activateIgnoringOtherApps:YES]; } diff --git a/MacPass/PasswordCreatorWindow.xib b/MacPass/PasswordCreatorWindow.xib index f6c3715e..cc9ef516 100644 --- a/MacPass/PasswordCreatorWindow.xib +++ b/MacPass/PasswordCreatorWindow.xib @@ -1,7 +1,8 @@ - + - + + @@ -15,12 +16,12 @@ - + - +