Autotype for a selected entry. WIP

This commit is contained in:
michael starke
2014-12-16 20:37:55 +01:00
parent 1f92e5aeef
commit 3eb98a516c
9 changed files with 101 additions and 83 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment defaultVersion="1080" identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPAutotypeDaemon"> <customObject id="-2" userLabel="File's Owner" customClass="MPAutotypeDaemon">
@@ -12,7 +12,7 @@
</connections> </connections>
</customObject> </customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/> <customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Autotype Selection" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="1"> <window title="Autotype Selection" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
<windowStyleMask key="styleMask" titled="YES"/> <windowStyleMask key="styleMask" titled="YES"/>
<rect key="contentRect" x="196" y="240" width="370" height="156"/> <rect key="contentRect" x="196" y="240" width="370" height="156"/>
@@ -23,7 +23,6 @@
<subviews> <subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="NdQ-vM-dHT"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="NdQ-vM-dHT">
<rect key="frame" x="123" y="13" width="82" height="32"/> <rect key="frame" x="123" y="13" width="82" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="WJJ-kW-fak"> <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="WJJ-kW-fak">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@@ -37,7 +36,6 @@ Gw
</button> </button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Jlm-i9-jVy"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Jlm-i9-jVy">
<rect key="frame" x="205" y="13" width="151" height="32"/> <rect key="frame" x="205" y="13" width="151" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Perform Autotype" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="AER-eU-kcu"> <buttonCell key="cell" type="push" title="Perform Autotype" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="AER-eU-kcu">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@@ -46,12 +44,11 @@ DQ
</string> </string>
</buttonCell> </buttonCell>
<connections> <connections>
<action selector="executeAutotypeWithSelectedMatch:" target="-2" id="icM-Aj-OHO"/> <action selector="performAutotypeWithSelectedMatch:" target="-2" id="vRo-HH-NIy"/>
</connections> </connections>
</button> </button>
<popUpButton verticalHuggingPriority="750" horizontalCompressionResistancePriority="499" translatesAutoresizingMaskIntoConstraints="NO" id="tAw-72-pSm"> <popUpButton verticalHuggingPriority="750" horizontalCompressionResistancePriority="499" translatesAutoresizingMaskIntoConstraints="NO" id="tAw-72-pSm">
<rect key="frame" x="111" y="58" width="242" height="26"/> <rect key="frame" x="111" y="58" width="242" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="TAr-ZQ-aDu"> <popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="TAr-ZQ-aDu">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/> <font key="font" metaFont="menu"/>
@@ -64,7 +61,6 @@ DQ
</popUpButton> </popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="q1d-ED-T5M"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="q1d-ED-T5M">
<rect key="frame" x="18" y="102" width="334" height="34"/> <rect key="frame" x="18" y="102" width="334" height="34"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="There are multiple matches for the current window. Please select which match should be used." id="ehp-xc-B5g"> <textFieldCell key="cell" sendsActionOnEndEditing="YES" title="There are multiple matches for the current window. Please select which match should be used." id="ehp-xc-B5g">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -73,7 +69,6 @@ DQ
</textField> </textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Epz-xU-9TM"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Epz-xU-9TM">
<rect key="frame" x="18" y="64" width="89" height="17"/> <rect key="frame" x="18" y="64" width="89" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Match to use:" id="pLz-Kc-yPh"> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Match to use:" id="pLz-Kc-yPh">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>

View File

@@ -22,12 +22,15 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
FOUNDATION_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings; APPKIT_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings;
@class MPAutotypeDaemon;
@interface MPAppDelegate : NSObject <NSApplicationDelegate, NSMenuDelegate> @interface MPAppDelegate : NSObject <NSApplicationDelegate, NSMenuDelegate>
@property (strong) IBOutlet NSWindow *passwordCreatorWindow; @property (strong) IBOutlet NSWindow *passwordCreatorWindow;
@property (strong) IBOutlet NSWindow *welcomeWindow; @property (strong) IBOutlet NSWindow *welcomeWindow;
@property (strong) MPAutotypeDaemon *autotypeDaemon;
@property (weak) IBOutlet NSMenuItem *saveMenuItem; @property (weak) IBOutlet NSMenuItem *saveMenuItem;
@property (nonatomic, assign) BOOL isAllowedToStoreKeyFile; @property (nonatomic, assign) BOOL isAllowedToStoreKeyFile;
@@ -41,7 +44,6 @@ FOUNDATION_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings;
*/ */
- (IBAction)clearRememberdKeyFiles:(id)sender; - (IBAction)clearRememberdKeyFiles:(id)sender;
- (NSString *)applicationName; - (NSString *)applicationName;
- (void)lockAllDocuments; - (void)lockAllDocuments;

View File

@@ -44,7 +44,6 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
@private @private
MPServerDaemon *serverDaemon; MPServerDaemon *serverDaemon;
MPLockDaemon *lockDaemon; MPLockDaemon *lockDaemon;
MPAutotypeDaemon *autotypeDaemon;
MPDockTileHelper *dockTileHelper; MPDockTileHelper *dockTileHelper;
BOOL _shouldOpenFile; // YES if app was started to open a BOOL _shouldOpenFile; // YES if app was started to open a
} }
@@ -158,7 +157,7 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
- (void)applicationDidFinishLaunching:(NSNotification *)notification { - (void)applicationDidFinishLaunching:(NSNotification *)notification {
serverDaemon = [[MPServerDaemon alloc] init]; serverDaemon = [[MPServerDaemon alloc] init];
lockDaemon = [[MPLockDaemon alloc] init]; lockDaemon = [[MPLockDaemon alloc] init];
autotypeDaemon = [[MPAutotypeDaemon alloc] init]; self.autotypeDaemon = [[MPAutotypeDaemon alloc] init];
//dockTileHelper = [[MPDockTileHelper alloc] init]; //dockTileHelper = [[MPDockTileHelper alloc] init];
} }

View File

@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class DDHotKey; @class DDHotKey;
@class KPKEntry;
/** /**
* The autotype daemon is repsonsible for registering the globa hotkey and to perform any autotype actions * The autotype daemon is repsonsible for registering the globa hotkey and to perform any autotype actions
@@ -19,7 +20,8 @@
@property (weak) IBOutlet NSPopUpButton *matchSelectionButton; @property (weak) IBOutlet NSPopUpButton *matchSelectionButton;
@property (readonly, strong) DDHotKey *registredHotKey; @property (readonly, strong) DDHotKey *registredHotKey;
- (IBAction)executeAutotypeWithSelectedMatch:(id)sender; - (void)performAutotypeForEntry:(KPKEntry *)entryOrNil;
- (IBAction)performAutotypeWithSelectedMatch:(id)sender;
- (IBAction)cancelAutotypeSelection:(id)sender; - (IBAction)cancelAutotypeSelection:(id)sender;
@end @end

View File

@@ -44,7 +44,7 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
#pragma mark - #pragma mark -
#pragma mark Lifecylce #pragma mark Lifecylce
- (id)init { - (instancetype)init {
self = [super init]; self = [super init];
if (self) { if (self) {
_enabled = NO; _enabled = NO;
@@ -59,16 +59,17 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyGlobalAutotypeKeyDataKey] withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyGlobalAutotypeKeyDataKey]
options:nil]; options:nil];
[[NSNotificationCenter defaultCenter] addObserver:self [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
selector:@selector(_applicationWillBecomeActive:) selector:@selector(_didDeactivateApplication:)
name:NSApplicationWillBecomeActiveNotification name:NSWorkspaceDidDeactivateApplicationNotification
object:[NSApplication sharedApplication]]; object:nil];
} }
return self; return self;
} }
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
[self unbind:NSStringFromSelector(@selector(enabled))]; [self unbind:NSStringFromSelector(@selector(enabled))];
[self unbind:NSStringFromSelector(@selector(hotKeyData))]; [self unbind:NSStringFromSelector(@selector(hotKeyData))];
} }
@@ -93,11 +94,12 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
} }
} }
- (void)executeAutotypeForEntry:(KPKEntry *)entry {
}
#pragma mark - #pragma mark -
#pragma mark Actions #pragma mark Actions
- (void)performAutotypeWithSelectedMatch:(id)sender {
- (void)executeAutotypeWithSelectedMatch:(id)sender {
NSMenuItem *item = [self.matchSelectionButton selectedItem]; NSMenuItem *item = [self.matchSelectionButton selectedItem];
MPAutotypeContext *context = [item representedObject]; MPAutotypeContext *context = [item representedObject];
[self.matchSelectionWindow orderOut:self]; [self.matchSelectionWindow orderOut:self];
@@ -107,7 +109,7 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
- (void)cancelAutotypeSelection:(id)sender { - (void)cancelAutotypeSelection:(id)sender {
[self.matchSelectionWindow orderOut:sender]; [self.matchSelectionWindow orderOut:sender];
if(self.targetPID) { if(self.targetPID) {
[MPAutotypeDaemon _orderApplicationToFront:self.targetPID]; [self _orderApplicationToFront:self.targetPID];
} }
} }
@@ -115,13 +117,11 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
#pragma mark Hotkey evaluation #pragma mark Hotkey evaluation
- (void)_didPressHotKey { - (void)_didPressHotKey {
[self _performAutotypeUsingCurrentWindowAndApplication:YES]; [self _updateTargetInfoForFrontMostApplication];
[self performAutotypeForEntry:nil];
} }
- (void)_performAutotypeUsingCurrentWindowAndApplication:(BOOL)useCurrentWindowAndApplication { - (void)performAutotypeForEntry:(KPKEntry *)entryOrNil {
if(useCurrentWindowAndApplication) {
[self _updateTargetApplicationAndWindow];
}
NSInteger pid = [[NSProcessInfo processInfo] processIdentifier]; NSInteger pid = [[NSProcessInfo processInfo] processIdentifier];
if(self.targetPID == pid) { if(self.targetPID == pid) {
return; // We do not perform Autotype on ourselves return; // We do not perform Autotype on ourselves
@@ -129,11 +129,16 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
MPDocument *document = [self _findAutotypeDocument]; MPDocument *document = [self _findAutotypeDocument];
if(!document) { if(!document) {
return; // nothing to do /* We do not have a document. This can be
a) there is none - nothing happens
b) there is at least one, but locked - we get called again after the document has been unlocked
*/
return;
} }
MPAutotypeContext *context = [self _autotypeContextInDocument:document forWindowTitle:self.targetWindowTitle]; MPAutotypeContext *context = [self _autotypeContextInDocument:document forWindowTitle:self.targetWindowTitle preferredEntry:entryOrNil];
if(useCurrentWindowAndApplication) { /* TODO: that's popping up if the mulit seleciton dialog goes up! */
if(!entryOrNil) {
NSImage *appIcon = [[NSApplication sharedApplication] applicationIconImage]; NSImage *appIcon = [[NSApplication sharedApplication] applicationIconImage];
NSString *label = context ? NSLocalizedString(@"AUTOTYPE_OVERLAY_SINGLE_MATCH", "") : NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_MATCH", ""); NSString *label = context ? NSLocalizedString(@"AUTOTYPE_OVERLAY_SINGLE_MATCH", "") : NSLocalizedString(@"AUTOTYPE_OVERLAY_NO_MATCH", "");
[[MPOverlayWindowController sharedController] displayOverlayImage:appIcon label:label atView:nil]; [[MPOverlayWindowController sharedController] displayOverlayImage:appIcon label:label atView:nil];
@@ -159,12 +164,12 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
return currentDocument; return currentDocument;
} }
- (MPAutotypeContext *)_autotypeContextInDocument:(MPDocument *)document forWindowTitle:(NSString *)windowTitle { - (MPAutotypeContext *)_autotypeContextInDocument:(MPDocument *)document forWindowTitle:(NSString *)windowTitle preferredEntry:(KPKEntry *)entry {
/* /*
Query the document to generate a autotype command list for the window title 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 We do not care where this came form, just get the autotype commands
*/ */
NSArray *autotypeCandidates = [document autotypContextsForWindowTitle:windowTitle]; NSArray *autotypeCandidates = [document autotypContextsForWindowTitle:windowTitle preferredEntry:entry];
NSUInteger candidates = [autotypeCandidates count]; NSUInteger candidates = [autotypeCandidates count];
if(candidates == 0) { if(candidates == 0) {
return nil; return nil;
@@ -180,13 +185,13 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
if(nil == context) { if(nil == context) {
return; // No context to work with return; // No context to work with
} }
if([self _orderApplicationToFront:self.targetPID]) {
/* Sleep a bit after the app was activated */
/* TODO - we can use a saver way and use a notification to chekc if the app actally was activated */
usleep(1 * NSEC_PER_MSEC);
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSArray *commands = [MPAutotypeCommand commandsForContext:context]; NSArray *commands = [MPAutotypeCommand commandsForContext:context];
if([MPAutotypeDaemon _orderApplicationToFront:self.targetPID]) {
/* Sleep a bit after the app was activated */
usleep(0.5 * NSEC_PER_MSEC);
}
for(MPAutotypeCommand *command in commands) { for(MPAutotypeCommand *command in commands) {
[command execute]; [command execute];
} }
@@ -218,9 +223,7 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
} }
} }
- (NSDictionary *)_frontMostApplicationInfoDict { - (NSDictionary *)_infoDictionaryForApplication:(NSRunningApplication *)application {
NSRunningApplication *frontApplication = [[NSWorkspace sharedWorkspace] frontmostApplication];
NSArray *currentWindows = CFBridgingRelease(CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID)); NSArray *currentWindows = CFBridgingRelease(CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID));
for(NSDictionary *windowDict in currentWindows) { for(NSDictionary *windowDict in currentWindows) {
NSString *windowTitle = windowDict[(NSString *)kCGWindowName]; NSString *windowTitle = windowDict[(NSString *)kCGWindowName];
@@ -228,7 +231,7 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
continue; continue;
} }
NSNumber *processId = windowDict[(NSString *)kCGWindowOwnerPID]; NSNumber *processId = windowDict[(NSString *)kCGWindowOwnerPID];
if(processId && [processId isEqualToNumber:@(frontApplication.processIdentifier)]) { if(processId && [processId isEqualToNumber:@(application.processIdentifier)]) {
return @{ return @{
kMPWindowTitleKey: windowDict[(NSString *)kCGWindowName], kMPWindowTitleKey: windowDict[(NSString *)kCGWindowName],
kMPProcessIdentifierKey : processId kMPProcessIdentifierKey : processId
@@ -265,28 +268,28 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
[self.matchSelectionButton setMenu:associationMenu]; [self.matchSelectionButton setMenu:associationMenu];
[self.matchSelectionWindow makeKeyAndOrderFront:self]; [self.matchSelectionWindow makeKeyAndOrderFront:self];
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
/* Setup Items in Popup */
} }
#pragma mark - #pragma mark -
#pragma mark MPDocument Notifications #pragma mark MPDocument Notifications
- (void)_didUnlockDatabase:(NSNotification *)notification { - (void)_didUnlockDatabase:(NSNotification *)notification {
/* Remove ourselves and call again to search matches */
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[self _performAutotypeUsingCurrentWindowAndApplication:NO]; [self performAutotypeForEntry:nil];
} }
#pragma mark - #pragma mark -
#pragma mark NSApplication Notifications #pragma mark NSApplication Notifications
- (void)_applicationWillBecomeActive:(NSNotification *)notification { - (void)_didDeactivateApplication:(NSNotification *)notification {
//[self _updateTargetApplicationAndWindow]; NSDictionary *userInfo = notification.userInfo;
//NSLog(@"_applicaiontWillBecomActive"); [self _updateTargeInformationForApplication:userInfo[NSWorkspaceApplicationKey]];
} }
#pragma mark - #pragma mark -
#pragma mark Application information #pragma mark Application information
+ (BOOL)_orderApplicationToFront:(pid_t)processIdentifier { - (BOOL)_orderApplicationToFront:(pid_t)processIdentifier {
NSRunningApplication *runingApplication = [NSRunningApplication runningApplicationWithProcessIdentifier:processIdentifier]; NSRunningApplication *runingApplication = [NSRunningApplication runningApplicationWithProcessIdentifier:processIdentifier];
NSRunningApplication *frontApplication = [[NSWorkspace sharedWorkspace] frontmostApplication]; NSRunningApplication *frontApplication = [[NSWorkspace sharedWorkspace] frontmostApplication];
if(frontApplication.processIdentifier == processIdentifier) { if(frontApplication.processIdentifier == processIdentifier) {
@@ -295,15 +298,20 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
[runingApplication activateWithOptions:0]; [runingApplication activateWithOptions:0];
return YES; return YES;
} }
- (void)_updateTargetInfoForFrontMostApplication {
[self _updateTargeInformationForApplication:[[NSWorkspace sharedWorkspace] frontmostApplication]];
}
- (void)_updateTargetApplicationAndWindow { - (void)_updateTargeInformationForApplication:(NSRunningApplication *)application {
/* if(!application) {
Determine the window title of the current front most application self.targetPID = -1;
Start searching the db for the best fit (based on title, then on window associations self.targetWindowTitle = @"";
*/ }
NSDictionary *frontApplicationInfoDict = [self _frontMostApplicationInfoDict]; else {
self.targetPID = [frontApplicationInfoDict[kMPProcessIdentifierKey] intValue]; NSDictionary *frontApplicationInfoDict = [self _infoDictionaryForApplication:application];
self.targetWindowTitle = frontApplicationInfoDict[kMPWindowTitleKey]; self.targetPID = [frontApplicationInfoDict[kMPProcessIdentifierKey] intValue];
self.targetWindowTitle = frontApplicationInfoDict[kMPWindowTitleKey];
}
} }
@end @end

View File

@@ -25,23 +25,25 @@
@interface MPDocument (Autotype) @interface MPDocument (Autotype)
/** /**
* Tests the given item for a possible wrong autotype format * Tests the given item for a possible wrong autotype format
* MacPass 0.4 and 0.4.1 did store wrong Autotype sequences and thus mangled database files * MacPass 0.4 and 0.4.1 did store wrong Autotype sequences and thus mangled database files
* *
* @param item Item to test for malformation. Allowed Items are KPKNode, KPKEntry, KPKGroup and KPKAutotype * @param item Item to test for malformation. Allowed Items are KPKNode, KPKEntry, KPKGroup and KPKAutotype
* *
* @return YES if the given item is considered a possible candidate. NO in all other cases * @return YES if the given item is considered a possible candidate. NO in all other cases
*/ */
+ (BOOL)isCandidateForMalformedAutotype:(id)item; + (BOOL)isCandidateForMalformedAutotype:(id)item;
/** /**
* Returns an NSArray containing all Autotype Contexts that match the given window title * Returns an NSArray containing all Autotype Contexts that match the given window title.
* If no entry is set, all entries in the document will be searched
* *
* @param windowTitle Window title to search matches for * @param windowTitle Window title to search matches for
* @param entry Entry to use for lookup. If nil lookup will be performed in complete document
* *
* @return NSArray of MPAutotypeContexts for the given window title * @return NSArray of MPAutotypeContext objects matching the window title.
*/ */
- (NSArray *)autotypContextsForWindowTitle:(NSString *)windowTitle; - (NSArray *)autotypContextsForWindowTitle:(NSString *)windowTitle preferredEntry:(KPKEntry *)entryOrNil;
/** /**
* Checks if the document has malformed autotype items * Checks if the document has malformed autotype items
* *

View File

@@ -46,11 +46,11 @@
return (NSOrderedSame == [@"{TAB}{USERNAME}{TAB}{PASSWORD}{ENTER}" compare:keystrokeSequence options:NSCaseInsensitiveSearch]); return (NSOrderedSame == [@"{TAB}{USERNAME}{TAB}{PASSWORD}{ENTER}" compare:keystrokeSequence options:NSCaseInsensitiveSearch]);
} }
- (NSArray *)autotypContextsForWindowTitle:(NSString *)windowTitle { - (NSArray *)autotypContextsForWindowTitle:(NSString *)windowTitle preferredEntry:(KPKEntry *)entry {
if(!windowTitle) { if(!windowTitle) {
return nil; return nil;
} }
NSArray *autotypeEntries = [self.root autotypeableChildEntries]; NSArray *autotypeEntries = entry ? [[NSArray alloc] initWithObjects:entry, nil] : [self.root autotypeableChildEntries];
NSMutableArray *contexts = [[NSMutableArray alloc] initWithCapacity:MAX(1,ceil([autotypeEntries count] / 4.0))]; NSMutableArray *contexts = [[NSMutableArray alloc] initWithCapacity:MAX(1,ceil([autotypeEntries count] / 4.0))];
for(KPKEntry *entry in autotypeEntries) { for(KPKEntry *entry in autotypeEntries) {
/* TODO: /* TODO:

View File

@@ -50,6 +50,8 @@
- (IBAction)pickExpiryDate:(id)sender; - (IBAction)pickExpiryDate:(id)sender;
- (IBAction)performAutotypeForEntry:(id)sender;
#pragma mark Helper #pragma mark Helper
- (IBAction)fixAutotype:(id)sender; - (IBAction)fixAutotype:(id)sender;

View File

@@ -7,25 +7,26 @@
// //
#import "MPDocumentWindowController.h" #import "MPDocumentWindowController.h"
#import "MPDocument.h"
#import "MPPasswordInputController.h"
#import "MPEntryViewController.h"
#import "MPToolbarDelegate.h"
#import "MPOutlineViewController.h"
#import "MPInspectorViewController.h"
#import "MPAppDelegate.h"
#import "MPActionHelper.h" #import "MPActionHelper.h"
#import "MPDatabaseSettingsWindowController.h" #import "MPAppDelegate.h"
#import "MPPasswordEditWindowController.h" #import "MPAutotypeDaemon.h"
#import "MPConstants.h" #import "MPConstants.h"
#import "MPSettingsHelper.h"
#import "MPDocumentWindowDelegate.h"
#import "MPFixAutotypeWindowController.h"
#import "MPContextToolbarButton.h" #import "MPContextToolbarButton.h"
#import "KPKTree.h" #import "MPDatabaseSettingsWindowController.h"
#import "KPKEntry.h" #import "MPDocument.h"
#import "MPDocumentWindowDelegate.h"
#import "MPEntryViewController.h"
#import "MPFixAutotypeWindowController.h"
#import "MPInspectorViewController.h"
#import "MPOutlineViewController.h"
#import "MPPasswordEditWindowController.h"
#import "MPPasswordInputController.h"
#import "MPSettingsHelper.h"
#import "MPToolbarDelegate.h"
#import "KPKCompositeKey.h" #import "KPKCompositeKey.h"
#import "KPKEntry.h"
#import "KPKTree.h"
typedef NS_ENUM(NSUInteger, MPAlertContext) { typedef NS_ENUM(NSUInteger, MPAlertContext) {
MPAlertLossySaveWarning, MPAlertLossySaveWarning,
@@ -369,6 +370,13 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
[[NSUserDefaults standardUserDefaults] setBool:!inspectorWasVisible forKey:kMPSettingsKeyShowInspector]; [[NSUserDefaults standardUserDefaults] setBool:!inspectorWasVisible forKey:kMPSettingsKeyShowInspector];
} }
- (void)performAutotypeForEntry:(id)sender {
id<MPTargetNodeResolving> entryResolver = [NSApp targetForAction:@selector(currentTargetEntry)];
KPKEntry *targetEntry = [entryResolver currentTargetEntry];
MPAutotypeDaemon *autotyped = ((MPAppDelegate *)[NSApplication sharedApplication]).autotypeDaemon;
[autotyped performAutotypeForEntry:targetEntry];
}
- (void)showInspector:(id)sender { - (void)showInspector:(id)sender {
if(![self _isInspectorVisible]) { if(![self _isInspectorVisible]) {
[self toggleInspector:sender]; [self toggleInspector:sender];