diff --git a/Evergreen/AppDelegate.swift b/Evergreen/AppDelegate.swift index a6ab0d675..b57ebbd8b 100644 --- a/Evergreen/AppDelegate.swift +++ b/Evergreen/AppDelegate.swift @@ -69,6 +69,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, dockBadge.appDelegate = self NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(sidebarSelectionDidChange(_:)), name: .SidebarSelectionDidChange, object: nil) + appDelegate = self } @@ -195,6 +197,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, let _ = faviconDownloader.favicon(for: feed) } + @objc func sidebarSelectionDidChange(_ note: Notification) { + + guard let inspectorWindowController = inspectorWindowController, inspectorWindowController.isOpen else { + return + } + inspectorWindowController.objects = objectsForInspector() + } + // MARK: Main Window func windowControllerWithName(_ storyboardName: String) -> NSWindowController { @@ -310,13 +320,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, inspectorWindowController!.window!.performClose(self) } else { - var selectedObjects: [Any]? = nil - if let window = NSApplication.shared.mainWindow { - if let windowController = window.windowController as? MainWindowController { - selectedObjects = windowController.selectedObjectsInSidebar() - } - } - inspectorWindowController!.objects = selectedObjects + inspectorWindowController!.objects = objectsForInspector() inspectorWindowController!.showWindow(self) } } @@ -432,4 +436,12 @@ private extension AppDelegate { return windowControllerWithName("MainWindow") } + + func objectsForInspector() -> [Any]? { + + guard let window = NSApplication.shared.mainWindow, let windowController = window.windowController as? MainWindowController else { + return nil + } + return windowController.selectedObjectsInSidebar() + } } diff --git a/Evergreen/Inspector/Inspector.storyboard b/Evergreen/Inspector/Inspector.storyboard index 1219101ba..92f7fc906 100644 --- a/Evergreen/Inspector/Inspector.storyboard +++ b/Evergreen/Inspector/Inspector.storyboard @@ -8,8 +8,8 @@ - - + + diff --git a/Evergreen/Inspector/InspectorWindowController.swift b/Evergreen/Inspector/InspectorWindowController.swift index 57ee5f5a5..723fc4af7 100644 --- a/Evergreen/Inspector/InspectorWindowController.swift +++ b/Evergreen/Inspector/InspectorWindowController.swift @@ -64,6 +64,8 @@ final class InspectorWindowController: NSWindowController { inspectors = [feedInspector, folderInspector, builtinSmartFeedInspector, nothingInspector] currentInspector = nothingInspector + + window?.flippedOrigin = NSPoint(x: 128, y: 128) } func inspector(for objects: [Any]?) -> InspectorViewController { @@ -95,6 +97,12 @@ private extension InspectorWindowController { guard let window = window, inspector !== window.contentViewController else { return } + + let flippedOrigin = window.flippedOrigin window.contentViewController = inspector + window.layoutIfNeeded() + if let origin = flippedOrigin { + window.setFlippedOriginAdjustingForScreen(origin) + } } } diff --git a/Frameworks/RSCore/RSCore/NSWindow-Extensions.swift b/Frameworks/RSCore/RSCore/NSWindow-Extensions.swift index 400f00ddf..b5f21a28d 100755 --- a/Frameworks/RSCore/RSCore/NSWindow-Extensions.swift +++ b/Frameworks/RSCore/RSCore/NSWindow-Extensions.swift @@ -45,4 +45,42 @@ public extension NSWindow { setFrame(frame, display: true) setFrameTopLeftPoint(frame.origin) } + + public var flippedOrigin: NSPoint? { + + // Screen coordinates start at lower-left. + // With this we can use upper-left, like sane people. + + get { + guard let screenFrame = screen?.frame else { + return nil + } + + let flippedPoint = NSPoint(x: frame.origin.x, y: screenFrame.maxY - frame.maxY) + return flippedPoint + } + set { + guard let screenFrame = screen?.frame else { + return + } + var point = newValue! + point.y = screenFrame.maxY - point.y + setFrameTopLeftPoint(point) + } + } + + public func setFlippedOriginAdjustingForScreen(_ point: NSPoint) { + + guard let screenFrame = screen?.frame else { + return + } + + let paddingFromBottomEdge: CGFloat = 8.0 + var unflippedPoint = point + unflippedPoint.y = (screenFrame.maxY - point.y) - frame.height + if unflippedPoint.y < 0 { + unflippedPoint.y = paddingFromBottomEdge + } + setFrameOrigin(unflippedPoint) + } }