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:
parent
fa0744ed2c
commit
8707a71313
@ -157,6 +157,18 @@
|
|||||||
<action selector="copy:" target="Ady-hI-5gd" id="G1f-GL-Joy"/>
|
<action selector="copy:" target="Ady-hI-5gd" id="G1f-GL-Joy"/>
|
||||||
</connections>
|
</connections>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
|
<menuItem title="Copy Article URL" id="qNk-By-jKp">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="copyArticleURL:" target="Ady-hI-5gd" id="A5t-x7-Mmy"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
|
<menuItem title="Copy External URL" id="fOF-99-6Iv">
|
||||||
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="copyExternalURL:" target="Ady-hI-5gd" id="MkV-Do-Bc1"/>
|
||||||
|
</connections>
|
||||||
|
</menuItem>
|
||||||
<menuItem title="Paste" keyEquivalent="v" id="gVA-U4-sdL">
|
<menuItem title="Paste" keyEquivalent="v" id="gVA-U4-sdL">
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="paste:" target="Ady-hI-5gd" id="UvS-8e-Qdg"/>
|
<action selector="paste:" target="Ady-hI-5gd" id="UvS-8e-Qdg"/>
|
||||||
|
@ -188,6 +188,14 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||||||
|
|
||||||
public func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
|
public func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
|
||||||
|
|
||||||
|
if item.action == #selector(copyArticleURL(_:)) {
|
||||||
|
return canCopyArticleURL()
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.action == #selector(copyExternalURL(_:)) {
|
||||||
|
return canCopyExternalURL()
|
||||||
|
}
|
||||||
|
|
||||||
if item.action == #selector(openArticleInBrowser(_:)) {
|
if item.action == #selector(openArticleInBrowser(_:)) {
|
||||||
if let item = item as? NSMenuItem, item.keyEquivalentModifierMask.contains(.shift) {
|
if let item = item as? NSMenuItem, item.keyEquivalentModifierMask.contains(.shift) {
|
||||||
item.title = Browser.titleForOpenInBrowserInverted
|
item.title = Browser.titleForOpenInBrowserInverted
|
||||||
@ -286,6 +294,18 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IBAction func copyArticleURL(_ sender: Any?) {
|
||||||
|
if let link = currentLink {
|
||||||
|
URLPasteboardWriter.write(urlString: link, to: .general)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@IBAction func copyExternalURL(_ sender: Any?) {
|
||||||
|
if let link = oneSelectedArticle?.externalURL {
|
||||||
|
URLPasteboardWriter.write(urlString: link, to: .general)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@IBAction func openArticleInBrowser(_ sender: Any?) {
|
@IBAction func openArticleInBrowser(_ sender: Any?) {
|
||||||
if let link = currentLink {
|
if let link = currentLink {
|
||||||
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)
|
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)
|
||||||
@ -1008,6 +1028,14 @@ private extension MainWindowController {
|
|||||||
|
|
||||||
// MARK: - Command Validation
|
// MARK: - Command Validation
|
||||||
|
|
||||||
|
func canCopyArticleURL() -> Bool {
|
||||||
|
return currentLink != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func canCopyExternalURL() -> Bool {
|
||||||
|
return oneSelectedArticle?.externalURL != nil && oneSelectedArticle?.externalURL != currentLink
|
||||||
|
}
|
||||||
|
|
||||||
func canGoToNextUnread(wrappingToTop wrapping: Bool = false) -> Bool {
|
func canGoToNextUnread(wrappingToTop wrapping: Bool = false) -> Bool {
|
||||||
|
|
||||||
guard let timelineViewController = currentTimelineViewController, let sidebarViewController = sidebarViewController else {
|
guard let timelineViewController = currentTimelineViewController, let sidebarViewController = sidebarViewController else {
|
||||||
|
@ -91,6 +91,13 @@ extension TimelineViewController {
|
|||||||
Browser.open(urlString, inBackground: false)
|
Browser.open(urlString, inBackground: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func copyURLFromContextualMenu(_ sender: Any?) {
|
||||||
|
guard let menuItem = sender as? NSMenuItem, let urlString = menuItem.representedObject as? String else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
URLPasteboardWriter.write(urlString: urlString, to: .general)
|
||||||
|
}
|
||||||
|
|
||||||
@objc func performShareServiceFromContextualMenu(_ sender: Any?) {
|
@objc func performShareServiceFromContextualMenu(_ sender: Any?) {
|
||||||
guard let menuItem = sender as? NSMenuItem, let sharingCommandInfo = menuItem.representedObject as? SharingCommandInfo else {
|
guard let menuItem = sender as? NSMenuItem, let sharingCommandInfo = menuItem.representedObject as? SharingCommandInfo else {
|
||||||
return
|
return
|
||||||
@ -168,6 +175,12 @@ private extension TimelineViewController {
|
|||||||
if articles.count == 1, let link = articles.first!.preferredLink {
|
if articles.count == 1, let link = articles.first!.preferredLink {
|
||||||
menu.addSeparatorIfNeeded()
|
menu.addSeparatorIfNeeded()
|
||||||
menu.addItem(openInBrowserMenuItem(link))
|
menu.addItem(openInBrowserMenuItem(link))
|
||||||
|
menu.addSeparatorIfNeeded()
|
||||||
|
menu.addItem(copyArticleURLMenuItem(link))
|
||||||
|
|
||||||
|
if let externalLink = articles.first?.externalURL, externalLink != link {
|
||||||
|
menu.addItem(copyExternalURLMenuItem(externalLink))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let sharingMenu = shareMenu(for: articles) {
|
if let sharingMenu = shareMenu(for: articles) {
|
||||||
@ -261,6 +274,15 @@ private extension TimelineViewController {
|
|||||||
return menuItem(NSLocalizedString("Open in Browser", comment: "Command"), #selector(openInBrowserFromContextualMenu(_:)), urlString)
|
return menuItem(NSLocalizedString("Open in Browser", comment: "Command"), #selector(openInBrowserFromContextualMenu(_:)), urlString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copyArticleURLMenuItem(_ urlString: String) -> NSMenuItem {
|
||||||
|
return menuItem(NSLocalizedString("Copy Article URL", comment: "Command"), #selector(copyURLFromContextualMenu(_:)), urlString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyExternalURLMenuItem(_ urlString: String) -> NSMenuItem {
|
||||||
|
return menuItem(NSLocalizedString("Copy External URL", comment: "Command"), #selector(copyURLFromContextualMenu(_:)), urlString)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func menuItem(_ title: String, _ action: Selector, _ representedObject: Any) -> NSMenuItem {
|
func menuItem(_ title: String, _ action: Selector, _ representedObject: Any) -> NSMenuItem {
|
||||||
|
|
||||||
let item = NSMenuItem(title: title, action: action, keyEquivalent: "")
|
let item = NSMenuItem(title: title, action: action, keyEquivalent: "")
|
||||||
|
@ -362,6 +362,17 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
|||||||
menuElements.append(UIMenu(title: "", options: .displayInline, children: secondaryActions))
|
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) {
|
if let action = self.openInBrowserAction(article) {
|
||||||
menuElements.append(UIMenu(title: "", options: .displayInline, children: [action]))
|
menuElements.append(UIMenu(title: "", options: .displayInline, children: [action]))
|
||||||
}
|
}
|
||||||
@ -888,6 +899,25 @@ private extension MasterTimelineViewController {
|
|||||||
return action
|
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? {
|
func openInBrowserAction(_ article: Article) -> UIAction? {
|
||||||
guard let preferredLink = article.preferredLink, let _ = URL(string: preferredLink) else {
|
guard let preferredLink = article.preferredLink, let _ = URL(string: preferredLink) else {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user