mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-23 04:19:32 +00:00
Autotype fix dialog now only shows candiates.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
#import "MPDocument+Autotype.h"
|
||||
#import "MPAutotypeContext.h"
|
||||
#import "MPAutotypeHelper.h"
|
||||
|
||||
#import "KPKGroup.h"
|
||||
#import "KPKEntry.h"
|
||||
@@ -30,6 +31,22 @@
|
||||
|
||||
@implementation MPDocument (Autotype)
|
||||
|
||||
+ (BOOL)isCandidateForMalformedAutotype:(id)item {
|
||||
|
||||
NSString *keystrokeSequence;
|
||||
if([item isKindOfClass:[KPKEntry class]] && ![((KPKEntry *)item).autotype hasDefaultKeystrokeSequence]) {
|
||||
keystrokeSequence = ((KPKEntry *)item).autotype.defaultKeystrokeSequence;
|
||||
}
|
||||
else if( [item isKindOfClass:[KPKGroup class]] && ![item hasDefaultAutotypeSequence]) {
|
||||
keystrokeSequence = ((KPKGroup *)item).defaultAutoTypeSequence;
|
||||
}
|
||||
else if( [item isKindOfClass:[KPKWindowAssociation class]] && ![item hasDefaultKeystrokeSequence]){
|
||||
keystrokeSequence = ((KPKWindowAssociation *)item).keystrokeSequence;
|
||||
}
|
||||
/* if nothing is true, keystrokeSequence is nil an hence return is NO */
|
||||
return (NSOrderedSame == [@"{TAB}{USERNAME}{TAB}{PASSWORD}{ENTER}" compare:keystrokeSequence options:NSCaseInsensitiveSearch]);
|
||||
}
|
||||
|
||||
- (NSArray *)autotypContextsForWindowTitle:(NSString *)windowTitle {
|
||||
if(!windowTitle) {
|
||||
return nil;
|
||||
@@ -59,4 +76,29 @@
|
||||
return contexts;
|
||||
}
|
||||
|
||||
- (BOOL)hasMalformedAutotypeItems {
|
||||
return [[self malformedAutotypeItems] count] > 0;
|
||||
}
|
||||
|
||||
- (NSArray *)malformedAutotypeItems {
|
||||
NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:1000];
|
||||
[self _flattenGroup:self.root toArray:items];
|
||||
NSPredicate *malformedPrediacte = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
|
||||
return [MPDocument isCandidateForMalformedAutotype:evaluatedObject];
|
||||
}];
|
||||
NSArray *malformedItems = [items filteredArrayUsingPredicate:malformedPrediacte];
|
||||
return malformedItems;
|
||||
}
|
||||
|
||||
- (void)_flattenGroup:(KPKGroup *)group toArray:(NSMutableArray *)array {
|
||||
[array addObject:group];
|
||||
for(KPKEntry *entry in group.entries) {
|
||||
[array addObject:entry];
|
||||
[array addObjectsFromArray:entry.autotype.associations];
|
||||
}
|
||||
for(KPKGroup *childGroup in group.groups) {
|
||||
[self _flattenGroup:childGroup toArray:array];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user