Add function to write multiple URLs to the clipboard. Do some minor formatting cleanups.

This commit is contained in:
Brent Simmons committed 2025-10-01 09:34:45 -07:00
1 parent 7b96ba05f9
commit b819fa460d
1 file changed
+10 -8
@@ -3,33 +3,35 @@
// RSCore
//
// Created by Brent Simmons on 1/28/18.
// Copyright © 2018 Ranchero Software, LLC. All rights reserved.
// Copyright © 2018 Brent Simmons. All rights reserved.
//
#if os(macOS)
import AppKit
// Takes a string, not a URL, but writes it as a URL (when possible) and as a String.
/// Takes a string, not a URL, but writes it as a URL (when possible) and as a String.
@objc public final class URLPasteboardWriter: NSObject, NSPasteboardWriting {
let urlString: String
public init(urlString: String) {
self.urlString = urlString
}
public class func write(urlString: String, to pasteboard: NSPasteboard) {
write(urlStrings: [urlString], to: pasteboard)
}
public class func write(urlStrings: [String], to pasteboard: NSPasteboard) {
pasteboard.clearContents()
let writer = URLPasteboardWriter(urlString: urlString)
pasteboard.writeObjects([writer])
let writers = urlStrings.map { URLPasteboardWriter(urlString: $0) }
pasteboard.writeObjects(writers)
}
// MARK: - NSPasteboardWriting
public func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
if let _ = URL(string: urlString) {
return [.URL, .string]
}
@@ -37,11 +39,11 @@ import AppKit
}
public func pasteboardPropertyList(forType type: NSPasteboard.PasteboardType) -> Any? {
guard type == .string || type == .URL else {
return nil
}
return urlString
}
}
#endif