From e4beadb84d84d665f37f7d9ae22f3a0090dbd2d5 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 21 Jan 2018 20:35:44 -0800 Subject: [PATCH] Display image, name, feed URL, and home page URL in feed inspector. --- .../FeedInspectorViewController.swift | 75 ++++++++++++++++++- Evergreen/Inspector/Inspector.storyboard | 10 ++- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/Evergreen/Inspector/FeedInspectorViewController.swift b/Evergreen/Inspector/FeedInspectorViewController.swift index c30dfd02f..accbbb551 100644 --- a/Evergreen/Inspector/FeedInspectorViewController.swift +++ b/Evergreen/Inspector/FeedInspectorViewController.swift @@ -11,8 +11,17 @@ import Data final class FeedInspectorViewController: NSViewController, Inspector { + @IBOutlet var imageView: NSImageView! + @IBOutlet var nameTextField: NSTextField! + @IBOutlet var homePageURLTextField: NSTextField! + @IBOutlet var urlTextField: NSTextField! + let isFallbackInspector = false - var objects: [Any]? + var objects: [Any]? { + didSet { + updateUI() + } + } func canInspect(_ objects: [Any]) -> Bool { @@ -20,6 +29,68 @@ final class FeedInspectorViewController: NSViewController, Inspector { } func willEndInspectingObjects() { - + + 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() { + + imageView.image = nil + nameTextField.stringValue = "" + homePageURLTextField.stringValue = "" + urlTextField.stringValue = "" } } diff --git a/Evergreen/Inspector/Inspector.storyboard b/Evergreen/Inspector/Inspector.storyboard index 4e379d040..5ecb10b64 100644 --- a/Evergreen/Inspector/Inspector.storyboard +++ b/Evergreen/Inspector/Inspector.storyboard @@ -62,7 +62,7 @@ Field - + @@ -78,7 +78,7 @@ Field - + @@ -112,6 +112,12 @@ Field + + + + + +