Started creation of Autotype out of normalized command strings

This commit is contained in:
michael starke
2014-02-19 19:45:00 +01:00
parent 24d0c3a6ee
commit 7f16310a4d
8 changed files with 69 additions and 16 deletions

View File

@@ -9,12 +9,13 @@
<connections> <connections>
<outlet property="matchSelectionButton" destination="tAw-72-pSm" id="2a0-3C-UUB"/> <outlet property="matchSelectionButton" destination="tAw-72-pSm" id="2a0-3C-UUB"/>
<outlet property="matchSelectionWindow" destination="1" id="ZYa-oC-Nfs"/> <outlet property="matchSelectionWindow" destination="1" id="ZYa-oC-Nfs"/>
<outlet property="performAutotypeButton" destination="Jlm-i9-jVy" id="Qjk-sL-Yqk"/>
</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"/>
<window title="Autotype Selection" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" wantsToBeColor="NO" visibleAtLaunch="NO" animationBehavior="default" id="1"> <window title="Autotype Selection" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" releasedWhenClosed="NO" wantsToBeColor="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="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"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1418"/> <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1418"/>
<view key="contentView" id="2"> <view key="contentView" id="2">
@@ -43,12 +44,12 @@ Gw
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
</buttonCell> </buttonCell>
</button> </button>
<popUpButton verticalHuggingPriority="750" 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"/> <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="system"/> <font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="7RT-wh-F0R"> <menu key="menu" title="OtherViews" id="7RT-wh-F0R">
<items> <items>
<menuItem title="Item 3" id="HzV-Dh-6B9"/> <menuItem title="Item 3" id="HzV-Dh-6B9"/>

View File

@@ -7,17 +7,32 @@
// //
#import "MPAutotypeCommand.h" #import "MPAutotypeCommand.h"
#import "NSString+Commands.h"
#import "MPAutotypeContext.h"
#import "MPKeyMapper.h" #import "MPKeyMapper.h"
#import "NSString+Commands.h"
#import <Carbon/Carbon.h> #import <Carbon/Carbon.h>
@implementation MPAutotypeCommand @implementation MPAutotypeCommand
+ (NSArray *)commandsForContext:(MPAutotypeContext *)context { + (NSArray *)commandsForContext:(MPAutotypeContext *)context {
NSError *error; if([context isValid]) {
NSRegularExpression *regularExpression = [[NSRegularExpression alloc] initWithPattern:@"" options:0 error:&error]; 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; return nil;
} }

View File

@@ -22,9 +22,10 @@
*/ */
@property (nonatomic, strong) KPKEntry *entry; @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 *command;
@property (nonatomic, copy) NSString *normalizedCommand;
/** /**
* Designated initializer * Designated initializer
@@ -37,5 +38,11 @@
- (instancetype)initWithEntry:(KPKEntry *)entry andSequence:(NSString *)sequence; - (instancetype)initWithEntry:(KPKEntry *)entry andSequence:(NSString *)sequence;
- (instancetype)initWithDefaultSequenceForEntry:(KPKEntry *)entry; - (instancetype)initWithDefaultSequenceForEntry:(KPKEntry *)entry;
- (instancetype)initWithWindowAssociation:(KPKWindowAssociation *)association; - (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 @end

View File

@@ -28,8 +28,9 @@
- (instancetype)initWithEntry:(KPKEntry *)entry andSequence:(NSString *)sequence { - (instancetype)initWithEntry:(KPKEntry *)entry andSequence:(NSString *)sequence {
self = [super init]; self = [super init];
if(self) { if(self) {
_command = [[sequence normalizedAutotypeSequence] copy]; _command = [sequence copy];
_entry = entry; _entry = entry;
_normalizedCommand = [[sequence normalizedAutotypeSequence] copy];
} }
return self; return self;
} }
@@ -39,4 +40,8 @@
return copy; return copy;
} }
- (BOOL)isValid {
return (self.normalizedCommand != nil);
}
@end @end

View File

@@ -7,15 +7,19 @@
// //
#import "MPAutotypeDaemon.h" #import "MPAutotypeDaemon.h"
#import "DDHotKeyCenter.h"
#import "MPPasteBoardController.h"
#import "MPDocument.h" #import "MPDocument.h"
#import "MPDocument+Autotype.h" #import "MPDocument+Autotype.h"
#import "MPAutotypeCommand.h" #import "MPAutotypeCommand.h"
#import "MPAutotypeContext.h"
#import "MPPasteBoardController.h"
#import "MPSettingsHelper.h" #import "MPSettingsHelper.h"
#import "KPKEntry.h" #import "KPKEntry.h"
#import "DDHotKeyCenter.h"
#import <Carbon/Carbon.h> #import <Carbon/Carbon.h>
NSString *const kMPWindowTitleKey = @"windowTitle"; NSString *const kMPWindowTitleKey = @"windowTitle";
@@ -33,11 +37,18 @@ NSString *const kMPApplciationNameKey = @"applicationName";
self = [super init]; self = [super init];
if (self) { if (self) {
_enabled = NO; _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; return self;
} }
- (void)dealloc {
[self unbind:@"enabled"];
}
#pragma mark Properties #pragma mark Properties
- (void)setEnabled:(BOOL)enabled { - (void)setEnabled:(BOOL)enabled {
if(_enabled != enabled) { if(_enabled != enabled) {
@@ -53,6 +64,8 @@ NSString *const kMPApplciationNameKey = @"applicationName";
- (void)executeAutotypeWithSelectedMatch:(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];
} }
- (void)_didPressHotKey { - (void)_didPressHotKey {
@@ -86,7 +99,7 @@ NSString *const kMPApplciationNameKey = @"applicationName";
return; // No Entries found. return; // No Entries found.
} }
if(candiates > 1) { if(candiates > 1) {
[self _presentSelectionWindow]; [self _presentSelectionWindow:autotypeCandidates];
return; // Nothing to do, we get called back by the window 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! */ /* 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; return nil;
} }
- (void)_presentSelectionWindow { - (void)_presentSelectionWindow:(NSArray *)candidates {
if(!self.matchSelectionWindow) { if(!self.matchSelectionWindow) {
[[NSBundle mainBundle] loadNibNamed:@"AutotypeCandidateSelectionWindow" owner:self topLevelObjects:nil]; [[NSBundle mainBundle] loadNibNamed:@"AutotypeCandidateSelectionWindow" owner:self topLevelObjects:nil];
[self.performAutotypeButton setTarget:self]; [self.performAutotypeButton setTarget:self];
[self.performAutotypeButton setAction:@selector(executeAutotypeWithSelectedMatch:)]; [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]; [self.matchSelectionWindow makeKeyAndOrderFront:self];
/* Setup Items in Popup */ /* Setup Items in Popup */
} }

View File

@@ -48,7 +48,7 @@
KPKWindowAssociation *association = [entry.autotype windowAssociationMatchingWindowTitle:windowTitle]; KPKWindowAssociation *association = [entry.autotype windowAssociationMatchingWindowTitle:windowTitle];
context = [[MPAutotypeContext alloc] initWithWindowAssociation:association]; context = [[MPAutotypeContext alloc] initWithWindowAssociation:association];
} }
if(context) { if([context isValid]) {
[contexts addObject:context]; [contexts addObject:context];
} }
} }

Binary file not shown.