Add Copy Article URL & Copy External URL Menu Items

The Mac items display in the edit and contextual menus, and in the iOS contextual menu for an article.
This commit is contained in:
Rob Mathers
2021-05-01 16:47:39 -04:00
parent fa0744ed2c
commit 8707a71313
4 changed files with 92 additions and 0 deletions

View File

@@ -362,6 +362,17 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
menuElements.append(UIMenu(title: "", options: .displayInline, children: secondaryActions))
}
var copyActions = [UIAction]()
if let action = self.copyArticleURLAction(article) {
copyActions.append(action)
}
if let action = self.copyExternalURLAction(article) {
copyActions.append(action)
}
if !copyActions.isEmpty {
menuElements.append(UIMenu(title: "", options: .displayInline, children: copyActions))
}
if let action = self.openInBrowserAction(article) {
menuElements.append(UIMenu(title: "", options: .displayInline, children: [action]))
}
@@ -887,6 +898,25 @@ private extension MasterTimelineViewController {
}
return action
}
func copyArticleURLAction(_ article: Article) -> UIAction? {
guard let preferredLink = article.preferredLink, let url = URL(string: preferredLink) else { return nil }
let title = NSLocalizedString("Copy Article URL", comment: "Copy Article URL")
let action = UIAction(title: title, image: AppAssets.copyImage) { action in
UIPasteboard.general.url = url
}
return action
}
func copyExternalURLAction(_ article: Article) -> UIAction? {
guard let externalURL = article.externalURL, externalURL != article.preferredLink, let url = URL(string: externalURL) else { return nil }
let title = NSLocalizedString("Copy External URL", comment: "Copy External URL")
let action = UIAction(title: title, image: AppAssets.copyImage) { action in
UIPasteboard.general.url = url
}
return action
}
func openInBrowserAction(_ article: Article) -> UIAction? {
guard let preferredLink = article.preferredLink, let _ = URL(string: preferredLink) else {