mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-20 14:33:04 +01:00
Make further progress on inspectors.
This commit is contained in:
parent
541a88c17a
commit
a8cee0d803
@ -8,7 +8,17 @@
|
||||
|
||||
import AppKit
|
||||
|
||||
final class BuiltinSmartFeedInspectorViewController: NSViewController {
|
||||
final class BuiltinSmartFeedInspectorViewController: NSViewController, Inspector {
|
||||
|
||||
let isFallbackInspector = false
|
||||
var objects: [Any]?
|
||||
|
||||
func canInspect(_ objects: [Any]) -> Bool {
|
||||
|
||||
return objects.count == 1 && objects.first is PseudoFeed
|
||||
}
|
||||
|
||||
func willEndInspectingObjects() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,19 @@
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import Data
|
||||
|
||||
final class FeedInspectorViewController: NSViewController {
|
||||
final class FeedInspectorViewController: NSViewController, Inspector {
|
||||
|
||||
let isFallbackInspector = false
|
||||
var objects: [Any]?
|
||||
|
||||
func canInspect(_ objects: [Any]) -> Bool {
|
||||
|
||||
return objects.count == 1 && objects.first is Feed
|
||||
}
|
||||
|
||||
func willEndInspectingObjects() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,19 @@
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import Account
|
||||
|
||||
final class FolderInspectorViewController: NSViewController {
|
||||
final class FolderInspectorViewController: NSViewController, Inspector {
|
||||
|
||||
let isFallbackInspector = false
|
||||
var objects: [Any]?
|
||||
|
||||
func canInspect(_ objects: [Any]) -> Bool {
|
||||
|
||||
return objects.count == 1 && objects.first is Folder
|
||||
}
|
||||
|
||||
func willEndInspectingObjects() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
<scene sceneID="nxk-j5-jp4">
|
||||
<objects>
|
||||
<windowController showSeguePresentationStyle="single" id="cfG-Pn-VJS" customClass="InspectorWindowController" customModule="Evergreen" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<window key="window" title="Inspector" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="bma-LM-jVu" customClass="NSPanel">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" utility="YES"/>
|
||||
<window key="window" title="Inspector" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" tabbingMode="disallowed" id="bma-LM-jVu" customClass="NSPanel">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" utility="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="314" y="928" width="256" height="256"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
|
||||
@ -35,38 +35,6 @@
|
||||
<view key="view" id="E15-dH-my9">
|
||||
<rect key="frame" x="0.0" y="0.0" width="256" height="270"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" horizontalScrollElasticity="none" translatesAutoresizingMaskIntoConstraints="NO" id="Y7h-bI-q4X">
|
||||
<rect key="frame" x="0.0" y="0.0" width="256" height="270"/>
|
||||
<clipView key="contentView" id="jKX-BM-mcT">
|
||||
<rect key="frame" x="0.0" y="0.0" width="256" height="270"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<view fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zfd-8k-OKB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="241" height="255"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
</view>
|
||||
</subviews>
|
||||
</clipView>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="256" id="E2h-fr-otm"/>
|
||||
</constraints>
|
||||
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="gtQ-f4-7Xf">
|
||||
<rect key="frame" x="-100" y="-100" width="256" height="16"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="ftW-E0-V9g">
|
||||
<rect key="frame" x="240" y="0.0" width="16" height="270"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
</scrollView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="Y7h-bI-q4X" firstAttribute="leading" secondItem="E15-dH-my9" secondAttribute="leading" id="5Wp-fI-ImY"/>
|
||||
<constraint firstAttribute="trailing" secondItem="Y7h-bI-q4X" secondAttribute="trailing" id="VNM-7e-XyN"/>
|
||||
<constraint firstAttribute="bottom" secondItem="Y7h-bI-q4X" secondAttribute="bottom" id="hAx-bV-njb"/>
|
||||
<constraint firstItem="Y7h-bI-q4X" firstAttribute="top" secondItem="E15-dH-my9" secondAttribute="top" id="oLa-0Y-yxk"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</viewController>
|
||||
<customObject id="kLX-um-NVe" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
@ -165,7 +133,7 @@ Field</string>
|
||||
<!--Folder-->
|
||||
<scene sceneID="8By-fa-WDQ">
|
||||
<objects>
|
||||
<viewController title="Folder" storyboardIdentifier="Folder" showSeguePresentationStyle="single" id="ylq-Dz-pnT" sceneMemberID="viewController">
|
||||
<viewController title="Folder" storyboardIdentifier="Folder" showSeguePresentationStyle="single" id="ylq-Dz-pnT" customClass="FolderInspectorViewController" customModule="Evergreen" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" id="DIQ-fD-5q6">
|
||||
<rect key="frame" x="0.0" y="0.0" width="256" height="152"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
@ -210,7 +178,7 @@ Field</string>
|
||||
<!--Builtin Smart Feed-->
|
||||
<scene sceneID="dFq-3d-JKW">
|
||||
<objects>
|
||||
<viewController title="Builtin Smart Feed" storyboardIdentifier="PseudoFeed" showSeguePresentationStyle="single" id="ye3-co-8lc" customClass="PseudoFeedInspectorViewController" customModule="Evergreen" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<viewController title="Builtin Smart Feed" storyboardIdentifier="BuiltinSmartFeed" showSeguePresentationStyle="single" id="ye3-co-8lc" customClass="BuiltinSmartFeedInspectorViewController" customModule="Evergreen" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" id="DXo-3M-jJQ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="256" height="113"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
|
@ -8,23 +8,83 @@
|
||||
|
||||
import AppKit
|
||||
|
||||
protocol Inspector {
|
||||
protocol Inspector: class {
|
||||
|
||||
var objects: [Any] { get set }
|
||||
var objects: [Any]? { get set }
|
||||
var isFallbackInspector: Bool { get } // Can handle nothing-to-inspect or unexpected type of objects.
|
||||
|
||||
func isInspectorFor(_ objects: [Any]) -> Bool
|
||||
func canInspect(_ objects: [Any]) -> Bool
|
||||
|
||||
func willEndInspectingObjects() // Called on the current inspector right before objects is about to change.
|
||||
}
|
||||
|
||||
final class InspectorWindowController: NSWindowController {
|
||||
|
||||
public var isOpen: Bool {
|
||||
private var inspectors: [Inspector]!
|
||||
|
||||
private var currentInspector: Inspector! {
|
||||
didSet {
|
||||
if let oldInspector = oldValue {
|
||||
oldInspector.willEndInspectingObjects()
|
||||
}
|
||||
currentInspector.objects = objects
|
||||
for inspector in inspectors {
|
||||
if inspector !== currentInspector {
|
||||
inspector.objects = nil
|
||||
}
|
||||
}
|
||||
show(currentInspector)
|
||||
}
|
||||
}
|
||||
|
||||
var objects: [Any]? {
|
||||
didSet {
|
||||
currentInspector = inspector(for: objects)
|
||||
}
|
||||
}
|
||||
|
||||
var isOpen: Bool {
|
||||
get {
|
||||
return isWindowLoaded && window!.isVisible
|
||||
}
|
||||
}
|
||||
|
||||
func inspector(for objects: [Any]) -> Inspector {
|
||||
override func windowDidLoad() {
|
||||
|
||||
let storyboard = NSStoryboard(name: NSStoryboard.Name(rawValue: "Inspector"), bundle: nil)
|
||||
let feedInspector = inspector("Feed", storyboard)
|
||||
let folderInspector = inspector("Folder", storyboard)
|
||||
let builtinSmartFeedInspector = inspector("BuiltinSmartFeed", storyboard)
|
||||
let nothingInspector = inspector("Nothing", storyboard)
|
||||
inspectors = [feedInspector, folderInspector, builtinSmartFeedInspector, nothingInspector]
|
||||
}
|
||||
|
||||
func inspector(for objects: [Any]?) -> Inspector {
|
||||
|
||||
var fallbackInspector: Inspector? = nil
|
||||
|
||||
for inspector in inspectors {
|
||||
if inspector.isFallbackInspector {
|
||||
fallbackInspector = inspector
|
||||
}
|
||||
else if let objects = objects, inspector.canInspect(objects) {
|
||||
return inspector
|
||||
}
|
||||
}
|
||||
|
||||
return fallbackInspector!
|
||||
}
|
||||
}
|
||||
|
||||
private extension InspectorWindowController {
|
||||
|
||||
func inspector(_ identifier: String, _ storyboard: NSStoryboard) -> Inspector {
|
||||
|
||||
return storyboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: identifier)) as! Inspector
|
||||
}
|
||||
|
||||
func show(_ inspector: Inspector) {
|
||||
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,17 @@
|
||||
|
||||
import AppKit
|
||||
|
||||
final class NothingInspectorViewController: NSViewController {
|
||||
final class NothingInspectorViewController: NSViewController, Inspector {
|
||||
|
||||
let isFallbackInspector = true
|
||||
var objects: [Any]?
|
||||
|
||||
func canInspect(_ objects: [Any]) -> Bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func willEndInspectingObjects() {
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user