From 016a2948c47f3ec14033401592c1bb9f5695e3aa Mon Sep 17 00:00:00 2001 From: Nate Weaver Date: Mon, 10 Oct 2022 16:49:13 -0500 Subject: [PATCH] Run alert modally if no window is passed; add doc comments --- .../URLPasteboardWriter+NetNewsWire.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Mac/MainWindow/URLPasteboardWriter+NetNewsWire.swift b/Mac/MainWindow/URLPasteboardWriter+NetNewsWire.swift index 679cd1602..6c6b1cfb4 100644 --- a/Mac/MainWindow/URLPasteboardWriter+NetNewsWire.swift +++ b/Mac/MainWindow/URLPasteboardWriter+NetNewsWire.swift @@ -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 don’t have links, so they weren't copied.", comment: "") - alert.informativeText = NSLocalizedString("You won't see this message again.", comment: "") + alert.messageText = NSLocalizedString("Some articles don’t 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 }