Added copy action to TOTP editor. Fixes #1186

This commit is contained in:
Michael Starke 2021-11-02 14:57:09 +01:00
parent 2e46d7c121
commit 65f2582e3c
6 changed files with 25 additions and 9 deletions

View File

@ -1,4 +1,4 @@
github "sparkle-project/Sparkle" ~> 1.22
github "MacPass/TransformerKit" "a8b5bb73cc327ec6798569b865c32fec5eb2289f"
github "MacPass/KeePassKit" "35da75901b293a53b44b1d0fe9d8fb312a4a7602"
github "mstarke/HNHUi" ~> 5.0
github "mstarke/HNHUi" ~> 6.0

View File

@ -1,5 +1,5 @@
github "MacPass/KeePassKit" "35da75901b293a53b44b1d0fe9d8fb312a4a7602"
github "MacPass/KissXML" "933f04fe5ad95c2be07ec0c2f801e140007f20fa"
github "MacPass/TransformerKit" "a8b5bb73cc327ec6798569b865c32fec5eb2289f"
github "mstarke/HNHUi" "5.0"
github "mstarke/HNHUi" "6.0"
github "sparkle-project/Sparkle" "1.24.0"

View File

@ -50,7 +50,8 @@
[self updateEditing];
__weak MPEntryAttributeViewController *welf = self;
self.valueTextField.copyActionBlock = ^void(NSTextField *tf) {
self.valueTextField.buttonTitle = NSLocalizedString(@"COPY", "Button to copy the value of an Attribute");
self.valueTextField.buttonActionBlock = ^void(NSTextField *tf) {
NSText *text = [welf.view.window fieldEditor:NO forObject:welf.valueTextField];
if([text isKindOfClass:NSTextView.class]) {
[welf textField:welf.valueTextField textView:(NSTextView *)text performAction:@selector(copy:)];
@ -103,7 +104,7 @@
[selectedValue appendString:[textView.string substringWithRange:rangeValue.rangeValue]];
}
if(selectedValue.length == 0) {
[selectedValue setString:textView.string];
[selectedValue setString:textField.stringValue];
}
NSString *name = @"";
if([self.representedAttribute.key isEqual:kKPKUsernameKey]) {

View File

@ -22,6 +22,14 @@
- (void)viewDidLoad {
self.remainingTimeButton.title = @"";
self.toptValueTextField.buttonTitle = NSLocalizedString(@"COPY", @"Copy the TOTP value to the clipboard");
__weak MPTOTPViewController *welf = self;
self.toptValueTextField.buttonActionBlock = (^void(NSTextField *tf) {
NSText *text = [welf.view.window fieldEditor:NO forObject:welf.toptValueTextField];
if([text isKindOfClass:NSTextView.class]) {
[welf textField:welf.toptValueTextField textView:(NSTextView *)text performAction:@selector(copy:)];
}
});
}
- (IBAction)showOTPSetup:(id)sender {
@ -53,10 +61,10 @@
for(NSValue *rangeValue in textView.selectedRanges) {
[selectedValue appendString:[textView.string substringWithRange:rangeValue.rangeValue]];
}
NSString *name = NSLocalizedString(@"TOTP", "Field TOTP was copied to the pasteboard");
if(selectedValue.length == 0) {
return YES;
[selectedValue setString:textField.stringValue];
}
NSString *name = NSLocalizedString(@"TOTP", "Field TOTP was copied to the pasteboard");
[MPPasteBoardController.defaultController copyObject:selectedValue overlayInfo:info name:name atView:self.view];
return NO;
}

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="18122" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="19455" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19455"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@ -36,7 +36,7 @@
<subviews>
<textField horizontalHuggingPriority="249" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xBL-Jz-VQO" customClass="HNHUITextField">
<rect key="frame" x="0.0" y="0.0" width="406" height="21"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" truncatesLastVisibleLine="YES" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="Vuy-HC-UhI">
<textFieldCell key="cell" lineBreakMode="truncatingTail" truncatesLastVisibleLine="YES" selectable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="Vuy-HC-UhI">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>

View File

@ -210,6 +210,10 @@
/* Context menu that copies reference to username */
"COPIED_USERNAME_REFERENCE" = "Reference to username copied!";
/* Button to copy the value of an Attribute
Copy the TOTP value to the clipboard */
"COPY" = "Copy";
/* Submenu to copy attributes as reference */
"COPY_AS_REFERENCE" = "Copy Reference To…";
@ -758,6 +762,9 @@
/* Toolbar item to perform autotype */
"TOOLBAR_PERFORM_AUTOTYPE_FOR_ENTRY" = "Autotype";
/* Field TOTP was copied to the pasteboard */
"TOTP" = "TOTP";
/* Time in seconds remaining for a valid TOTP string, format should be %ld */
"TOTP_REMAINING_TIME_%ld_SECONDS" = "%ld s";