Support opening multiple articles in browser from main menu

Move openArticleURLs() to MainWindowController.
This commit is contained in:
Nate Weaver
2022-10-07 18:48:10 -05:00
parent 3420346fa3
commit 2fbc2fb628
3 changed files with 35 additions and 32 deletions

View File

@@ -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?) {