mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Refactor state restoration so that the MainWindowController has control of state restoration order.
This commit is contained in:
@@ -447,13 +447,15 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
|
||||
extension MainWindowController: NSWindowDelegate {
|
||||
|
||||
func window(_ window: NSWindow, willEncodeRestorableState state: NSCoder) {
|
||||
func window(_ window: NSWindow, willEncodeRestorableState coder: NSCoder) {
|
||||
sidebarViewController?.encodeState(with: coder)
|
||||
|
||||
// saveSplitViewState(to: state)
|
||||
}
|
||||
|
||||
func window(_ window: NSWindow, didDecodeRestorableState state: NSCoder) {
|
||||
|
||||
func window(_ window: NSWindow, didDecodeRestorableState coder: NSCoder) {
|
||||
sidebarViewController?.decodeState(with: coder)
|
||||
|
||||
// restoreSplitViewState(from: state)
|
||||
//
|
||||
// // Make sure the timeline view is first responder if possible, to start out viewing
|
||||
@@ -494,6 +496,10 @@ extension MainWindowController: SidebarDelegate {
|
||||
return timelineViewController.unreadCount
|
||||
}
|
||||
|
||||
func sidebarInvalidatedRestorationState(_: SidebarViewController) {
|
||||
invalidateRestorableState()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - TimelineContainerViewControllerDelegate
|
||||
@@ -532,6 +538,10 @@ extension MainWindowController: TimelineContainerViewControllerDelegate {
|
||||
sidebarViewController?.selectFeed(webFeed)
|
||||
}
|
||||
|
||||
func timelineInvalidatedRestorationState(_: TimelineContainerViewController) {
|
||||
invalidateRestorableState()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - NSSearchFieldDelegate
|
||||
|
||||
@@ -15,6 +15,7 @@ import RSCore
|
||||
protocol SidebarDelegate: class {
|
||||
func sidebarSelectionDidChange(_: SidebarViewController, selectedObjects: [AnyObject]?)
|
||||
func unreadCount(for: AnyObject) -> Int
|
||||
func sidebarInvalidatedRestorationState(_: SidebarViewController)
|
||||
}
|
||||
|
||||
@objc class SidebarViewController: NSViewController, NSOutlineViewDelegate, NSOutlineViewDataSource, NSMenuDelegate, UndoableCommandRunner {
|
||||
@@ -38,8 +39,7 @@ protocol SidebarDelegate: class {
|
||||
}
|
||||
set {
|
||||
treeControllerDelegate.isReadFiltered = newValue
|
||||
invalidateRestorableState()
|
||||
rebuildTreeAndRestoreSelection()
|
||||
delegate?.sidebarInvalidatedRestorationState(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,12 +93,13 @@ protocol SidebarDelegate: class {
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
override func encodeRestorableState(with coder: NSCoder) {
|
||||
func encodeState(with coder: NSCoder) {
|
||||
coder.encode(isReadFiltered, forKey: UserInfoKey.readFeedsFilterState)
|
||||
}
|
||||
|
||||
override func restoreState(with coder: NSCoder) {
|
||||
func decodeState(with coder: NSCoder) {
|
||||
isReadFiltered = coder.decodeBool(forKey: UserInfoKey.readFeedsFilterState)
|
||||
rebuildTreeAndRestoreSelection()
|
||||
}
|
||||
|
||||
// MARK: - Notifications
|
||||
@@ -377,6 +378,7 @@ protocol SidebarDelegate: class {
|
||||
} else {
|
||||
isReadFiltered = true
|
||||
}
|
||||
rebuildTreeAndRestoreSelection()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import Articles
|
||||
protocol TimelineContainerViewControllerDelegate: class {
|
||||
func timelineSelectionDidChange(_: TimelineContainerViewController, articles: [Article]?, mode: TimelineSourceMode)
|
||||
func timelineRequestedWebFeedSelection(_: TimelineContainerViewController, webFeed: WebFeed)
|
||||
func timelineInvalidatedRestorationState(_: TimelineContainerViewController)
|
||||
|
||||
}
|
||||
|
||||
final class TimelineContainerViewController: NSViewController {
|
||||
@@ -91,6 +93,15 @@ final class TimelineContainerViewController: NSViewController {
|
||||
regularTimelineViewController.toggleReadFilter()
|
||||
}
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
func encodeState(with coder: NSCoder) {
|
||||
regularTimelineViewController.encodeState(with: coder)
|
||||
}
|
||||
|
||||
func decodeState(with coder: NSCoder) {
|
||||
regularTimelineViewController.decodeState(with: coder)
|
||||
}
|
||||
}
|
||||
|
||||
extension TimelineContainerViewController: TimelineDelegate {
|
||||
@@ -103,6 +114,10 @@ extension TimelineContainerViewController: TimelineDelegate {
|
||||
delegate?.timelineRequestedWebFeedSelection(self, webFeed: webFeed)
|
||||
}
|
||||
|
||||
func timelineInvalidatedRestorationState(_: TimelineViewController) {
|
||||
delegate?.timelineInvalidatedRestorationState(self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension TimelineContainerViewController {
|
||||
|
||||
@@ -15,6 +15,7 @@ import os.log
|
||||
protocol TimelineDelegate: class {
|
||||
func timelineSelectionDidChange(_: TimelineViewController, selectedArticles: [Article]?)
|
||||
func timelineRequestedWebFeedSelection(_: TimelineViewController, webFeed: WebFeed)
|
||||
func timelineInvalidatedRestorationState(_: TimelineViewController)
|
||||
}
|
||||
|
||||
final class TimelineViewController: NSViewController, UndoableCommandRunner, UnreadCountProvider {
|
||||
@@ -243,6 +244,16 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: State Restoration
|
||||
|
||||
func encodeState(with coder: NSCoder) {
|
||||
|
||||
}
|
||||
|
||||
func decodeState(with coder: NSCoder) {
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@objc func openArticleInBrowser(_ sender: Any?) {
|
||||
|
||||
Reference in New Issue
Block a user