2019-02-15 06:47:08 +01:00
|
|
|
|
//
|
2019-02-15 06:58:45 +01:00
|
|
|
|
// TimelineContainerViewController.swift
|
2019-02-15 06:47:08 +01:00
|
|
|
|
// NetNewsWire
|
|
|
|
|
//
|
|
|
|
|
// Created by Brent Simmons on 2/14/19.
|
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2019-02-18 06:43:51 +01:00
|
|
|
|
import AppKit
|
|
|
|
|
import Articles
|
|
|
|
|
|
|
|
|
|
protocol TimelineContainerViewControllerDelegate: class {
|
|
|
|
|
func timelineSelectionDidChange(_: TimelineContainerViewController, articles: [Article]?, mode: TimelineSourceMode)
|
|
|
|
|
}
|
2019-02-15 06:47:08 +01:00
|
|
|
|
|
2019-02-17 07:14:06 +01:00
|
|
|
|
final class TimelineContainerViewController: NSViewController {
|
|
|
|
|
|
|
|
|
|
@IBOutlet var containerView: TimelineContainerView!
|
2019-02-18 06:43:51 +01:00
|
|
|
|
|
2019-02-18 21:38:14 +01:00
|
|
|
|
var currentTimelineViewController: TimelineViewController? {
|
|
|
|
|
didSet {
|
|
|
|
|
let view = currentTimelineViewController?.view
|
|
|
|
|
if containerView.contentView === view {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
containerView.contentView = view
|
2019-03-04 00:55:54 +01:00
|
|
|
|
view?.window?.recalculateKeyViewLoop()
|
2019-02-18 21:38:14 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-18 06:43:51 +01:00
|
|
|
|
weak var delegate: TimelineContainerViewControllerDelegate?
|
|
|
|
|
|
2019-02-17 07:14:06 +01:00
|
|
|
|
private lazy var regularTimelineViewController = {
|
|
|
|
|
return TimelineViewController(delegate: self)
|
|
|
|
|
}()
|
2019-07-06 05:06:31 +02:00
|
|
|
|
private lazy var searchTimelineViewController: TimelineViewController = {
|
|
|
|
|
let viewController = TimelineViewController(delegate: self)
|
|
|
|
|
viewController.showsSearchResults = true
|
|
|
|
|
return viewController
|
2019-02-17 07:14:06 +01:00
|
|
|
|
}()
|
2019-02-15 06:47:08 +01:00
|
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
2019-02-18 04:38:17 +01:00
|
|
|
|
setRepresentedObjects(nil, mode: .regular)
|
2019-02-25 07:39:57 +01:00
|
|
|
|
showTimeline(for: .regular)
|
2019-02-15 06:47:08 +01:00
|
|
|
|
}
|
2019-02-17 07:14:06 +01:00
|
|
|
|
|
|
|
|
|
// MARK: - API
|
|
|
|
|
|
2019-02-18 04:38:17 +01:00
|
|
|
|
func setRepresentedObjects(_ objects: [AnyObject]?, mode: TimelineSourceMode) {
|
|
|
|
|
timelineViewController(for: mode).representedObjects = objects
|
2019-02-17 07:14:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-25 07:39:57 +01:00
|
|
|
|
func showTimeline(for mode: TimelineSourceMode) {
|
2019-02-18 21:38:14 +01:00
|
|
|
|
currentTimelineViewController = timelineViewController(for: mode)
|
2019-02-17 07:14:06 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension TimelineContainerViewController: TimelineDelegate {
|
|
|
|
|
|
2019-02-18 06:43:51 +01:00
|
|
|
|
func timelineSelectionDidChange(_ timelineViewController: TimelineViewController, selectedArticles: [Article]?) {
|
|
|
|
|
delegate?.timelineSelectionDidChange(self, articles: selectedArticles, mode: mode(for: timelineViewController))
|
2019-02-17 07:14:06 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private extension TimelineContainerViewController {
|
|
|
|
|
|
|
|
|
|
func timelineViewController(for mode: TimelineSourceMode) -> TimelineViewController {
|
|
|
|
|
switch mode {
|
|
|
|
|
case .regular:
|
|
|
|
|
return regularTimelineViewController
|
|
|
|
|
case .search:
|
|
|
|
|
return searchTimelineViewController
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-18 06:43:51 +01:00
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
}
|
2019-02-15 06:47:08 +01:00
|
|
|
|
}
|