diff --git a/MacPass/MPEntryAttributeViewController.h b/MacPass/MPEntryAttributeViewController.h index b59714f2..bb342305 100644 --- a/MacPass/MPEntryAttributeViewController.h +++ b/MacPass/MPEntryAttributeViewController.h @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN @property (strong) IBOutlet NSButton *actionButton; - (void)updateValuesAndEditing; - +- (void)performCopyForText:(NSString *)text; @end diff --git a/MacPass/MPEntryAttributeViewController.m b/MacPass/MPEntryAttributeViewController.m index 0bd5b1e8..fc76ee21 100644 --- a/MacPass/MPEntryAttributeViewController.m +++ b/MacPass/MPEntryAttributeViewController.m @@ -46,7 +46,7 @@ NSString *nameForDefaultKey(NSString *key) { - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; - // set editor to false? + _isEditor = NO; return self; } @@ -66,6 +66,7 @@ NSString *nameForDefaultKey(NSString *key) { self.actionButton.action = @selector(_copyText:); self.actionButton.target = self; self.actionButton.hidden = YES; + self.actionButton.title = NSLocalizedString(@"COPY", "Button title for copying an attribute value"); [self updateValuesAndEditing]; } @@ -84,15 +85,10 @@ NSString *nameForDefaultKey(NSString *key) { - (void)setRepresentedObject:(id)representedObject { if(self.representedAttribute) { - [NSNotificationCenter.defaultCenter removeObserver:self name:KPKWillChangeAttributeNotification object:self.representedObject]; [NSNotificationCenter.defaultCenter removeObserver:self name:KPKDidChangeAttributeNotification object:self.representedObject]; } super.representedObject = representedObject; if(self.representedAttribute) { - [NSNotificationCenter.defaultCenter addObserver:self - selector:(@selector(_willChangeAttribute:)) - name:KPKWillChangeAttributeNotification - object:self.representedAttribute]; [NSNotificationCenter.defaultCenter addObserver:self selector:(@selector(_didChangeAttribute:)) name:KPKDidChangeAttributeNotification @@ -104,10 +100,7 @@ NSString *nameForDefaultKey(NSString *key) { } - (void)_copyText:(id)sender { - NSText *text = [self.view.window fieldEditor:NO forObject:self.valueTextField]; - if([text isKindOfClass:NSTextView.class]) { - [self textField:self.valueTextField textView:(NSTextView *)text performAction:@selector(copy:)]; - } + [self performCopyForText:self.valueTextField.stringValue]; } - (BOOL)textField:(NSTextField *)textField textView:(NSTextView *)textView performAction:(SEL)action { @@ -116,7 +109,7 @@ NSString *nameForDefaultKey(NSString *key) { } // Only copy action - MPPasteboardOverlayInfoType info = MPPasteboardOverlayInfoCustom; + NSMutableString *selectedValue = [[NSMutableString alloc] init]; for(NSValue *rangeValue in textView.selectedRanges) { [selectedValue appendString:[textView.string substringWithRange:rangeValue.rangeValue]]; @@ -124,7 +117,15 @@ NSString *nameForDefaultKey(NSString *key) { if(selectedValue.length == 0) { [selectedValue setString:textField.stringValue]; } + [self performCopyForText:selectedValue]; + return NO; +} + +- (void)performCopyForText:(NSString *)text { + + MPPasteboardOverlayInfoType info = MPPasteboardOverlayInfoCustom; NSString *name = @""; + if([self.representedAttribute.key isEqual:kKPKUsernameKey]) { info = MPPasteboardOverlayInfoUsername; } @@ -140,13 +141,7 @@ NSString *nameForDefaultKey(NSString *key) { else { name = self.representedAttribute.key; } - [MPPasteBoardController.defaultController copyObject:selectedValue overlayInfo:info name:name atView:self.view]; - return NO; -} - - -- (void)_willChangeAttribute:(NSNotification *)notification { - // nothing to d + [MPPasteBoardController.defaultController copyObject:text overlayInfo:info name:name atView:self.view]; } - (void)_didChangeAttribute:(NSNotification *)notification { @@ -203,30 +198,5 @@ NSString *nameForDefaultKey(NSString *key) { self.representedAttribute.value = self.valueTextField.stringValue; } -- (void)objectDidBeginEditing:(id)editor { - NSLog(@"%@: %@", NSStringFromClass(self.class), NSStringFromSelector(_cmd)); - [super objectDidBeginEditing:editor]; -} - -- (void)objectDidEndEditing:(id)editor { - NSLog(@"%@: %@", NSStringFromClass(self.class), NSStringFromSelector(_cmd)); - [super objectDidEndEditing:editor]; -} - -- (BOOL)commitEditing { - NSLog(@"%@: %@", NSStringFromClass(self.class), NSStringFromSelector(_cmd)); - return [super commitEditing]; -} - -- (BOOL)commitEditingAndReturnError:(NSError *__autoreleasing _Nullable *)error { - NSLog(@"%@: %@", NSStringFromClass(self.class), NSStringFromSelector(_cmd)); - return [super commitEditingAndReturnError:error]; -} - -- (void)commitEditingWithDelegate:(id)delegate didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo { - NSLog(@"%@: %@", NSStringFromClass(self.class), NSStringFromSelector(_cmd)); - [super commitEditingWithDelegate:delegate didCommitSelector:didCommitSelector contextInfo:contextInfo]; -} - @end diff --git a/MacPass/MPEntryPasswordAttributeViewController.m b/MacPass/MPEntryPasswordAttributeViewController.m index 0a789de3..4665fde3 100644 --- a/MacPass/MPEntryPasswordAttributeViewController.m +++ b/MacPass/MPEntryPasswordAttributeViewController.m @@ -27,14 +27,6 @@ self.togglePasswordButton.action = @selector(toggleDisplay:); self.togglePasswordButton.target = self.passwordTextField; - __weak MPEntryPasswordAttributeViewController *welf = self; - self.passwordTextField.buttonTitle = NSLocalizedString(@"COPY", "Button to copy the value of an Attribute"); - self.passwordTextField.buttonActionBlock = ^void(NSTextField *tf) { - NSText *text = [welf.view.window fieldEditor:NO forObject:welf.passwordTextField]; - if([text isKindOfClass:NSTextView.class]) { - [welf textField:welf.passwordTextField textView:(NSTextView *)text performAction:@selector(copy:)]; - } - }; } - (void)updateValuesAndEditing { diff --git a/MacPass/MPEntryPasswordAttributeViewController.xib b/MacPass/MPEntryPasswordAttributeViewController.xib index 76d585c5..2e017164 100644 --- a/MacPass/MPEntryPasswordAttributeViewController.xib +++ b/MacPass/MPEntryPasswordAttributeViewController.xib @@ -8,6 +8,7 @@ + @@ -17,7 +18,7 @@ - + @@ -36,7 +37,7 @@ - + @@ -51,7 +52,7 @@ + + +