mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-08 16:18:48 +01:00
Keep the inspector’s top-left origin steady on changing views.
This commit is contained in:
parent
394274f1e5
commit
ca5703e14f
@ -69,6 +69,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||||||
dockBadge.appDelegate = self
|
dockBadge.appDelegate = self
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(sidebarSelectionDidChange(_:)), name: .SidebarSelectionDidChange, object: nil)
|
||||||
|
|
||||||
appDelegate = self
|
appDelegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +197,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||||||
let _ = faviconDownloader.favicon(for: feed)
|
let _ = faviconDownloader.favicon(for: feed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func sidebarSelectionDidChange(_ note: Notification) {
|
||||||
|
|
||||||
|
guard let inspectorWindowController = inspectorWindowController, inspectorWindowController.isOpen else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
inspectorWindowController.objects = objectsForInspector()
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Main Window
|
// MARK: Main Window
|
||||||
|
|
||||||
func windowControllerWithName(_ storyboardName: String) -> NSWindowController {
|
func windowControllerWithName(_ storyboardName: String) -> NSWindowController {
|
||||||
@ -310,13 +320,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
|||||||
inspectorWindowController!.window!.performClose(self)
|
inspectorWindowController!.window!.performClose(self)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var selectedObjects: [Any]? = nil
|
inspectorWindowController!.objects = objectsForInspector()
|
||||||
if let window = NSApplication.shared.mainWindow {
|
|
||||||
if let windowController = window.windowController as? MainWindowController {
|
|
||||||
selectedObjects = windowController.selectedObjectsInSidebar()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inspectorWindowController!.objects = selectedObjects
|
|
||||||
inspectorWindowController!.showWindow(self)
|
inspectorWindowController!.showWindow(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -432,4 +436,12 @@ private extension AppDelegate {
|
|||||||
|
|
||||||
return windowControllerWithName("MainWindow")
|
return windowControllerWithName("MainWindow")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func objectsForInspector() -> [Any]? {
|
||||||
|
|
||||||
|
guard let window = NSApplication.shared.mainWindow, let windowController = window.windowController as? MainWindowController else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return windowController.selectedObjectsInSidebar()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
<!--Window Controller-->
|
<!--Window Controller-->
|
||||||
<scene sceneID="nxk-j5-jp4">
|
<scene sceneID="nxk-j5-jp4">
|
||||||
<objects>
|
<objects>
|
||||||
<windowController showSeguePresentationStyle="single" id="cfG-Pn-VJS" customClass="InspectorWindowController" customModule="Evergreen" customModuleProvider="target" sceneMemberID="viewController">
|
<windowController storyboardIdentifier="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" tabbingMode="disallowed" id="bma-LM-jVu" customClass="NSPanel">
|
<window key="window" identifier="InspectorPanel" 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"/>
|
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" utility="YES"/>
|
||||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="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="contentRect" x="314" y="928" width="256" height="256"/>
|
||||||
|
@ -64,6 +64,8 @@ final class InspectorWindowController: NSWindowController {
|
|||||||
|
|
||||||
inspectors = [feedInspector, folderInspector, builtinSmartFeedInspector, nothingInspector]
|
inspectors = [feedInspector, folderInspector, builtinSmartFeedInspector, nothingInspector]
|
||||||
currentInspector = nothingInspector
|
currentInspector = nothingInspector
|
||||||
|
|
||||||
|
window?.flippedOrigin = NSPoint(x: 128, y: 128)
|
||||||
}
|
}
|
||||||
|
|
||||||
func inspector(for objects: [Any]?) -> InspectorViewController {
|
func inspector(for objects: [Any]?) -> InspectorViewController {
|
||||||
@ -95,6 +97,12 @@ private extension InspectorWindowController {
|
|||||||
guard let window = window, inspector !== window.contentViewController else {
|
guard let window = window, inspector !== window.contentViewController else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let flippedOrigin = window.flippedOrigin
|
||||||
window.contentViewController = inspector
|
window.contentViewController = inspector
|
||||||
|
window.layoutIfNeeded()
|
||||||
|
if let origin = flippedOrigin {
|
||||||
|
window.setFlippedOriginAdjustingForScreen(origin)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,4 +45,42 @@ public extension NSWindow {
|
|||||||
setFrame(frame, display: true)
|
setFrame(frame, display: true)
|
||||||
setFrameTopLeftPoint(frame.origin)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user