Continue progress on feed inspector.
This commit is contained in:
parent
e4beadb84d
commit
e50055632b
|
@ -8,18 +8,27 @@
|
|||
|
||||
import AppKit
|
||||
import Data
|
||||
import DB5
|
||||
|
||||
final class FeedInspectorViewController: NSViewController, Inspector {
|
||||
|
||||
@IBOutlet var imageView: NSImageView!
|
||||
@IBOutlet var nameTextField: NSTextField!
|
||||
@IBOutlet var homePageURLTextField: NSTextField!
|
||||
@IBOutlet var urlTextField: NSTextField!
|
||||
@IBOutlet var imageView: NSImageView?
|
||||
@IBOutlet var nameTextField: NSTextField?
|
||||
@IBOutlet var homePageURLTextField: NSTextField?
|
||||
@IBOutlet var urlTextField: NSTextField?
|
||||
|
||||
private var feed: Feed? {
|
||||
didSet {
|
||||
updateUI()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Inspector
|
||||
|
||||
let isFallbackInspector = false
|
||||
var objects: [Any]? {
|
||||
didSet {
|
||||
updateUI()
|
||||
updateFeed()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,69 +37,74 @@ final class FeedInspectorViewController: NSViewController, Inspector {
|
|||
return objects.count == 1 && objects.first is Feed
|
||||
}
|
||||
|
||||
func willEndInspectingObjects() {
|
||||
|
||||
makeUIEmpty()
|
||||
// MARK: NSViewController
|
||||
|
||||
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 var feed: Feed? {
|
||||
guard let objects = objects, objects.count == 1, let feed = objects.first as? Feed else {
|
||||
return nil
|
||||
func updateFeed() {
|
||||
|
||||
guard let objects = objects, objects.count == 1, let singleFeed = objects.first as? Feed else {
|
||||
feed = nil
|
||||
return
|
||||
}
|
||||
return feed
|
||||
feed = singleFeed
|
||||
}
|
||||
|
||||
func updateUI() {
|
||||
|
||||
view.needsLayout = true
|
||||
updateImage()
|
||||
updateName()
|
||||
updateHomePageURL()
|
||||
updateFeedURL()
|
||||
|
||||
guard let feed = feed else {
|
||||
makeUIEmpty()
|
||||
view.needsLayout = true
|
||||
}
|
||||
|
||||
func updateImage() {
|
||||
|
||||
guard let feed = feed, let image = image(for: feed) else {
|
||||
imageView?.image = nil
|
||||
return
|
||||
}
|
||||
|
||||
updateImage(feed)
|
||||
updateName(feed)
|
||||
updateHomePageURL(feed)
|
||||
updateFeedURL(feed)
|
||||
imageView?.image = image
|
||||
}
|
||||
|
||||
func updateImage(_ feed: Feed) {
|
||||
func image(for feed: Feed) -> NSImage? {
|
||||
|
||||
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
|
||||
}
|
||||
return appDelegate.feedIconDownloader.icon(for: feed) ?? appDelegate.faviconDownloader.favicon(for: feed)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func makeUIEmpty() {
|
||||
|
||||
imageView.image = nil
|
||||
nameTextField.stringValue = ""
|
||||
homePageURLTextField.stringValue = ""
|
||||
urlTextField.stringValue = ""
|
||||
urlTextField?.stringValue = feed?.url ?? ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ protocol Inspector: class {
|
|||
var isFallbackInspector: Bool { get } // Can handle nothing-to-inspect or unexpected type of objects.
|
||||
|
||||
func canInspect(_ objects: [Any]) -> Bool
|
||||
|
||||
func willEndInspectingObjects() // Called on the current inspector right before objects is about to change.
|
||||
}
|
||||
|
||||
typealias InspectorViewController = Inspector & NSViewController
|
||||
|
@ -44,9 +42,6 @@ final class InspectorWindowController: NSWindowController {
|
|||
|
||||
private var currentInspector: InspectorViewController! {
|
||||
didSet {
|
||||
if let oldInspector = oldValue {
|
||||
oldInspector.willEndInspectingObjects()
|
||||
}
|
||||
currentInspector.objects = objects
|
||||
for inspector in inspectors {
|
||||
if inspector !== currentInspector {
|
||||
|
|
Loading…
Reference in New Issue