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