Refactor state restoration so that the MainWindowController has control of state restoration order.

This commit is contained in:
Maurice Parker
2020-03-03 10:54:37 -08:00
parent e920235038
commit 72e5915fb8
4 changed files with 45 additions and 7 deletions

View File

@@ -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

View File

@@ -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()
}
}

View File

@@ -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 {

View File

@@ -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?) {