From ada77a5eb0300e75cb01da948807d4847af395c3 Mon Sep 17 00:00:00 2001 From: Barijaona Ramaholimihaso Date: Sun, 25 Jun 2023 11:53:32 +0300 Subject: [PATCH 1/3] Switch to current pasteboard types Cf. https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html --- Vienna/Sources/Main window/ArticleListView.m | 4 ++-- Vienna/Sources/Main window/UnifiedDisplayView.m | 4 ++-- Vienna/Sources/Shared/Constants.h | 1 - Vienna/Sources/Shared/Constants.m | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Vienna/Sources/Main window/ArticleListView.m b/Vienna/Sources/Main window/ArticleListView.m index 4b0faddcf1..1041b3e0ef 100644 --- a/Vienna/Sources/Main window/ArticleListView.m +++ b/Vienna/Sources/Main window/ArticleListView.m @@ -1478,7 +1478,7 @@ -(BOOL)copyTableSelection:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *) [pboard declareTypes:@[VNAPasteboardTypeRSSItem, VNAPasteboardTypeWebURLsWithTitles, NSPasteboardTypeString, NSPasteboardTypeHTML] owner:self]; if (count == 1) { - [pboard addTypes:@[VNAPasteboardTypeURL, VNAPasteboardTypeURLName, NSPasteboardTypeURL] + [pboard addTypes:@[NSPasteboardTypeURL, VNAPasteboardTypeURLName] owner:self]; } @@ -1513,7 +1513,7 @@ -(BOOL)copyTableSelection:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *) [fullHTMLText appendFormat:@"%@
%@

", msgLink, msgTitle, msgText]; if (count == 1) { - [pboard setString:msgLink forType:VNAPasteboardTypeURL]; + [pboard setString:msgLink forType:NSPasteboardTypeURL]; [pboard setString:msgTitle forType:VNAPasteboardTypeURLName]; // Write the link to the pastboard. diff --git a/Vienna/Sources/Main window/UnifiedDisplayView.m b/Vienna/Sources/Main window/UnifiedDisplayView.m index e0dbbde110..f0f3dbab21 100644 --- a/Vienna/Sources/Main window/UnifiedDisplayView.m +++ b/Vienna/Sources/Main window/UnifiedDisplayView.m @@ -599,7 +599,7 @@ -(BOOL)copyIndexesSelection:(NSIndexSet*)rowIndexes toPasteboard:(NSPasteboard * // Set up the pasteboard [pboard declareTypes:@[VNAPasteboardTypeRSSItem, VNAPasteboardTypeWebURLsWithTitles, NSPasteboardTypeString, NSPasteboardTypeHTML] owner:self]; if (count == 1) { - [pboard addTypes:@[VNAPasteboardTypeURL, VNAPasteboardTypeURLName, NSPasteboardTypeURL] + [pboard addTypes:@[NSPasteboardTypeURL, VNAPasteboardTypeURLName] owner:self]; } @@ -634,7 +634,7 @@ -(BOOL)copyIndexesSelection:(NSIndexSet*)rowIndexes toPasteboard:(NSPasteboard * [fullHTMLText appendFormat:@"%@
%@

", msgLink, msgTitle, msgText]; if (count == 1) { - [pboard setString:msgLink forType:VNAPasteboardTypeURL]; + [pboard setString:msgLink forType:NSPasteboardTypeURL]; [pboard setString:msgTitle forType:VNAPasteboardTypeURLName]; // Write the link to the pastboard. diff --git a/Vienna/Sources/Shared/Constants.h b/Vienna/Sources/Shared/Constants.h index 2c4dc21066..a297567c55 100644 --- a/Vienna/Sources/Shared/Constants.h +++ b/Vienna/Sources/Shared/Constants.h @@ -127,7 +127,6 @@ extern NSInteger const MA_Default_ConcurrentDownloads; extern NSPasteboardType const VNAPasteboardTypeRSSItem; extern NSPasteboardType const VNAPasteboardTypeFolderList; extern NSPasteboardType const VNAPasteboardTypeRSSSource; -extern NSPasteboardType const VNAPasteboardTypeURL; extern NSPasteboardType const VNAPasteboardTypeURLName; extern NSPasteboardType const VNAPasteboardTypeWebURLsWithTitles; diff --git a/Vienna/Sources/Shared/Constants.m b/Vienna/Sources/Shared/Constants.m index 483bcbb11b..34e38f8530 100644 --- a/Vienna/Sources/Shared/Constants.m +++ b/Vienna/Sources/Shared/Constants.m @@ -140,6 +140,5 @@ NSPasteboardType const VNAPasteboardTypeFolderList = @"ViennaFolderType"; NSPasteboardType const VNAPasteboardTypeRSSSource = @"CorePasteboardFlavorType 0x52535373"; NSPasteboardType const VNAPasteboardTypeRSSItem = @"CorePasteboardFlavorType 0x52535369"; -NSPasteboardType const VNAPasteboardTypeURL = @"CorePasteboardFlavorType 0x75726C20"; -NSPasteboardType const VNAPasteboardTypeURLName = @"CorePasteboardFlavorType 0x75726C6E"; +NSPasteboardType const VNAPasteboardTypeURLName = @"public.url-name"; NSPasteboardType const VNAPasteboardTypeWebURLsWithTitles = @"WebURLsWithTitlesPboardType"; From 9f85685c854244a316356b43924ea16f6ebbf222 Mon Sep 17 00:00:00 2001 From: Barijaona Ramaholimihaso Date: Sun, 2 Jul 2023 20:58:20 +0300 Subject: [PATCH 2/3] Use titles as sharing service's subject Especially useful for the e-mail sharing service --- .../Main window/MainWindowController.swift | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Vienna/Sources/Main window/MainWindowController.swift b/Vienna/Sources/Main window/MainWindowController.swift index e7c3c1ee19..5ee56abeb2 100644 --- a/Vienna/Sources/Main window/MainWindowController.swift +++ b/Vienna/Sources/Main window/MainWindowController.swift @@ -175,15 +175,23 @@ final class MainWindowController: NSWindowController { } } + var shareableItemsSubject = String() + private var shareableItems: [NSPasteboardWriting] { var items = [URL]() if let activeTab = browser.activeTab, let url = activeTab.tabUrl { items.append(url) + shareableItemsSubject = activeTab.title ?? NSLocalizedString("URL", comment: "URL") } else { if let articles = articleListView?.markedArticleRange as? [Article] { let links = articles.compactMap { $0.link } let urls = links.compactMap { URL(string: $0) } items = urls + if articles.count == 1 { + shareableItemsSubject = articles[0].title ?? "" + } else { + shareableItemsSubject = String(format: NSLocalizedString("%u articles", comment: ""), articles.count) + } } } return items as [NSURL] @@ -229,16 +237,21 @@ final class MainWindowController: NSWindowController { @IBAction private func performSharingService(_ sender: Any) { if (sender as? SharingServiceMenuItem)?.name == "emailLink" { - let sharingService = NSSharingService(named: .composeEmail) - sharingService?.perform(withItems: shareableItems) + if let sharingService = NSSharingService(named: .composeEmail) { + sharingService.delegate = self + sharingService.perform(withItems: shareableItems) + } } if (sender as? SharingServiceMenuItem)?.name == "safariReadingList" { - let sharingService = NSSharingService(named: .addToSafariReadingList) - sharingService?.perform(withItems: shareableItems) + if let sharingService = NSSharingService(named: .addToSafariReadingList) { + sharingService.delegate = self + sharingService.perform(withItems: shareableItems) + } } if let sharingService = (sender as? SharingServiceToolbarItem)?.service { + sharingService.delegate = self sharingService.perform(withItems: shareableItems) } } @@ -490,6 +503,12 @@ extension MainWindowController: NSSharingServiceDelegate { return window } + func sharingService( + _ sharingService: NSSharingService, + willShareItems items: [Any] + ) { + sharingService.subject = shareableItemsSubject + } } // MARK: - NSSharingServicePickerDelegate From 739392cf9e34e0a88dffc83ca6e2f434785f9e2b Mon Sep 17 00:00:00 2001 From: Barijaona Ramaholimihaso Date: Sun, 2 Jul 2023 21:18:26 +0300 Subject: [PATCH 3/3] Improve drag & drop, copy & paste pasteboard To avoid having default font Times New Roman in Mail.app, I specify style "font-family:sans-serif" in template. Remove markup in type string pasteboard items. --- Vienna/Sources/Main window/ArticleListView.m | 8 +++++--- Vienna/Sources/Main window/UnifiedDisplayView.m | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Vienna/Sources/Main window/ArticleListView.m b/Vienna/Sources/Main window/ArticleListView.m index 1041b3e0ef..24cbedec8e 100644 --- a/Vienna/Sources/Main window/ArticleListView.m +++ b/Vienna/Sources/Main window/ArticleListView.m @@ -1483,7 +1483,8 @@ -(BOOL)copyTableSelection:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *) } // Open the HTML string - [fullHTMLText appendString:@""]; + [fullHTMLText appendString:@"" + ""]; // Get all the articles that are being dragged NSUInteger msgIndex = rowIndexes.firstIndex; @@ -1507,10 +1508,11 @@ -(BOOL)copyTableSelection:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *) [arrayOfArticles addObject:articleDict]; // Plain text - [fullPlainText appendFormat:@"%@\n%@\n\n", msgTitle, msgText]; + [fullPlainText appendFormat:@"%@\n%@\n\n", msgTitle, thisArticle.summary]; // Add HTML version too. - [fullHTMLText appendFormat:@"%@
%@

", msgLink, msgTitle, msgText]; + [fullHTMLText appendFormat:@"
%@
" + "
%@

", msgLink, msgTitle, msgText]; if (count == 1) { [pboard setString:msgLink forType:NSPasteboardTypeURL]; diff --git a/Vienna/Sources/Main window/UnifiedDisplayView.m b/Vienna/Sources/Main window/UnifiedDisplayView.m index f0f3dbab21..c2a63f889a 100644 --- a/Vienna/Sources/Main window/UnifiedDisplayView.m +++ b/Vienna/Sources/Main window/UnifiedDisplayView.m @@ -604,7 +604,8 @@ -(BOOL)copyIndexesSelection:(NSIndexSet*)rowIndexes toPasteboard:(NSPasteboard * } // Open the HTML string - [fullHTMLText appendString:@""]; + [fullHTMLText appendString:@"" + ""]; // Get all the articles that are being dragged NSUInteger msgIndex = rowIndexes.firstIndex; @@ -628,10 +629,11 @@ -(BOOL)copyIndexesSelection:(NSIndexSet*)rowIndexes toPasteboard:(NSPasteboard * [arrayOfArticles addObject:articleDict]; // Plain text - [fullPlainText appendFormat:@"%@\n%@\n\n", msgTitle, msgText]; + [fullPlainText appendFormat:@"%@\n%@\n\n", msgTitle, thisArticle.summary]; // Add HTML version too. - [fullHTMLText appendFormat:@"%@
%@

", msgLink, msgTitle, msgText]; + [fullHTMLText appendFormat:@"
%@
" + "
%@

", msgLink, msgTitle, msgText]; if (count == 1) { [pboard setString:msgLink forType:NSPasteboardTypeURL];