NetNewsWire/Mac/Inspector/BuiltinSmartFeedInspectorVi...

72 lines
1.5 KiB
Swift
Raw Normal View History

2018-01-21 06:48:27 +01:00
//
// BuiltinSmartFeedInspectorViewController.swift
2018-08-29 07:18:24 +02:00
// NetNewsWire
2018-01-21 06:48:27 +01:00
//
// Created by Brent Simmons on 1/20/18.
// Copyright © 2018 Ranchero Software. All rights reserved.
//
import AppKit
2018-01-21 07:36:17 +01:00
final class BuiltinSmartFeedInspectorViewController: NSViewController, Inspector {
2018-01-21 06:48:27 +01:00
2018-01-22 06:24:25 +01:00
@IBOutlet var nameTextField: NSTextField?
@IBOutlet weak var smartFeedImageView: NSImageView!
2018-01-22 06:24:25 +01:00
private var smartFeed: PseudoFeed? {
didSet {
updateUI()
}
}
// MARK: Inspector
2018-01-21 07:36:17 +01:00
let isFallbackInspector = false
2018-01-22 06:24:25 +01:00
var objects: [Any]? {
didSet {
updateSmartFeed()
}
}
var windowTitle: String = NSLocalizedString("Smart Feed Inspector", comment: "Smart Feed Inspector window title")
2018-01-21 07:36:17 +01:00
func canInspect(_ objects: [Any]) -> Bool {
2018-01-22 06:24:25 +01:00
guard let _ = singleSmartFeed(from: objects) else {
return false
}
return true
}
// MARK: NSViewController
override func viewDidLoad() {
updateUI()
}
}
private extension BuiltinSmartFeedInspectorViewController {
func singleSmartFeed(from objects: [Any]?) -> PseudoFeed? {
guard let objects = objects, objects.count == 1, let singleSmartFeed = objects.first as? PseudoFeed else {
return nil
}
return singleSmartFeed
}
func updateSmartFeed() {
smartFeed = singleSmartFeed(from: objects)
2018-01-21 07:36:17 +01:00
}
2018-01-22 06:24:25 +01:00
func updateUI() {
nameTextField?.stringValue = smartFeed?.nameForDisplay ?? ""
windowTitle = smartFeed?.nameForDisplay ?? NSLocalizedString("Smart Feed Inspector", comment: "Smart Feed Inspector window title")
if #available(macOS 11.0, *) {
smartFeedImageView?.image = smartFeed?.smallIcon?.image
}
2018-01-21 07:36:17 +01:00
}
2018-01-21 06:48:27 +01:00
}