mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 14:02:28 +00:00
Testing support for custom attributes in autotype builder
This commit is contained in:
@@ -1,32 +1,44 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<deployment identifier="macosx"/>
|
<deployment identifier="macosx"/>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12120"/>
|
||||||
|
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<objects>
|
<objects>
|
||||||
<customObject id="-2" userLabel="File's Owner" customClass="MPAutotypeBuilderViewController">
|
<customObject id="-2" userLabel="File's Owner" customClass="MPAutotypeBuilderViewController">
|
||||||
<connections>
|
<connections>
|
||||||
<outlet property="tokenField" destination="k06-gn-ahB" id="YKa-O1-bpM"/>
|
<outlet property="availableCommandsTokenField" destination="k06-gn-ahB" id="JKc-6C-BYh"/>
|
||||||
|
<outlet property="commandBuilderTokenField" destination="Jzn-UC-Ok8" id="sA3-3j-bMi"/>
|
||||||
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
|
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
|
||||||
</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" customClass="NSObject"/>
|
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||||
<customView id="Hz6-mo-xeY">
|
<customView id="Hz6-mo-xeY">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="405" height="298"/>
|
<rect key="frame" x="0.0" y="0.0" width="405" height="333"/>
|
||||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<tokenField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="k06-gn-ahB">
|
<tokenField verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="k06-gn-ahB">
|
||||||
<rect key="frame" x="20" y="15" width="365" height="268"/>
|
<rect key="frame" x="20" y="50" width="365" height="268"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
<tokenFieldCell key="cell" selectable="YES" editable="YES" borderStyle="bezel" alignment="left" drawsBackground="YES" allowsEditingTextAttributes="YES" id="mfe-Zs-cxC">
|
<tokenFieldCell key="cell" selectable="YES" editable="YES" borderStyle="bezel" alignment="left" drawsBackground="YES" allowsEditingTextAttributes="YES" id="mfe-Zs-cxC">
|
||||||
<font key="font" metaFont="cellTitle"/>
|
<font key="font" metaFont="cellTitle"/>
|
||||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||||
</tokenFieldCell>
|
</tokenFieldCell>
|
||||||
</tokenField>
|
</tokenField>
|
||||||
|
<tokenField verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Jzn-UC-Ok8">
|
||||||
|
<rect key="frame" x="20" y="20" width="365" height="22"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
|
<tokenFieldCell key="cell" selectable="YES" editable="YES" borderStyle="bezel" alignment="left" drawsBackground="YES" allowsEditingTextAttributes="YES" id="uy0-iq-Q8N">
|
||||||
|
<font key="font" metaFont="system"/>
|
||||||
|
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||||
|
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||||
|
</tokenFieldCell>
|
||||||
|
</tokenField>
|
||||||
</subviews>
|
</subviews>
|
||||||
<point key="canvasLocation" x="344.5" y="200"/>
|
<point key="canvasLocation" x="66.5" y="-10.5"/>
|
||||||
</customView>
|
</customView>
|
||||||
</objects>
|
</objects>
|
||||||
</document>
|
</document>
|
||||||
|
|||||||
@@ -9,9 +9,11 @@
|
|||||||
#import "MPAutotypeBuilderViewController.h"
|
#import "MPAutotypeBuilderViewController.h"
|
||||||
#import <KeePassKit/KeePassKit.h>
|
#import <KeePassKit/KeePassKit.h>
|
||||||
|
|
||||||
@interface MPAutotypeBuilderViewController ()
|
@interface MPAutotypeBuilderViewController () <NSTokenFieldDelegate>
|
||||||
|
|
||||||
|
@property (weak) IBOutlet NSTokenField *availableCommandsTokenField;
|
||||||
|
@property (weak) IBOutlet NSTokenField *commandBuilderTokenField;
|
||||||
|
|
||||||
@property (weak) IBOutlet NSTokenField *tokenField;
|
|
||||||
@property (nonatomic, readonly, strong) NSArray<NSString *> *tokens;
|
@property (nonatomic, readonly, strong) NSArray<NSString *> *tokens;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -28,7 +30,7 @@
|
|||||||
for(NSString *attribute in [KPKFormat sharedFormat].entryDefaultKeys) {
|
for(NSString *attribute in [KPKFormat sharedFormat].entryDefaultKeys) {
|
||||||
[fields addObject:[NSString stringWithFormat:@"{%@}", attribute]];
|
[fields addObject:[NSString stringWithFormat:@"{%@}", attribute]];
|
||||||
}
|
}
|
||||||
|
[fields addObject:@"{S:Custom}"];
|
||||||
_tokens = [fields arrayByAddingObjectsFromArray:@[ _MPToken(kKPKAutotypeShortEnter, kKPKAutotypeEnter),
|
_tokens = [fields arrayByAddingObjectsFromArray:@[ _MPToken(kKPKAutotypeShortEnter, kKPKAutotypeEnter),
|
||||||
_MPToken(kKPKAutotypeShortAlt, kKPKAutotypeAlt),
|
_MPToken(kKPKAutotypeShortAlt, kKPKAutotypeAlt),
|
||||||
_MPToken(kKPKAutotypeShortControl, kKPKAutotypeControl),
|
_MPToken(kKPKAutotypeShortControl, kKPKAutotypeControl),
|
||||||
@@ -47,17 +49,55 @@
|
|||||||
|
|
||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
self.tokenField.editable = NO;
|
self.availableCommandsTokenField.editable = NO;
|
||||||
self.tokenField.objectValue = self.tokens;
|
self.availableCommandsTokenField.objectValue = self.tokens;
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_textViewDidChangeSelection:) name:NSTextViewDidChangeSelectionNotification object:nil];
|
self.availableCommandsTokenField.delegate = self;
|
||||||
|
self.commandBuilderTokenField.delegate = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_textViewDidChangeSelection:(NSNotification *)notification {
|
- (IBAction)addCustomKeyPlaceholder:(id)sender {
|
||||||
NSTextView *tv = [self.tokenField.cell fieldEditorForView:self.tokenField];
|
if(![sender isKindOfClass:NSMenuItem.class]) {
|
||||||
if(tv) {
|
return;
|
||||||
NSArray *selectionRanges = tv.selectedRanges;
|
|
||||||
}
|
}
|
||||||
|
NSMenuItem *item = sender;
|
||||||
|
NSArray *tokens = [self.commandBuilderTokenField.objectValue arrayByAddingObject:[NSString stringWithFormat:@"{S:%@}", item.title]];
|
||||||
|
self.commandBuilderTokenField.objectValue = tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSMenu *)tokenField:(NSTokenField *)tokenField menuForRepresentedObject:(id)representedObject {
|
||||||
|
if(tokenField == self.commandBuilderTokenField) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
if([[representedObject uppercaseString] hasPrefix:@"{S:"]) {
|
||||||
|
KPKEntry *entry = self.representedObject;
|
||||||
|
NSArray <KPKAttribute *> *customAttributes = entry.customAttributes;
|
||||||
|
if(customAttributes.count > 0 ) {
|
||||||
|
NSMenu *menu = [[NSMenu alloc] init];
|
||||||
|
for(KPKAttribute *attribute in customAttributes) {
|
||||||
|
[menu addItemWithTitle:attribute.key action:@selector(addCustomKeyPlaceholder:) keyEquivalent:@""];
|
||||||
|
}
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)tokenField:(NSTokenField *)tokenField hasMenuForRepresentedObject:(id)representedObject {
|
||||||
|
if(tokenField != self.availableCommandsTokenField) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
BOOL showMenu = ([[representedObject uppercaseString] hasPrefix:@"{S:"] && [self.representedObject customAttributes].count > 0);
|
||||||
|
return showMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSTokenStyle)tokenField:(NSTokenField *)tokenField styleForRepresentedObject:(id)representedObject {
|
||||||
|
if(tokenField == self.availableCommandsTokenField) {
|
||||||
|
return NSTokenStyleDefault;
|
||||||
|
}
|
||||||
|
if([representedObject hasPrefix:@"{"] || [representedObject hasSuffix:@"}"]) {
|
||||||
|
return NSTokenStyleDefault;
|
||||||
|
}
|
||||||
|
return NSTokenStyleNone;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -280,6 +280,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
|||||||
- (IBAction)showAutotypeBuilder:(id)sender {
|
- (IBAction)showAutotypeBuilder:(id)sender {
|
||||||
[sender setEnabled:NO];
|
[sender setEnabled:NO];
|
||||||
MPAutotypeBuilderViewController *autotypeBuilder = [[MPAutotypeBuilderViewController alloc] init];
|
MPAutotypeBuilderViewController *autotypeBuilder = [[MPAutotypeBuilderViewController alloc] init];
|
||||||
|
autotypeBuilder.representedObject = self.representedObject;
|
||||||
[self _showPopopver:autotypeBuilder atView:sender onEdge:NSMinYEdge];
|
[self _showPopopver:autotypeBuilder atView:sender onEdge:NSMinYEdge];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,7 +396,13 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
|||||||
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(tags))]
|
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(tags))]
|
||||||
options:nil];
|
options:nil];
|
||||||
|
|
||||||
NSArray *inputs = @[ self.titleTextField, self.passwordTextField, self.usernameTextField, self.URLTextField, self.expiresCheckButton , self.tagsTokenField, self.generatePasswordButton];
|
NSArray *inputs = @[self.titleTextField,
|
||||||
|
self.passwordTextField,
|
||||||
|
self.usernameTextField,
|
||||||
|
self.URLTextField,
|
||||||
|
self.expiresCheckButton,
|
||||||
|
self.tagsTokenField,
|
||||||
|
self.generatePasswordButton];
|
||||||
|
|
||||||
for(NSControl *control in inputs) {
|
for(NSControl *control in inputs) {
|
||||||
NSString *keyPath = [NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(isHistory))];
|
NSString *keyPath = [NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(isHistory))];
|
||||||
|
|||||||
Reference in New Issue
Block a user