2018-01-21 04:06:07 +01:00
|
|
|
//
|
|
|
|
// FeedInspectorViewController.swift
|
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 1/20/18.
|
|
|
|
// Copyright © 2018 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import AppKit
|
2018-01-21 07:36:17 +01:00
|
|
|
import Data
|
2018-01-21 04:06:07 +01:00
|
|
|
|
2018-01-21 07:36:17 +01:00
|
|
|
final class FeedInspectorViewController: NSViewController, Inspector {
|
2018-01-21 04:06:07 +01:00
|
|
|
|
2018-01-22 05:35:44 +01:00
|
|
|
@IBOutlet var imageView: NSImageView!
|
|
|
|
@IBOutlet var nameTextField: NSTextField!
|
|
|
|
@IBOutlet var homePageURLTextField: NSTextField!
|
|
|
|
@IBOutlet var urlTextField: NSTextField!
|
|
|
|
|
2018-01-21 07:36:17 +01:00
|
|
|
let isFallbackInspector = false
|
2018-01-22 05:35:44 +01:00
|
|
|
var objects: [Any]? {
|
|
|
|
didSet {
|
|
|
|
updateUI()
|
|
|
|
}
|
|
|
|
}
|
2018-01-21 07:36:17 +01:00
|
|
|
|
|
|
|
func canInspect(_ objects: [Any]) -> Bool {
|
|
|
|
|
|
|
|
return objects.count == 1 && objects.first is Feed
|
|
|
|
}
|
|
|
|
|
|
|
|
func willEndInspectingObjects() {
|
2018-01-22 05:35:44 +01:00
|
|
|
|
|
|
|
makeUIEmpty()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension FeedInspectorViewController {
|
|
|
|
|
|
|
|
private var feed: Feed? {
|
|
|
|
guard let objects = objects, objects.count == 1, let feed = objects.first as? Feed else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return feed
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateUI() {
|
|
|
|
|
|
|
|
view.needsLayout = true
|
|
|
|
|
|
|
|
guard let feed = feed else {
|
|
|
|
makeUIEmpty()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
updateImage(feed)
|
|
|
|
updateName(feed)
|
|
|
|
updateHomePageURL(feed)
|
|
|
|
updateFeedURL(feed)
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateImage(_ feed: Feed) {
|
|
|
|
|
|
|
|
if let image = appDelegate.feedIconDownloader.icon(for: feed) {
|
|
|
|
imageView.image = image
|
|
|
|
}
|
|
|
|
else if let image = appDelegate.faviconDownloader.favicon(for: feed) {
|
|
|
|
imageView.image = image
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
imageView.image = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateName(_ feed: Feed) {
|
|
|
|
|
|
|
|
nameTextField.stringValue = feed.editedName ?? feed.name ?? ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateHomePageURL(_ feed: Feed) {
|
|
|
|
|
|
|
|
homePageURLTextField.stringValue = feed.homePageURL ?? ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateFeedURL(_ feed: Feed) {
|
|
|
|
|
|
|
|
urlTextField.stringValue = feed.url
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeUIEmpty() {
|
2018-01-21 07:36:17 +01:00
|
|
|
|
2018-01-22 05:35:44 +01:00
|
|
|
imageView.image = nil
|
|
|
|
nameTextField.stringValue = ""
|
|
|
|
homePageURLTextField.stringValue = ""
|
|
|
|
urlTextField.stringValue = ""
|
2018-01-21 07:36:17 +01:00
|
|
|
}
|
2018-01-21 06:35:59 +01:00
|
|
|
}
|