Make progress on wiring views back together to handle selection changes.
This commit is contained in:
parent
175552d113
commit
80761b4a83
|
@ -49,7 +49,7 @@ final class DetailViewController: NSViewController, WKUIDelegate {
|
|||
// MARK: - API
|
||||
|
||||
func setState(_ state: DetailState, mode: TimelineSourceMode) {
|
||||
// TODO: also to-do is caller
|
||||
webViewController(for: mode).state = state
|
||||
}
|
||||
|
||||
func canScrollDown(_ callback: @escaping (Bool) -> Void) {
|
||||
|
@ -65,14 +65,17 @@ final class DetailViewController: NSViewController, WKUIDelegate {
|
|||
|
||||
extension DetailViewController: DetailWebViewControllerDelegate {
|
||||
|
||||
func mouseDidEnter(_ link: String) {
|
||||
guard !link.isEmpty else {
|
||||
func mouseDidEnter(_ detailWebViewController: DetailWebViewController, link: String) {
|
||||
guard !link.isEmpty, detailWebViewController === currentWebViewController else {
|
||||
return
|
||||
}
|
||||
statusBarView.mouseoverLink = link
|
||||
}
|
||||
|
||||
func mouseDidExit(_ link: String) {
|
||||
func mouseDidExit(_ detailWebViewController: DetailWebViewController, link: String) {
|
||||
guard detailWebViewController === currentWebViewController else {
|
||||
return
|
||||
}
|
||||
statusBarView.mouseoverLink = nil
|
||||
}
|
||||
}
|
||||
|
@ -87,4 +90,13 @@ private extension DetailViewController {
|
|||
controller.state = .noSelection
|
||||
return controller
|
||||
}
|
||||
|
||||
func webViewController(for mode: TimelineSourceMode) -> DetailWebViewController {
|
||||
switch mode {
|
||||
case .regular:
|
||||
return regularWebViewController
|
||||
case .search:
|
||||
return searchWebViewController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ import RSWeb
|
|||
import Articles
|
||||
|
||||
protocol DetailWebViewControllerDelegate: class {
|
||||
func mouseDidEnter(_ link: String)
|
||||
func mouseDidExit(_ link: String)
|
||||
func mouseDidEnter(_: DetailWebViewController, link: String)
|
||||
func mouseDidExit(_: DetailWebViewController, link: String)
|
||||
}
|
||||
|
||||
final class DetailWebViewController: NSViewController, WKUIDelegate {
|
||||
|
@ -85,10 +85,10 @@ extension DetailWebViewController: WKScriptMessageHandler {
|
|||
|
||||
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
||||
if message.name == MessageName.mouseDidEnter, let link = message.body as? String {
|
||||
delegate?.mouseDidEnter(link)
|
||||
delegate?.mouseDidEnter(self, link: link)
|
||||
}
|
||||
else if message.name == MessageName.mouseDidExit, let link = message.body as? String{
|
||||
delegate?.mouseDidExit(link)
|
||||
delegate?.mouseDidExit(self, link: link)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
sidebarViewController.delegate = self
|
||||
|
||||
timelineContainerViewController = splitViewController?.splitViewItems[1].viewController as? TimelineContainerViewController
|
||||
timelineContainerViewController.delegate = self
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(applicationWillTerminate(_:)), name: NSApplication.willTerminateNotification, object: nil)
|
||||
|
||||
|
@ -369,7 +370,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
|
||||
extension MainWindowController: SidebarDelegate {
|
||||
|
||||
func sidebarSelectionDidChange(to selectedObjects: [AnyObject]?) {
|
||||
func sidebarSelectionDidChange(_: SidebarViewController, selectedObjects: [AnyObject]?) {
|
||||
// TODO: if searching, cancel search
|
||||
timelineContainerViewController.setRepresentedObjects(selectedObjects, mode: .regular)
|
||||
timelineContainerViewController.showTimeline(.regular)
|
||||
|
@ -378,6 +379,22 @@ extension MainWindowController: SidebarDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - TimelineContainerViewControllerDelegate
|
||||
|
||||
extension MainWindowController: TimelineContainerViewControllerDelegate {
|
||||
|
||||
func timelineSelectionDidChange(_: TimelineContainerViewController, articles: [Article]?, mode: TimelineSourceMode) {
|
||||
let detailState: DetailState
|
||||
if let articles = articles {
|
||||
detailState = articles.count == 1 ? .article(articles.first!) : .multipleSelection
|
||||
}
|
||||
else {
|
||||
detailState = .noSelection
|
||||
}
|
||||
detailViewController?.setState(detailState, mode: mode)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Scripting Access
|
||||
|
||||
/*
|
||||
|
|
|
@ -13,7 +13,7 @@ import Account
|
|||
import RSCore
|
||||
|
||||
protocol SidebarDelegate: class {
|
||||
func sidebarSelectionDidChange(to: [AnyObject]?)
|
||||
func sidebarSelectionDidChange(_: SidebarViewController, selectedObjects: [AnyObject]?)
|
||||
}
|
||||
|
||||
@objc class SidebarViewController: NSViewController, NSOutlineViewDelegate, NSOutlineViewDataSource, NSMenuDelegate, UndoableCommandRunner {
|
||||
|
@ -385,7 +385,7 @@ private extension SidebarViewController {
|
|||
}
|
||||
|
||||
func selectionDidChange(_ selectedObjects: [AnyObject]?) {
|
||||
delegate?.sidebarSelectionDidChange(to: selectedObjects)
|
||||
delegate?.sidebarSelectionDidChange(self, selectedObjects: selectedObjects)
|
||||
}
|
||||
|
||||
func updateUnreadCounts(for objects: [AnyObject]) {
|
||||
|
|
|
@ -6,12 +6,19 @@
|
|||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import AppKit
|
||||
import Articles
|
||||
|
||||
protocol TimelineContainerViewControllerDelegate: class {
|
||||
func timelineSelectionDidChange(_: TimelineContainerViewController, articles: [Article]?, mode: TimelineSourceMode)
|
||||
}
|
||||
|
||||
final class TimelineContainerViewController: NSViewController {
|
||||
|
||||
@IBOutlet var containerView: TimelineContainerView!
|
||||
|
||||
|
||||
weak var delegate: TimelineContainerViewControllerDelegate?
|
||||
|
||||
private lazy var regularTimelineViewController = {
|
||||
return TimelineViewController(delegate: self)
|
||||
}()
|
||||
|
@ -38,8 +45,8 @@ final class TimelineContainerViewController: NSViewController {
|
|||
|
||||
extension TimelineContainerViewController: TimelineDelegate {
|
||||
|
||||
func selectionDidChange(in: TimelineViewController) {
|
||||
// TODO: notify MainWindowController
|
||||
func timelineSelectionDidChange(_ timelineViewController: TimelineViewController, selectedArticles: [Article]?) {
|
||||
delegate?.timelineSelectionDidChange(self, articles: selectedArticles, mode: mode(for: timelineViewController))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,4 +60,15 @@ private extension TimelineContainerViewController {
|
|||
return searchTimelineViewController
|
||||
}
|
||||
}
|
||||
|
||||
func mode(for timelineViewController: TimelineViewController) -> TimelineSourceMode {
|
||||
if timelineViewController === regularTimelineViewController {
|
||||
return .regular
|
||||
}
|
||||
else if timelineViewController === searchTimelineViewController {
|
||||
return .search
|
||||
}
|
||||
assertionFailure("Expected timelineViewController to match either regular or search timelineViewController, but it doesn’t.")
|
||||
return .regular // Should never get here.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import Articles
|
|||
import Account
|
||||
|
||||
protocol TimelineDelegate: class {
|
||||
func selectionDidChange(in: TimelineViewController)
|
||||
func timelineSelectionDidChange(_: TimelineViewController, selectedArticles: [Article]?)
|
||||
}
|
||||
|
||||
final class TimelineViewController: NSViewController, UndoableCommandRunner {
|
||||
|
|
Loading…
Reference in New Issue