2017-05-27 10:43:27 -07:00
|
|
|
//
|
|
|
|
// DetailViewController.swift
|
2018-08-28 22:18:24 -07:00
|
|
|
// NetNewsWire
|
2017-05-27 10:43:27 -07:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 7/26/15.
|
|
|
|
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import WebKit
|
|
|
|
import RSCore
|
2018-07-23 18:29:08 -07:00
|
|
|
import Articles
|
2017-12-03 12:13:44 -08:00
|
|
|
import RSWeb
|
2017-05-27 10:43:27 -07:00
|
|
|
|
2019-02-12 22:57:19 -08:00
|
|
|
enum DetailState: Equatable {
|
|
|
|
case noSelection
|
|
|
|
case multipleSelection
|
|
|
|
case article(Article)
|
|
|
|
}
|
|
|
|
|
2018-02-18 21:49:46 -08:00
|
|
|
final class DetailViewController: NSViewController, WKUIDelegate {
|
2017-11-05 20:31:50 -08:00
|
|
|
|
2017-12-16 10:18:02 -08:00
|
|
|
@IBOutlet var containerView: DetailContainerView!
|
2019-02-10 21:39:11 -08:00
|
|
|
@IBOutlet var statusBarView: DetailStatusBarView!
|
2017-12-03 12:38:44 -08:00
|
|
|
|
2019-02-12 22:57:19 -08:00
|
|
|
lazy var regularWebViewController = {
|
|
|
|
return createWebViewController()
|
|
|
|
}()
|
|
|
|
|
|
|
|
lazy var searchWebViewController = {
|
|
|
|
return createWebViewController()
|
|
|
|
}()
|
|
|
|
|
|
|
|
var currentWebViewController: DetailWebViewController! {
|
2018-02-18 21:49:46 -08:00
|
|
|
didSet {
|
2019-02-12 22:57:19 -08:00
|
|
|
let webview = currentWebViewController.view
|
|
|
|
if containerView.contentView === webview {
|
2018-02-18 21:49:46 -08:00
|
|
|
return
|
|
|
|
}
|
2019-02-10 21:39:11 -08:00
|
|
|
statusBarView.mouseoverLink = nil
|
2019-02-12 22:57:19 -08:00
|
|
|
containerView.contentView = webview
|
2018-02-18 21:49:46 -08:00
|
|
|
}
|
|
|
|
}
|
2019-02-10 21:46:53 -08:00
|
|
|
|
2017-05-27 10:43:27 -07:00
|
|
|
override func viewDidLoad() {
|
2019-02-12 22:57:19 -08:00
|
|
|
currentWebViewController = regularWebViewController
|
2017-05-27 10:43:27 -07:00
|
|
|
}
|
|
|
|
|
2019-02-12 22:57:19 -08:00
|
|
|
// MARK: - API
|
2019-02-11 22:36:31 -08:00
|
|
|
|
2019-02-16 22:14:06 -08:00
|
|
|
func setState(_ state: DetailState, mode: TimelineSourceMode) {
|
2019-02-17 21:43:51 -08:00
|
|
|
webViewController(for: mode).state = state
|
2019-02-12 22:57:19 -08:00
|
|
|
}
|
2017-12-20 13:39:31 -08:00
|
|
|
|
2019-02-24 22:39:57 -08:00
|
|
|
func showDetail(for mode: TimelineSourceMode) {
|
|
|
|
currentWebViewController = webViewController(for: mode)
|
|
|
|
}
|
|
|
|
|
2017-12-20 13:39:31 -08:00
|
|
|
func canScrollDown(_ callback: @escaping (Bool) -> Void) {
|
2019-02-12 22:57:19 -08:00
|
|
|
currentWebViewController.canScrollDown(callback)
|
2017-12-20 13:39:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
override func scrollPageDown(_ sender: Any?) {
|
2019-02-12 22:57:19 -08:00
|
|
|
currentWebViewController.scrollPageDown(sender)
|
2017-05-27 10:43:27 -07:00
|
|
|
}
|
2019-03-01 16:56:40 -06:00
|
|
|
|
|
|
|
// MARK: - Navigation
|
|
|
|
|
|
|
|
func focus() {
|
|
|
|
|
2019-09-11 17:47:02 -05:00
|
|
|
guard let window = currentWebViewController.webView.window else {
|
2019-03-01 16:56:40 -06:00
|
|
|
return
|
|
|
|
}
|
2019-09-11 17:47:02 -05:00
|
|
|
window.makeFirstResponderUnlessDescendantIsFirstResponder(currentWebViewController.webView)
|
2019-03-01 16:56:40 -06:00
|
|
|
}
|
|
|
|
|
2017-05-27 10:43:27 -07:00
|
|
|
}
|
|
|
|
|
2019-02-12 22:57:19 -08:00
|
|
|
// MARK: - DetailWebViewControllerDelegate
|
2019-02-12 18:12:12 -08:00
|
|
|
|
|
|
|
extension DetailViewController: DetailWebViewControllerDelegate {
|
2017-11-05 20:31:50 -08:00
|
|
|
|
2019-02-17 21:43:51 -08:00
|
|
|
func mouseDidEnter(_ detailWebViewController: DetailWebViewController, link: String) {
|
|
|
|
guard !link.isEmpty, detailWebViewController === currentWebViewController else {
|
2017-11-05 20:31:50 -08:00
|
|
|
return
|
|
|
|
}
|
2019-02-10 21:39:11 -08:00
|
|
|
statusBarView.mouseoverLink = link
|
2017-11-05 20:31:50 -08:00
|
|
|
}
|
|
|
|
|
2019-02-17 21:43:51 -08:00
|
|
|
func mouseDidExit(_ detailWebViewController: DetailWebViewController, link: String) {
|
|
|
|
guard detailWebViewController === currentWebViewController else {
|
|
|
|
return
|
|
|
|
}
|
2019-02-10 21:39:11 -08:00
|
|
|
statusBarView.mouseoverLink = nil
|
2017-11-05 20:31:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 22:57:19 -08:00
|
|
|
// MARK: - Private
|
2018-02-18 21:49:46 -08:00
|
|
|
|
2017-12-20 13:39:31 -08:00
|
|
|
private extension DetailViewController {
|
|
|
|
|
2019-02-12 22:57:19 -08:00
|
|
|
func createWebViewController() -> DetailWebViewController {
|
|
|
|
let controller = DetailWebViewController()
|
|
|
|
controller.delegate = self
|
|
|
|
controller.state = .noSelection
|
|
|
|
return controller
|
2017-12-20 13:39:31 -08:00
|
|
|
}
|
2019-02-17 21:43:51 -08:00
|
|
|
|
|
|
|
func webViewController(for mode: TimelineSourceMode) -> DetailWebViewController {
|
|
|
|
switch mode {
|
|
|
|
case .regular:
|
|
|
|
return regularWebViewController
|
|
|
|
case .search:
|
|
|
|
return searchWebViewController
|
|
|
|
}
|
|
|
|
}
|
2017-12-20 13:39:31 -08:00
|
|
|
}
|