From b6b106b9456e42e105d65ff8ea2a4425595ab25c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 5 Sep 2018 21:30:00 +0200 Subject: Add a "Copy" button that copies the email address to the clipboard Thanks to these references: - https://stackoverflow.com/questions/5686958/set-string-to-pasteboard-copy-paste-in-cocoa-application/5687005#5687005 - https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PasteboardGuide106/Articles/pbCopying.html --- CopyMailto/AppDelegate.h | 1 + CopyMailto/AppDelegate.m | 9 +++++++++ CopyMailto/Base.lproj/MainMenu.xib | 14 ++++++++++++++ 3 files changed, 24 insertions(+) (limited to 'CopyMailto') diff --git a/CopyMailto/AppDelegate.h b/CopyMailto/AppDelegate.h index 321d100..7ba86b3 100644 --- a/CopyMailto/AppDelegate.h +++ b/CopyMailto/AppDelegate.h @@ -15,5 +15,6 @@ - (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent; +- (IBAction)copyEmailToClipboard:(id)sender; @end diff --git a/CopyMailto/AppDelegate.m b/CopyMailto/AppDelegate.m index 6f3477d..5eb04c5 100644 --- a/CopyMailto/AppDelegate.m +++ b/CopyMailto/AppDelegate.m @@ -33,4 +33,13 @@ const NSUInteger MAILTO_INDEX = 7; [_email_address setStringValue:[url substringFromIndex:MAILTO_INDEX]]; } +- (IBAction)copyEmailToClipboard:(id)sender +{ + NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; + [pasteboard clearContents]; + [pasteboard writeObjects: + [NSArray arrayWithObject: + [_email_address stringValue]]]; +} + @end diff --git a/CopyMailto/Base.lproj/MainMenu.xib b/CopyMailto/Base.lproj/MainMenu.xib index e3f79a2..ce6197b 100644 --- a/CopyMailto/Base.lproj/MainMenu.xib +++ b/CopyMailto/Base.lproj/MainMenu.xib @@ -108,6 +108,20 @@ Gw + -- cgit v1.2.3