Run alert modally if no window is passed; add doc comments

This commit is contained in:
Nate Weaver
2022-10-10 16:49:13 -05:00
parent cdf2dd5d64
commit 016a2948c4

View File

@@ -10,15 +10,24 @@ import RSCore
extension URLPasteboardWriter {
/// Copy URL strings, alerting the user the first time the array of URL strings contains `nil`.
/// - Parameters:
/// - urlStrings: The URL strings to copy.
/// - pasteboard: The pastebaord to copy to.
/// - window: The window to use as a sheet parent for the alert. If `nil`, will run the alert modally.
static func write(urlStrings: [String?], to pasteboard: NSPasteboard = .general, alertingInWindow window: NSWindow?) {
URLPasteboardWriter.write(urlStrings: urlStrings.compactMap { $0 }, to: pasteboard)
if urlStrings.contains(nil), !AppDefaults.shared.hasSeenNotAllArticlesHaveURLsAlert, let window {
if urlStrings.contains(nil), !AppDefaults.shared.hasSeenNotAllArticlesHaveURLsAlert {
let alert = NSAlert()
alert.messageText = NSLocalizedString("Some articles dont have links, so they weren't copied.", comment: "")
alert.informativeText = NSLocalizedString("You won't see this message again.", comment: "")
alert.messageText = NSLocalizedString("Some articles dont have links, so they weren't copied.", comment: "\"Some articles have no links\" copy alert message text")
alert.informativeText = NSLocalizedString("You won't see this message again.", comment: "You won't see this message again")
alert.beginSheetModal(for: window)
if let window {
alert.beginSheetModal(for: window)
} else {
alert.runModal() // this should never happen
}
AppDefaults.shared.hasSeenNotAllArticlesHaveURLsAlert = true
}