diff --git a/Evergreen/Inspector/BuiltinSmartFeedInspectorViewController.swift b/Evergreen/Inspector/BuiltinSmartFeedInspectorViewController.swift index 7d850251a..0b6510ade 100644 --- a/Evergreen/Inspector/BuiltinSmartFeedInspectorViewController.swift +++ b/Evergreen/Inspector/BuiltinSmartFeedInspectorViewController.swift @@ -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() { + + } } diff --git a/Evergreen/Inspector/FeedInspectorViewController.swift b/Evergreen/Inspector/FeedInspectorViewController.swift index 2055f6e86..c30dfd02f 100644 --- a/Evergreen/Inspector/FeedInspectorViewController.swift +++ b/Evergreen/Inspector/FeedInspectorViewController.swift @@ -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() { + + } } diff --git a/Evergreen/Inspector/FolderInspectorViewController.swift b/Evergreen/Inspector/FolderInspectorViewController.swift index 886afe6fa..fca41698c 100644 --- a/Evergreen/Inspector/FolderInspectorViewController.swift +++ b/Evergreen/Inspector/FolderInspectorViewController.swift @@ -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() { + + } } diff --git a/Evergreen/Inspector/Inspector.storyboard b/Evergreen/Inspector/Inspector.storyboard index e146aea9a..1a6cf27f0 100644 --- a/Evergreen/Inspector/Inspector.storyboard +++ b/Evergreen/Inspector/Inspector.storyboard @@ -9,8 +9,8 @@ - - + + @@ -35,38 +35,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -165,7 +133,7 @@ Field - + @@ -210,7 +178,7 @@ Field - + diff --git a/Evergreen/Inspector/InspectorWindowController.swift b/Evergreen/Inspector/InspectorWindowController.swift index 7ed82a899..3b0c9d94e 100644 --- a/Evergreen/Inspector/InspectorWindowController.swift +++ b/Evergreen/Inspector/InspectorWindowController.swift @@ -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 } } diff --git a/Evergreen/Inspector/NothingInspectorViewController.swift b/Evergreen/Inspector/NothingInspectorViewController.swift index ac1cf4d00..be22ffbf2 100644 --- a/Evergreen/Inspector/NothingInspectorViewController.swift +++ b/Evergreen/Inspector/NothingInspectorViewController.swift @@ -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() { + + } }