Extended Attribute View Controller to work for custom attributes

Added toggle password button
Added remove attribute button
This commit is contained in:
Michael Starke
2021-10-24 01:55:43 +02:00
parent fc186aaf2c
commit 299b48870d
4 changed files with 90 additions and 22 deletions

View File

@@ -20,7 +20,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface MPEntryAttributeViewController : NSViewController <MPInspectorEditor, HNHUITextFieldDelegate>
@property (strong) IBOutlet NSTextField *keyTextField;
@property (strong) IBOutlet HNHUITextField *valueTextField;
@property (strong) IBOutlet HNHUISecureTextField *valueTextField;
@property (strong) IBOutlet NSButton *toggleProtectedButton;
@property (strong) IBOutlet NSButton *removeButton;
- (void)updateValues;
- (void)updateEditing;

View File

@@ -38,11 +38,14 @@
}
- (void)viewDidLoad {
[super viewDidLoad];
NSString *placeHolder = NSLocalizedString(@"NONE", "Placeholder text for input fields if no entry or group is selected");
self.keyTextField.placeholderString = placeHolder;
self.valueTextField.placeholderString = placeHolder;
[super viewDidLoad];
self.toggleProtectedButton.action = @selector(toggleDisplay:);
self.toggleProtectedButton.target = self.valueTextField;
[self updateValues];
[self updateEditing];
@@ -136,6 +139,7 @@
self.view.hidden = (!self.isEditor && self.representedAttribute.value.length == 0);
self.keyTextField.stringValue = self.representedAttribute.key ? self.representedAttribute.key : @"";
self.valueTextField.stringValue = self.representedAttribute.value ? self.representedAttribute.value : @"";
self.valueTextField.showPassword = !self.representedAttribute.protect;
}
- (void)updateEditing {
@@ -143,6 +147,8 @@
self.valueTextField.editable = self.isEditor;
self.keyTextField.selectable = YES;
self.valueTextField.selectable = YES;
self.toggleProtectedButton.hidden = _isDefaultAttribute;
self.removeButton.hidden = !self.isEditor || (self.isEditor && !_isDefaultAttribute);
}
@end

View File

@@ -9,6 +9,8 @@
<customObject id="-2" userLabel="File's Owner" customClass="MPEntryAttributeViewController">
<connections>
<outlet property="keyTextField" destination="m8q-FN-S8D" id="HzJ-cd-ifA"/>
<outlet property="removeButton" destination="Nmx-gC-8rG" id="eRy-l0-u0E"/>
<outlet property="toggleProtectedButton" destination="hAk-oD-dCj" id="js9-Hx-ycS"/>
<outlet property="valueTextField" destination="HZM-H4-dB4" id="56C-eA-J7G"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
@@ -30,17 +32,46 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="249" verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HZM-H4-dB4" customClass="HNHUITextField">
<stackView distribution="fill" orientation="horizontal" alignment="top" spacing="5" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="LBt-0e-cUK">
<rect key="frame" x="0.0" y="0.0" width="251" height="21"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" truncatesLastVisibleLine="YES" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="sO3-xr-VwO">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<outlet property="delegate" destination="-2" id="Dm6-8t-HmN"/>
</connections>
</textField>
<subviews>
<textField horizontalHuggingPriority="249" verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HZM-H4-dB4" customClass="HNHUISecureTextField">
<rect key="frame" x="0.0" y="0.0" width="181" height="21"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" truncatesLastVisibleLine="YES" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="sO3-xr-VwO">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<outlet property="delegate" destination="-2" id="Dm6-8t-HmN"/>
</connections>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="hAk-oD-dCj">
<rect key="frame" x="179" y="-6" width="44" height="32"/>
<buttonCell key="cell" type="push" bezelStyle="rounded" image="NSLockLockedTemplate" imagePosition="only" alignment="center" alternateImage="NSLockUnlockedTemplate" lineBreakMode="truncatingTail" borderStyle="border" inset="2" id="f80-K9-DO7">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Nmx-gC-8rG">
<rect key="frame" x="214" y="-6" width="44" height="32"/>
<buttonCell key="cell" type="push" bezelStyle="rounded" image="NSRemoveTemplate" imagePosition="only" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="179-uk-89S">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
@@ -58,7 +89,12 @@
<constraint firstAttribute="bottom" secondItem="No7-P9-4cl" secondAttribute="bottom" id="MX2-as-4EI"/>
<constraint firstItem="No7-P9-4cl" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="mbE-gq-jDF"/>
</constraints>
<point key="canvasLocation" x="108" y="202"/>
<point key="canvasLocation" x="-434.5" y="134"/>
</customView>
</objects>
<resources>
<image name="NSLockLockedTemplate" width="14" height="15"/>
<image name="NSLockUnlockedTemplate" width="17" height="15"/>
<image name="NSRemoveTemplate" width="14" height="4"/>
</resources>
</document>

View File

@@ -34,6 +34,7 @@
#import "MPTOTPViewController.h"
#import "MPTOTPSetupViewController.h"
#import "MPEntryAttributeViewController.h"
#import "MPNodeExpirationViewController.h"
#import "MPPrettyPasswordTransformer.h"
#import "NSString+MPPasswordCreation.h"
@@ -60,6 +61,18 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
MPEntryTabAutotype
};
typedef NS_ENUM(NSUInteger, MPInpspectorEditorIndex) {
//MPInpspectorEditorIndexImageEditor,
//MPInpspectorEditorIndexTitle,
MPInpspectorEditorIndexUsername,
MPInpspectorEditorIndexPassword,
MPInpspectorEditorIndexURL,
MPInpspectorEditorIndexExpires,
MPInpspectorEditorIndexTags,
MPInpspectorEditorIndexDefaultCount
};
@interface NSObject (MPAppKitPrivateAPI)
- (void)_searchWithGoogleFromMenu:(id)obj;
@end
@@ -76,7 +89,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
MPWindowTitleComboBoxDelegate *_windowTitleMenuDelegate;
MPTagsTokenFieldDelegate *_tagTokenFieldDelegate;
MPAddCustomFieldContextMenuDelegate *_addCustomFieldContextMenuDelegate;
NSMutableArray<MPEntryAttributeViewController *> *_attributeEditorViewControllers;
NSMutableArray<NSViewController<MPInspectorEditor> *> *_attributeEditorViewControllers;
}
@property (nonatomic, assign) BOOL showPassword;
@@ -134,7 +147,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
super.representedObject = representedObject;
self.totpViewController.representedObject = self.representedObject;
//[self _updateAttributeEditors];
[self _updateEditors];
/* only register for a single entry! */
if(self.representedEntry) {
@@ -202,8 +215,8 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
[self _setupTOPTView];
//[self _setupAttributeEditors];
//[self _updateAttributeEditors];
[self _setupAttributeEditors];
[self _updateEditors];
[self _setupCustomFieldsButton];
[self _setupViewBindings];
@@ -617,19 +630,30 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
}
- (void)_setupAttributeEditors {
/*
MPNodeExpirationViewController *vc = [[MPNodeExpirationViewController alloc] init];
vc.isEditor = NO;
[_attributeEditorViewControllers addObject:vc];
[self.fieldsStackView addArrangedSubview:vc.view];
*/
MPEntryAttributeViewController *vc = [[MPEntryAttributeViewController alloc] init];
vc.isEditor = NO;
[_attributeEditorViewControllers addObject:vc];
[self.fieldsStackView addArrangedSubview:vc.view];
/*
for(NSUInteger index = 0; index < kKPKDefaultEntryKeysCount; index++) {
MPEntryAttributeViewController *vc = [[MPEntryAttributeViewController alloc] init];
vc.isEditor = NO;
[_attributeEditorViewControllers addObject:vc];
[self.fieldsStackView addArrangedSubview:vc.view];
}
*/
}
- (void)_updateAttributeEditors {
_attributeEditorViewControllers[0].representedObject = [self.representedEntry attributeWithKey:kKPKTitleKey];
_attributeEditorViewControllers[1].representedObject = [self.representedEntry attributeWithKey:kKPKUsernameKey];
_attributeEditorViewControllers[2].representedObject = [self.representedEntry attributeWithKey:kKPKPasswordKey];
_attributeEditorViewControllers[3].representedObject = [self.representedEntry attributeWithKey:kKPKURLKey];
- (void)_updateEditors {
_attributeEditorViewControllers[MPInpspectorEditorIndexUsername].representedObject = [self.representedEntry attributeWithKey:kKPKUsernameKey];
}
- (void)_setupTOPTView {