Make the timeline show articles.
This commit is contained in:
parent
2574e1bbd7
commit
175552d113
|
@ -37,6 +37,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
|
||||
private static var detailViewMinimumThickness = 384
|
||||
private var sidebarViewController: SidebarViewController!
|
||||
private var timelineContainerViewController: TimelineContainerViewController!
|
||||
|
||||
// MARK: - NSWindowController
|
||||
|
||||
|
@ -64,9 +65,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
|
||||
detailSplitViewItem?.minimumThickness = CGFloat(MainWindowController.detailViewMinimumThickness)
|
||||
restoreSplitViewState()
|
||||
|
||||
sidebarViewController = splitViewController?.splitViewItems[0].viewController as? SidebarViewController
|
||||
sidebarViewController.delegate = self
|
||||
|
||||
timelineContainerViewController = splitViewController?.splitViewItems[1].viewController as? TimelineContainerViewController
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(applicationWillTerminate(_:)), name: NSApplication.willTerminateNotification, object: nil)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshDidBegin, object: nil)
|
||||
|
@ -365,8 +369,10 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
|
||||
extension MainWindowController: SidebarDelegate {
|
||||
|
||||
func selectionDidChange(to selectedObjects: [AnyObject]?) {
|
||||
// TODO: communicate with TimelineViewController
|
||||
func sidebarSelectionDidChange(to selectedObjects: [AnyObject]?) {
|
||||
// TODO: if searching, cancel search
|
||||
timelineContainerViewController.setRepresentedObjects(selectedObjects, mode: .regular)
|
||||
timelineContainerViewController.showTimeline(.regular)
|
||||
updateWindowTitle()
|
||||
NotificationCenter.default.post(name: .InspectableObjectsDidChange, object: nil)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import Account
|
|||
import RSCore
|
||||
|
||||
protocol SidebarDelegate: class {
|
||||
func selectionDidChange(to: [AnyObject]?)
|
||||
func sidebarSelectionDidChange(to: [AnyObject]?)
|
||||
}
|
||||
|
||||
@objc class SidebarViewController: NSViewController, NSOutlineViewDelegate, NSOutlineViewDataSource, NSMenuDelegate, UndoableCommandRunner {
|
||||
|
@ -385,7 +385,7 @@ private extension SidebarViewController {
|
|||
}
|
||||
|
||||
func selectionDidChange(_ selectedObjects: [AnyObject]?) {
|
||||
delegate?.selectionDidChange(to: selectedObjects)
|
||||
delegate?.sidebarSelectionDidChange(to: selectedObjects)
|
||||
}
|
||||
|
||||
func updateUnreadCounts(for objects: [AnyObject]) {
|
||||
|
|
|
@ -8,17 +8,10 @@
|
|||
|
||||
import Cocoa
|
||||
|
||||
enum TimelineState {
|
||||
case empty
|
||||
case representedObjects([AnyObject])
|
||||
}
|
||||
|
||||
final class TimelineContainerViewController: NSViewController {
|
||||
|
||||
@IBOutlet var containerView: TimelineContainerView!
|
||||
|
||||
private var states: [TimelineSourceMode: TimelineState] = [.regular: .empty, .search: .empty]
|
||||
|
||||
private lazy var regularTimelineViewController = {
|
||||
return TimelineViewController(delegate: self)
|
||||
}()
|
||||
|
@ -28,17 +21,17 @@ final class TimelineContainerViewController: NSViewController {
|
|||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
setState(.empty, mode: .regular)
|
||||
showTimeline(for: .regular)
|
||||
setRepresentedObjects(nil, mode: .regular)
|
||||
showTimeline(.regular)
|
||||
}
|
||||
|
||||
// MARK: - API
|
||||
|
||||
func setState(_ state: TimelineState, mode: TimelineSourceMode) {
|
||||
timelineViewController(for: mode).state = state
|
||||
func setRepresentedObjects(_ objects: [AnyObject]?, mode: TimelineSourceMode) {
|
||||
timelineViewController(for: mode).representedObjects = objects
|
||||
}
|
||||
|
||||
func showTimeline(for mode: TimelineSourceMode) {
|
||||
func showTimeline(_ mode: TimelineSourceMode) {
|
||||
containerView.contentView = timelineViewController(for: mode).view
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
</tableColumn>
|
||||
</tableColumns>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="-2" id="zir-Wd-WsF"/>
|
||||
<outlet property="delegate" destination="-2" id="nbI-3q-mrc"/>
|
||||
<outlet property="menu" destination="zCu-LD-kHw" id="nNl-iz-nVl"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
|
|
|
@ -19,13 +19,27 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner {
|
|||
|
||||
@IBOutlet var tableView: TimelineTableView!
|
||||
|
||||
var state: TimelineState = .empty {
|
||||
var representedObjects: [AnyObject]? {
|
||||
didSet {
|
||||
switch state {
|
||||
case .empty:
|
||||
representedObjects = nil
|
||||
case .representedObjects(let updatedRepresentedObjects):
|
||||
representedObjects = updatedRepresentedObjects
|
||||
if !representedObjectArraysAreEqual(oldValue, representedObjects) {
|
||||
|
||||
if let representedObjects = representedObjects {
|
||||
if representedObjects.count == 1 && representedObjects.first is Feed {
|
||||
showFeedNames = false
|
||||
}
|
||||
else {
|
||||
showFeedNames = true
|
||||
}
|
||||
}
|
||||
else {
|
||||
showFeedNames = false
|
||||
}
|
||||
|
||||
postTimelineSelectionDidChangeNotification(nil)
|
||||
fetchArticles()
|
||||
if articles.count > 0 {
|
||||
tableView.scrollRowToVisible(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,32 +113,6 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner {
|
|||
}
|
||||
}
|
||||
|
||||
private var representedObjects: [AnyObject]? {
|
||||
didSet {
|
||||
if !representedObjectArraysAreEqual(oldValue, representedObjects) {
|
||||
|
||||
if let representedObjects = representedObjects {
|
||||
if representedObjects.count == 1 && representedObjects.first is Feed {
|
||||
showFeedNames = false
|
||||
}
|
||||
else {
|
||||
showFeedNames = true
|
||||
}
|
||||
}
|
||||
else {
|
||||
showFeedNames = false
|
||||
}
|
||||
|
||||
postTimelineSelectionDidChangeNotification(nil)
|
||||
articles = ArticleArray()
|
||||
fetchArticles()
|
||||
if articles.count > 0 {
|
||||
tableView.scrollRowToVisible(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var oneSelectedArticle: Article? {
|
||||
return selectedArticles.count == 1 ? selectedArticles.first : nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue