Skip to content

Commit

Permalink
added double-click copy action to TOTP column
Browse files Browse the repository at this point in the history
we no longer copy empty stuff to the pasteboard on double-click
  • Loading branch information
mstarke committed Nov 23, 2022
1 parent 05ba068 commit 29756c0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions MacPass/MPEntryViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef NS_ENUM(NSUInteger, MPDisplayMode) {
- (IBAction)copyPassword:(id)sender;
- (IBAction)copyCustomAttribute:(id)sender;
- (IBAction)copyURL:(id)sender;
- (IBAction)copyTOTP:(id)sender;
- (IBAction)openURL:(id)sender;
- (IBAction)copyAsReference:(id)sender;

Expand Down
21 changes: 16 additions & 5 deletions MacPass/MPEntryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ - (void)_updateTOTPTimer {
}
__weak MPEntryViewController *welf = self;
self.totpUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
NSLog(@"Update TOTP Column Content");
NSIndexSet *columnIndex = [NSIndexSet indexSetWithIndex:[welf.entryTable columnWithIdentifier:MPEntryTableTOTPColumnIdentifier]];
NSIndexSet *rowIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,welf.entryTable.numberOfRows)];
[welf.entryTable reloadDataForRowIndexes:rowIndexes columnIndexes:columnIndex];
Expand All @@ -751,7 +750,7 @@ - (void)copyPassword:(id)sender {
NSArray *nodes = self.currentTargetNodes;
KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil;
NSString *value = [selectedEntry.password kpk_finalValueForEntry:selectedEntry];
if(value) {
if(value.length > 0) {
[MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoPassword name:nil atView:self.view];
}
}
Expand All @@ -760,11 +759,20 @@ - (void)copyUsername:(id)sender {
NSArray *nodes = self.currentTargetNodes;
KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil;
NSString *value = [selectedEntry.username kpk_finalValueForEntry:selectedEntry];
if(value) {
if(value.length > 0) {
[MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoUsername name:nil atView:self.view];
}
}

- (void)copyTOTP:(id)sender {
NSArray *nodes = self.currentTargetNodes;
KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil;
NSString *value = selectedEntry.timeOTP;
if(value.length > 0) {
[MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoTOTP name:nil atView:self.view];
}
}

- (void)copyCustomAttribute:(id)sender {
NSArray *nodes = self.currentTargetNodes;
KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil;
Expand All @@ -773,7 +781,7 @@ - (void)copyCustomAttribute:(id)sender {
NSAssert((index >= 0) && (index < selectedEntry.customAttributes.count), @"Index for custom field needs to be valid");
KPKAttribute *attribute = selectedEntry.customAttributes[index];
NSString *value = attribute.evaluatedValue;
if(value) {
if(value.length > 0) {
[MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoCustom name:attribute.key atView:self.view];
}
}
Expand All @@ -783,7 +791,7 @@ - (void)copyURL:(id)sender {
NSArray *nodes = self.currentTargetNodes;
KPKEntry *selectedEntry = nodes.count == 1 ? [nodes.firstObject asEntry] : nil;
NSString *value = [selectedEntry.url kpk_finalValueForEntry:selectedEntry];
if(value) {
if(value.length > 0) {
[MPPasteBoardController.defaultController copyObject:value overlayInfo:MPPasteboardOverlayInfoURL name:nil atView:self.view];
}
}
Expand Down Expand Up @@ -852,6 +860,9 @@ - (void)_columnDoubleClick:(id)sender {
else if([identifier isEqualToString:MPEntryTableUserNameColumnIdentifier]) {
[self copyUsername:nil];
}
else if([identifier isEqualToString:MPEntryTableTOTPColumnIdentifier]) {
[self copyTOTP:nil];
}
else if([identifier isEqualToString:MPEntryTableURLColumnIdentifier]) {
[self _executeURLColumnDoubleClick];
}
Expand Down
1 change: 1 addition & 0 deletions MacPass/MPPasteBoardController.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef NS_ENUM(NSUInteger, MPPasteboardOverlayInfoType) {
MPPasteboardOverlayInfoPassword,
MPPasteboardOverlayInfoUsername,
MPPasteboardOverlayInfoURL,
MPPasteboardOverlayInfoTOTP,
MPPasteboardOverlayInfoCustom, // overlay info that a custom field was copied
MPPasteboardOverlayInfoReference // overlay info that a reference that was copied
};
Expand Down
5 changes: 5 additions & 0 deletions MacPass/MPPasteBoardController.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ - (void)copyObject:(id<NSPasteboardWriting>)object overlayInfo:(MPPasteboardOver
infoText = NSLocalizedString(@"COPIED_USERNAME", @"Username was copied to the pasteboard");
break;

case MPPasteboardOverlayInfoTOTP:
infoImage = [MPIconHelper icon:MPIconPassword];
infoText = NSLocalizedString(@"COPIED_TOTP", "TOTP was copied to the pasteboard");
break;

case MPPasteboardOverlayInfoCustom:
infoImage = [MPIconHelper icon:MPIconPassword];
infoText = [NSString stringWithFormat:NSLocalizedString(@"COPIED_FIELD_%@", "Field name that was copied to the pasteboard"), name];
Expand Down

0 comments on commit 29756c0

Please sign in to comment.