From 299b48870d5a363449300a5cad7f0065e8d49c51 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Sun, 24 Oct 2021 01:55:43 +0200 Subject: [PATCH] Extended Attribute View Controller to work for custom attributes Added toggle password button Added remove attribute button --- MacPass/MPEntryAttributeViewController.h | 4 +- MacPass/MPEntryAttributeViewController.m | 8 ++- MacPass/MPEntryAttributeViewController.xib | 58 ++++++++++++++++++---- MacPass/MPEntryInspectorViewController.m | 42 ++++++++++++---- 4 files changed, 90 insertions(+), 22 deletions(-) diff --git a/MacPass/MPEntryAttributeViewController.h b/MacPass/MPEntryAttributeViewController.h index 2d99e70c..308f022e 100644 --- a/MacPass/MPEntryAttributeViewController.h +++ b/MacPass/MPEntryAttributeViewController.h @@ -20,7 +20,9 @@ NS_ASSUME_NONNULL_BEGIN @interface MPEntryAttributeViewController : NSViewController @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; diff --git a/MacPass/MPEntryAttributeViewController.m b/MacPass/MPEntryAttributeViewController.m index 42110e77..fc92bcd9 100644 --- a/MacPass/MPEntryAttributeViewController.m +++ b/MacPass/MPEntryAttributeViewController.m @@ -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 diff --git a/MacPass/MPEntryAttributeViewController.xib b/MacPass/MPEntryAttributeViewController.xib index fcec34be..63718095 100644 --- a/MacPass/MPEntryAttributeViewController.xib +++ b/MacPass/MPEntryAttributeViewController.xib @@ -9,6 +9,8 @@ + + @@ -30,17 +32,46 @@ - + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -58,7 +89,12 @@ - + + + + + + diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index 6e487150..26f3f465 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -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 *_attributeEditorViewControllers; + NSMutableArray *> *_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 {