2017-11-08 06:14:58 +01:00
|
|
|
//
|
|
|
|
// FeedPasteboardWriter.swift
|
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 11/7/17.
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-02-03 07:51:32 +01:00
|
|
|
import AppKit
|
2017-11-08 06:14:58 +01:00
|
|
|
import Data
|
|
|
|
|
|
|
|
@objc final class FeedPasteboardWriter: NSObject, NSPasteboardWriting {
|
|
|
|
|
|
|
|
private let feed: Feed
|
|
|
|
static let feedUTI = "com.ranchero.feed"
|
|
|
|
static let feedUTIType = NSPasteboard.PasteboardType(rawValue: feedUTI)
|
2017-12-27 01:18:19 +01:00
|
|
|
static let feedUTIInternal = "com.ranchero.evergreen.internal.feed"
|
2017-11-08 06:14:58 +01:00
|
|
|
static let feedUTIInternalType = NSPasteboard.PasteboardType(rawValue: feedUTIInternal)
|
|
|
|
|
|
|
|
init(feed: Feed) {
|
|
|
|
|
|
|
|
self.feed = feed
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - NSPasteboardWriting
|
|
|
|
|
|
|
|
func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
|
|
|
|
|
2018-02-04 22:45:26 +01:00
|
|
|
return [FeedPasteboardWriter.feedUTIType, .URL, .string, FeedPasteboardWriter.feedUTIInternalType]
|
2017-11-08 06:14:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func pasteboardPropertyList(forType type: NSPasteboard.PasteboardType) -> Any? {
|
|
|
|
|
|
|
|
let plist: Any?
|
|
|
|
|
|
|
|
switch type {
|
|
|
|
case .string:
|
|
|
|
plist = feed.nameForDisplay
|
|
|
|
case .URL:
|
|
|
|
plist = feed.url
|
|
|
|
case FeedPasteboardWriter.feedUTIType:
|
|
|
|
plist = exportDictionary()
|
|
|
|
case FeedPasteboardWriter.feedUTIInternalType:
|
|
|
|
plist = internalDictionary()
|
|
|
|
default:
|
|
|
|
plist = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return plist
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension FeedPasteboardWriter {
|
|
|
|
|
|
|
|
private struct Key {
|
|
|
|
|
|
|
|
static let url = "URL"
|
|
|
|
static let homePageURL = "homePageURL"
|
|
|
|
static let name = "name"
|
|
|
|
|
|
|
|
// Internal
|
|
|
|
static let accountID = "accountID"
|
|
|
|
static let feedID = "feedID"
|
|
|
|
static let editedName = "editedName"
|
|
|
|
static let unreadCount = "unreadCount"
|
|
|
|
}
|
|
|
|
|
|
|
|
func exportDictionary() -> [String: String] {
|
|
|
|
|
|
|
|
var d = [String: String]()
|
|
|
|
|
|
|
|
d[Key.url] = feed.url
|
|
|
|
d[Key.homePageURL] = feed.homePageURL ?? ""
|
|
|
|
d[Key.name] = feed.nameForDisplay
|
|
|
|
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
func internalDictionary() -> [String: Any] {
|
|
|
|
|
|
|
|
var d = [String: Any]()
|
|
|
|
|
|
|
|
d[Key.url] = feed.url
|
|
|
|
if let homePageURL = feed.homePageURL {
|
|
|
|
d[Key.homePageURL] = homePageURL
|
|
|
|
}
|
|
|
|
if let name = feed.name {
|
|
|
|
d[Key.name] = name
|
|
|
|
}
|
|
|
|
if let editedName = feed.editedName {
|
|
|
|
d[Key.editedName] = editedName
|
|
|
|
}
|
|
|
|
if feed.unreadCount > 0 {
|
|
|
|
d[Key.unreadCount] = feed.unreadCount
|
|
|
|
}
|
|
|
|
|
|
|
|
return d
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|