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