2018-01-21 04:06:07 +01:00
|
|
|
//
|
|
|
|
// FeedInspectorViewController.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2018-01-21 04:06:07 +01:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 1/20/18.
|
|
|
|
// Copyright © 2018 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import AppKit
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2018-07-28 21:16:14 +02:00
|
|
|
import Account
|
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
|
|
|
|
2019-10-03 02:42:16 +02:00
|
|
|
@IBOutlet weak var imageView: NSImageView?
|
|
|
|
@IBOutlet weak var nameTextField: NSTextField?
|
|
|
|
@IBOutlet weak var homePageURLTextField: NSTextField?
|
|
|
|
@IBOutlet weak var urlTextField: NSTextField?
|
|
|
|
@IBOutlet weak var isNotifyAboutNewArticlesCheckBox: NSButton!
|
2019-09-20 02:49:11 +02:00
|
|
|
@IBOutlet weak var isReaderViewAlwaysOnCheckBox: NSButton?
|
|
|
|
|
2018-01-22 06:01:18 +01:00
|
|
|
private var feed: Feed? {
|
|
|
|
didSet {
|
2018-01-22 06:24:25 +01:00
|
|
|
if feed != oldValue {
|
|
|
|
updateUI()
|
|
|
|
}
|
2018-01-22 06:01:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Inspector
|
2018-01-22 05:35:44 +01:00
|
|
|
|
2018-01-21 07:36:17 +01:00
|
|
|
let isFallbackInspector = false
|
2018-01-22 05:35:44 +01:00
|
|
|
var objects: [Any]? {
|
|
|
|
didSet {
|
2018-01-22 06:01:18 +01:00
|
|
|
updateFeed()
|
2018-01-22 05:35:44 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-21 07:36:17 +01:00
|
|
|
|
|
|
|
func canInspect(_ objects: [Any]) -> Bool {
|
|
|
|
return objects.count == 1 && objects.first is Feed
|
|
|
|
}
|
|
|
|
|
2018-01-22 06:01:18 +01:00
|
|
|
// MARK: NSViewController
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
imageView!.wantsLayer = true
|
2019-04-13 21:18:55 +02:00
|
|
|
imageView!.layer?.cornerRadius = 4.0
|
2018-01-22 06:01:18 +01:00
|
|
|
|
|
|
|
updateUI()
|
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: nil)
|
|
|
|
}
|
|
|
|
|
2019-09-20 02:49:11 +02:00
|
|
|
// MARK: Actions
|
2019-10-03 02:42:16 +02:00
|
|
|
@IBAction func isNotifyAboutNewArticlesChanged(_ sender: Any) {
|
|
|
|
feed?.isNotifyAboutNewArticles = (isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false
|
|
|
|
}
|
|
|
|
|
2019-09-20 02:49:11 +02:00
|
|
|
@IBAction func isReaderViewAlwaysOnChanged(_ sender: Any) {
|
|
|
|
feed?.isArticleExtractorAlwaysOn = (isReaderViewAlwaysOnCheckBox?.state ?? .off) == .on ? true : false
|
|
|
|
}
|
|
|
|
|
2018-01-22 06:01:18 +01:00
|
|
|
// MARK: Notifications
|
|
|
|
|
|
|
|
@objc func imageDidBecomeAvailable(_ note: Notification) {
|
|
|
|
updateImage()
|
2018-01-22 05:35:44 +01:00
|
|
|
}
|
2019-09-20 02:49:11 +02:00
|
|
|
|
2018-01-22 05:35:44 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 06:31:26 +01:00
|
|
|
extension FeedInspectorViewController: NSTextFieldDelegate {
|
|
|
|
|
2018-12-09 21:32:33 +01:00
|
|
|
func controlTextDidChange(_ note: Notification) {
|
2018-01-24 06:49:33 +01:00
|
|
|
guard let feed = feed, let nameTextField = nameTextField else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
feed.editedName = nameTextField.stringValue
|
|
|
|
}
|
2019-09-20 02:49:11 +02:00
|
|
|
|
2018-01-22 06:31:26 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 05:35:44 +01:00
|
|
|
private extension FeedInspectorViewController {
|
|
|
|
|
2018-01-22 06:01:18 +01:00
|
|
|
func updateFeed() {
|
|
|
|
guard let objects = objects, objects.count == 1, let singleFeed = objects.first as? Feed else {
|
|
|
|
feed = nil
|
|
|
|
return
|
2018-01-22 05:35:44 +01:00
|
|
|
}
|
2018-01-22 06:01:18 +01:00
|
|
|
feed = singleFeed
|
2018-01-22 05:35:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func updateUI() {
|
2018-01-22 06:01:18 +01:00
|
|
|
updateImage()
|
|
|
|
updateName()
|
|
|
|
updateHomePageURL()
|
|
|
|
updateFeedURL()
|
2019-10-03 02:42:16 +02:00
|
|
|
updateNotifyAboutNewArticles()
|
2019-09-20 02:49:11 +02:00
|
|
|
updateIsReaderViewAlwaysOn()
|
|
|
|
|
2018-01-22 06:01:18 +01:00
|
|
|
view.needsLayout = true
|
2018-01-22 05:35:44 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 06:01:18 +01:00
|
|
|
func updateImage() {
|
2018-01-22 06:04:52 +01:00
|
|
|
guard let feed = feed else {
|
2018-01-22 06:01:18 +01:00
|
|
|
imageView?.image = nil
|
|
|
|
return
|
2018-01-22 05:35:44 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 06:04:52 +01:00
|
|
|
if let feedIcon = appDelegate.feedIconDownloader.icon(for: feed) {
|
|
|
|
imageView?.image = feedIcon
|
|
|
|
return
|
|
|
|
}
|
2018-01-22 06:24:25 +01:00
|
|
|
|
2018-01-22 06:04:52 +01:00
|
|
|
if let favicon = appDelegate.faviconDownloader.favicon(for: feed) {
|
|
|
|
if favicon.size.height < 16.0 && favicon.size.width < 16.0 {
|
|
|
|
favicon.size = NSSize(width: 16, height: 16)
|
|
|
|
}
|
|
|
|
imageView?.image = favicon
|
|
|
|
return
|
|
|
|
}
|
2018-01-22 05:35:44 +01:00
|
|
|
|
2019-05-21 12:42:40 +02:00
|
|
|
imageView?.image = AppAssets.genericFeedImage
|
2018-01-22 05:35:44 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 06:01:18 +01:00
|
|
|
func updateName() {
|
2018-01-23 07:01:25 +01:00
|
|
|
guard let nameTextField = nameTextField else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let name = feed?.editedName ?? feed?.name ?? ""
|
|
|
|
if nameTextField.stringValue != name {
|
|
|
|
nameTextField.stringValue = name
|
|
|
|
}
|
2018-01-22 05:35:44 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 06:01:18 +01:00
|
|
|
func updateHomePageURL() {
|
|
|
|
homePageURLTextField?.stringValue = feed?.homePageURL ?? ""
|
2018-01-22 05:35:44 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 06:01:18 +01:00
|
|
|
func updateFeedURL() {
|
|
|
|
urlTextField?.stringValue = feed?.url ?? ""
|
2018-01-21 07:36:17 +01:00
|
|
|
}
|
2019-09-20 02:49:11 +02:00
|
|
|
|
2019-10-03 02:42:16 +02:00
|
|
|
func updateNotifyAboutNewArticles() {
|
|
|
|
isNotifyAboutNewArticlesCheckBox?.state = (feed?.isNotifyAboutNewArticles ?? false) ? .on : .off
|
|
|
|
}
|
|
|
|
|
2019-09-20 02:49:11 +02:00
|
|
|
func updateIsReaderViewAlwaysOn() {
|
|
|
|
isReaderViewAlwaysOnCheckBox?.state = (feed?.isArticleExtractorAlwaysOn ?? false) ? .on : .off
|
|
|
|
}
|
2018-01-21 06:35:59 +01:00
|
|
|
}
|