mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Support opening multiple articles in browser from main menu
Move openArticleURLs() to MainWindowController.
This commit is contained in:
@@ -340,10 +340,36 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
}
|
||||
}
|
||||
|
||||
func openArticleURLs(_ urlStrings: [String]) {
|
||||
func doOpenURLs() {
|
||||
for urlString in urlStrings {
|
||||
Browser.open(urlString, inBackground: false)
|
||||
}
|
||||
}
|
||||
|
||||
if urlStrings.count > 20 {
|
||||
let alert = NSAlert()
|
||||
let messageFormat = NSLocalizedString("Are you sure you want to open %ld articles in your browser?", comment: "")
|
||||
alert.messageText = String.localizedStringWithFormat(messageFormat, urlStrings.count)
|
||||
alert.addButton(withTitle: NSLocalizedString("Open", comment: ""))
|
||||
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
|
||||
|
||||
guard let window = self.window else { return }
|
||||
|
||||
alert.beginSheetModal(for: window) { response in
|
||||
if response == .alertFirstButtonReturn {
|
||||
doOpenURLs()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
doOpenURLs()
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func openArticleInBrowser(_ sender: Any?) {
|
||||
if let link = currentLink {
|
||||
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)
|
||||
}
|
||||
guard let selectedArticles else { return }
|
||||
let urlStrings = selectedArticles.compactMap { $0.preferredLink }
|
||||
openArticleURLs(urlStrings)
|
||||
}
|
||||
|
||||
@IBAction func openInBrowser(_ sender: Any?) {
|
||||
|
||||
@@ -89,34 +89,12 @@ extension TimelineViewController {
|
||||
}
|
||||
|
||||
@objc func openInBrowserFromContextualMenu(_ sender: Any?) {
|
||||
|
||||
guard let menuItem = sender as? NSMenuItem, let urlStrings = menuItem.representedObject as? [String] else {
|
||||
return
|
||||
}
|
||||
|
||||
func doOpenURLs() {
|
||||
for urlString in urlStrings {
|
||||
Browser.open(urlString, inBackground: false)
|
||||
}
|
||||
}
|
||||
|
||||
if urlStrings.count > 20 {
|
||||
let alert = NSAlert()
|
||||
let messageFormat = NSLocalizedString("Are you sure you want to open %ld articles in your browser?", comment: "")
|
||||
alert.messageText = String.localizedStringWithFormat(messageFormat, urlStrings.count)
|
||||
alert.addButton(withTitle: NSLocalizedString("Open", comment: ""))
|
||||
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
|
||||
|
||||
guard let window = self.view.window else { return }
|
||||
|
||||
alert.beginSheetModal(for: window) { response in
|
||||
if response == .alertFirstButtonReturn {
|
||||
doOpenURLs()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
doOpenURLs()
|
||||
}
|
||||
guard let windowController = self.view.window?.windowController as? MainWindowController else { return }
|
||||
windowController.openArticleURLs(urlStrings)
|
||||
}
|
||||
|
||||
@objc func copyURLFromContextualMenu(_ sender: Any?) {
|
||||
|
||||
@@ -315,9 +315,9 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
// MARK: - Actions
|
||||
|
||||
@objc func openArticleInBrowser(_ sender: Any?) {
|
||||
if let link = oneSelectedArticle?.preferredLink {
|
||||
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)
|
||||
}
|
||||
guard let windowController = self.view.window?.windowController as? MainWindowController else { return }
|
||||
let urlStrings = selectedArticles.compactMap { $0.preferredLink }
|
||||
windowController.openArticleURLs(urlStrings)
|
||||
}
|
||||
|
||||
@IBAction func toggleStatusOfSelectedArticles(_ sender: Any?) {
|
||||
@@ -779,8 +779,7 @@ extension TimelineViewController: NSUserInterfaceValidations {
|
||||
item.title = Browser.titleForOpenInBrowserInverted
|
||||
}
|
||||
|
||||
let currentLink = oneSelectedArticle?.preferredLink
|
||||
return currentLink != nil
|
||||
return selectedArticles.first { $0.preferredLink != nil } != nil
|
||||
}
|
||||
|
||||
if item.action == #selector(copy(_:)) {
|
||||
|
||||
Reference in New Issue
Block a user