mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-01 20:38:34 +01:00
Continue progress on feed inspector.
This commit is contained in:
parent
e4beadb84d
commit
e50055632b
@ -8,18 +8,27 @@
|
|||||||
|
|
||||||
import AppKit
|
import AppKit
|
||||||
import Data
|
import Data
|
||||||
|
import DB5
|
||||||
|
|
||||||
final class FeedInspectorViewController: NSViewController, Inspector {
|
final class FeedInspectorViewController: NSViewController, Inspector {
|
||||||
|
|
||||||
@IBOutlet var imageView: NSImageView!
|
@IBOutlet var imageView: NSImageView?
|
||||||
@IBOutlet var nameTextField: NSTextField!
|
@IBOutlet var nameTextField: NSTextField?
|
||||||
@IBOutlet var homePageURLTextField: NSTextField!
|
@IBOutlet var homePageURLTextField: NSTextField?
|
||||||
@IBOutlet var urlTextField: NSTextField!
|
@IBOutlet var urlTextField: NSTextField?
|
||||||
|
|
||||||
|
private var feed: Feed? {
|
||||||
|
didSet {
|
||||||
|
updateUI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Inspector
|
||||||
|
|
||||||
let isFallbackInspector = false
|
let isFallbackInspector = false
|
||||||
var objects: [Any]? {
|
var objects: [Any]? {
|
||||||
didSet {
|
didSet {
|
||||||
updateUI()
|
updateFeed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,69 +37,74 @@ final class FeedInspectorViewController: NSViewController, Inspector {
|
|||||||
return objects.count == 1 && objects.first is Feed
|
return objects.count == 1 && objects.first is Feed
|
||||||
}
|
}
|
||||||
|
|
||||||
func willEndInspectingObjects() {
|
// MARK: NSViewController
|
||||||
|
|
||||||
makeUIEmpty()
|
override func viewDidLoad() {
|
||||||
|
|
||||||
|
imageView!.wantsLayer = true
|
||||||
|
let cornerRadius = appDelegate.currentTheme.float(forKey: "MainWindow.Timeline.cell.avatarCornerRadius")
|
||||||
|
imageView!.layer?.cornerRadius = cornerRadius
|
||||||
|
|
||||||
|
updateUI()
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Notifications
|
||||||
|
|
||||||
|
@objc func imageDidBecomeAvailable(_ note: Notification) {
|
||||||
|
|
||||||
|
updateImage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension FeedInspectorViewController {
|
private extension FeedInspectorViewController {
|
||||||
|
|
||||||
private var feed: Feed? {
|
func updateFeed() {
|
||||||
guard let objects = objects, objects.count == 1, let feed = objects.first as? Feed else {
|
|
||||||
return nil
|
guard let objects = objects, objects.count == 1, let singleFeed = objects.first as? Feed else {
|
||||||
|
feed = nil
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return feed
|
feed = singleFeed
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUI() {
|
func updateUI() {
|
||||||
|
|
||||||
view.needsLayout = true
|
updateImage()
|
||||||
|
updateName()
|
||||||
|
updateHomePageURL()
|
||||||
|
updateFeedURL()
|
||||||
|
|
||||||
guard let feed = feed else {
|
view.needsLayout = true
|
||||||
makeUIEmpty()
|
}
|
||||||
|
|
||||||
|
func updateImage() {
|
||||||
|
|
||||||
|
guard let feed = feed, let image = image(for: feed) else {
|
||||||
|
imageView?.image = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
imageView?.image = image
|
||||||
updateImage(feed)
|
|
||||||
updateName(feed)
|
|
||||||
updateHomePageURL(feed)
|
|
||||||
updateFeedURL(feed)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateImage(_ feed: Feed) {
|
func image(for feed: Feed) -> NSImage? {
|
||||||
|
|
||||||
if let image = appDelegate.feedIconDownloader.icon(for: feed) {
|
return appDelegate.feedIconDownloader.icon(for: feed) ?? appDelegate.faviconDownloader.favicon(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) {
|
func updateName() {
|
||||||
|
|
||||||
nameTextField.stringValue = feed.editedName ?? feed.name ?? ""
|
nameTextField?.stringValue = feed?.editedName ?? feed?.name ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateHomePageURL(_ feed: Feed) {
|
func updateHomePageURL() {
|
||||||
|
|
||||||
homePageURLTextField.stringValue = feed.homePageURL ?? ""
|
homePageURLTextField?.stringValue = feed?.homePageURL ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateFeedURL(_ feed: Feed) {
|
func updateFeedURL() {
|
||||||
|
|
||||||
urlTextField.stringValue = feed.url
|
urlTextField?.stringValue = feed?.url ?? ""
|
||||||
}
|
|
||||||
|
|
||||||
func makeUIEmpty() {
|
|
||||||
|
|
||||||
imageView.image = nil
|
|
||||||
nameTextField.stringValue = ""
|
|
||||||
homePageURLTextField.stringValue = ""
|
|
||||||
urlTextField.stringValue = ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@ protocol Inspector: class {
|
|||||||
var isFallbackInspector: Bool { get } // Can handle nothing-to-inspect or unexpected type of objects.
|
var isFallbackInspector: Bool { get } // Can handle nothing-to-inspect or unexpected type of objects.
|
||||||
|
|
||||||
func canInspect(_ objects: [Any]) -> Bool
|
func canInspect(_ objects: [Any]) -> Bool
|
||||||
|
|
||||||
func willEndInspectingObjects() // Called on the current inspector right before objects is about to change.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typealias InspectorViewController = Inspector & NSViewController
|
typealias InspectorViewController = Inspector & NSViewController
|
||||||
@ -44,9 +42,6 @@ final class InspectorWindowController: NSWindowController {
|
|||||||
|
|
||||||
private var currentInspector: InspectorViewController! {
|
private var currentInspector: InspectorViewController! {
|
||||||
didSet {
|
didSet {
|
||||||
if let oldInspector = oldValue {
|
|
||||||
oldInspector.willEndInspectingObjects()
|
|
||||||
}
|
|
||||||
currentInspector.objects = objects
|
currentInspector.objects = objects
|
||||||
for inspector in inspectors {
|
for inspector in inspectors {
|
||||||
if inspector !== currentInspector {
|
if inspector !== currentInspector {
|
||||||
|
Loading…
Reference in New Issue
Block a user