diff --git a/MacPass/MPPasteBoardController.h b/MacPass/MPPasteBoardController.h index 1d53b1dc..57aad9dd 100644 --- a/MacPass/MPPasteBoardController.h +++ b/MacPass/MPPasteBoardController.h @@ -22,6 +22,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + typedef NS_ENUM(NSUInteger, MPPasteboardOverlayInfoType) { MPPasteboardOverlayInfoPassword, MPPasteboardOverlayInfoUsername, @@ -30,6 +32,22 @@ typedef NS_ENUM(NSUInteger, MPPasteboardOverlayInfoType) { MPPasteboardOverlayInfoReference // overlay info that a reference that was copied }; +typedef MPPasteboardOverlayInfoType MPPasteboardContentInfoType; + +@interface MPPasteBoardContentInfo : NSObject + +@property (readonly, strong) NSImage *image; +@property (readonly, strong) NSString *label; + ++ (instancetype)contentInforForCustomField:(NSString *)name; ++ (instancetype)passwordContentInfo; // creates a content info approporate for passwords ++ (instancetype)urlContentInfo; // creates a content info apprpriate for urls + +- (instancetype)initWithImage:(NSImage * _Nullable)image label:(NSString * _Nullable)label NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithType:(MPPasteboardContentInfoType)type; + +@end + @interface MPPasteBoardController : NSObject /** @@ -70,6 +88,9 @@ FOUNDATION_EXPORT NSString *const MPPasteBoardControllerDidClearClipboard; @param name a custom name @param view the view that initiated the copy action */ -- (void)copyObject:(id)object overlayInfo:(MPPasteboardOverlayInfoType)overlayInfoType name:(NSString *)name atView:(NSView *)view; +- (void)copyObject:(id)object overlayInfo:(MPPasteboardOverlayInfoType)overlayInfoType name:(NSString * _Nullable)name atView:(NSView *)view; +- (void)copyObject:(id)object contentInfo:(MPPasteBoardContentInfo *)info atView:(NSView *)view; @end + +NS_ASSUME_NONNULL_END diff --git a/MacPass/MPPasteBoardController.m b/MacPass/MPPasteBoardController.m index 93be81f0..aae3e18c 100644 --- a/MacPass/MPPasteBoardController.m +++ b/MacPass/MPPasteBoardController.m @@ -22,6 +22,7 @@ #import "MPPasteBoardController.h" #import "MPSettingsHelper.h" +#import "MPIconHelper.h" #import "MPOverlayWindowController.h" /* Notifications */ @@ -126,6 +127,10 @@ NSString *const MPPasteBoardTypeSource = @"org.nspasteboard.source"; self.isEmpty = NO; } +- (void)copyObject:(id)object contentInfo:(MPPasteBoardContentInfo *)info atView:(nonnull NSView *)view{ + [self copyObject:object overlayInfo:MPPasteboardOverlayInfoCustom name:info.label atView:view]; +} + - (void)copyObject:(id)object overlayInfo:(MPPasteboardOverlayInfoType)overlayInfoType name:(NSString *)name atView:(NSView *)view{ if(!object) { return; @@ -135,27 +140,27 @@ NSString *const MPPasteBoardTypeSource = @"org.nspasteboard.source"; NSString *infoText = nil; switch(overlayInfoType) { case MPPasteboardOverlayInfoPassword: - infoImage = [NSBundle.mainBundle imageForResource:@"00_PasswordTemplate"]; + infoImage = [MPIconHelper icon:MPIconPassword]; infoText = NSLocalizedString(@"COPIED_PASSWORD", @"Password was copied to the pasteboard"); break; case MPPasteboardOverlayInfoURL: - infoImage = [NSBundle.mainBundle imageForResource:@"01_PackageNetworkTemplate"]; + infoImage = [MPIconHelper icon:MPIconPackageNetwork]; infoText = NSLocalizedString(@"COPIED_URL", @"URL was copied to the pasteboard"); break; case MPPasteboardOverlayInfoUsername: - infoImage = [NSBundle.mainBundle imageForResource:@"09_IdentityTemplate"]; + infoImage = [MPIconHelper icon:MPIconIdentity]; infoText = NSLocalizedString(@"COPIED_USERNAME", @"Username was copied to the pasteboard"); break; case MPPasteboardOverlayInfoCustom: - infoImage = [NSBundle.mainBundle imageForResource:@"00_PasswordTemplate"]; + infoImage = [MPIconHelper icon:MPIconPassword]; infoText = [NSString stringWithFormat:NSLocalizedString(@"COPIED_FIELD_%@", "Field name that was copied to the pasteboard"), name]; break; case MPPasteboardOverlayInfoReference: - infoImage = [NSBundle.mainBundle imageForResource:@"04_KlipperTemplate"]; + infoImage = [MPIconHelper icon:MPIconKlipper]; infoText = name; break; diff --git a/MacPass/MPTOTPViewController.h b/MacPass/MPTOTPViewController.h index 919ecd2e..66e4d17e 100644 --- a/MacPass/MPTOTPViewController.h +++ b/MacPass/MPTOTPViewController.h @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface MPTOTPViewController : NSViewController +@interface MPTOTPViewController : NSViewController @property (strong) IBOutlet HNHUITextField *toptValueTextField; @property (strong) IBOutlet NSButton *remainingTimeButton; @property (strong) IBOutlet NSButton *showSetupButton; diff --git a/MacPass/MPTOTPViewController.m b/MacPass/MPTOTPViewController.m index f0160958..71b2c1c3 100644 --- a/MacPass/MPTOTPViewController.m +++ b/MacPass/MPTOTPViewController.m @@ -10,6 +10,7 @@ #import #import "MPEntryInspectorViewController.h" +#import "MPPasteBoardController.h" @interface MPTOTPViewController () @@ -45,6 +46,25 @@ [self _didChangeAttribute:nil]; } +- (BOOL)textField:(NSTextField *)textField textView:(NSTextView *)textView performAction:(SEL)action { + if(action == @selector(copy:)) { + MPPasteboardOverlayInfoType info = MPPasteboardOverlayInfoCustom; + NSMutableString *selectedValue = [[NSMutableString alloc] init]; + 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; + } + [MPPasteBoardController.defaultController copyObject:selectedValue overlayInfo:info name:name atView:self.view]; + return NO; + } + return YES; + +} + + - (void)_didChangeAttribute:(NSNotification *)notification { [self _updateDisplay]; } diff --git a/MacPass/MPTOTPViewController.xib b/MacPass/MPTOTPViewController.xib index bbb63c2a..d523635b 100644 --- a/MacPass/MPTOTPViewController.xib +++ b/MacPass/MPTOTPViewController.xib @@ -36,11 +36,14 @@ - + + + +