diff --git a/NetNewsWire/MainWindow/MainWindowController.swift b/NetNewsWire/MainWindow/MainWindowController.swift index 995aeaeb0..70bda4247 100644 --- a/NetNewsWire/MainWindow/MainWindowController.swift +++ b/NetNewsWire/MainWindow/MainWindowController.swift @@ -78,11 +78,17 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations, NSW // MARK: - Notifications func window(_ window: NSWindow, willEncodeRestorableState state: NSCoder) { + saveSplitViewState(to: state) } func window(_ window: NSWindow, didDecodeRestorableState state: NSCoder) { + restoreSplitViewState(from: state) + + // Make sure the timeline view is first responder if possible, to start out viewing + // whatever preserved selection might have been restored + makeTimelineViewFirstResponder() } @objc func refreshProgressDidChange(_ note: Notification) { diff --git a/NetNewsWire/MainWindow/Sidebar/SidebarViewController.swift b/NetNewsWire/MainWindow/Sidebar/SidebarViewController.swift index 9bf6a37dd..308b51f68 100644 --- a/NetNewsWire/MainWindow/Sidebar/SidebarViewController.swift +++ b/NetNewsWire/MainWindow/Sidebar/SidebarViewController.swift @@ -70,6 +70,26 @@ import RSCore } } + // MARK: State Restoration + + private static let stateRestorationSelectedRowIndexes = "selectedRowIndexes" + + override func encodeRestorableState(with coder: NSCoder) { + + super.encodeRestorableState(with: coder) + + coder.encode(outlineView.selectedRowIndexes, forKey: SidebarViewController.stateRestorationSelectedRowIndexes) + } + + override func restoreState(with coder: NSCoder) { + + super.restoreState(with: coder) + + if let restoredRowIndexes = coder.decodeObject(of: [NSIndexSet.self], forKey: SidebarViewController.stateRestorationSelectedRowIndexes) as? IndexSet { + outlineView.selectRowIndexes(restoredRowIndexes, byExtendingSelection: false) + } + } + // MARK: - Notifications @objc func unreadCountDidChange(_ note: Notification) { @@ -278,6 +298,8 @@ import RSCore func outlineViewSelectionDidChange(_ notification: Notification) { postSidebarSelectionDidChangeNotification(selectedObjects.isEmpty ? nil : selectedObjects) + + self.invalidateRestorableState() } //MARK: - Node Manipulation diff --git a/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift b/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift index 69e285e4b..f19d47770 100644 --- a/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift +++ b/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift @@ -143,6 +143,26 @@ class TimelineViewController: NSViewController, UndoableCommandRunner { sharingServiceDelegate = SharingServiceDelegate(self.view.window) } + // MARK: State Restoration + + private static let stateRestorationSelectedArticles = "selectedArticles" + + override func encodeRestorableState(with coder: NSCoder) { + + super.encodeRestorableState(with: coder) + + coder.encode(self.selectedArticleIDs(), forKey: TimelineViewController.stateRestorationSelectedArticles) + } + + override func restoreState(with coder: NSCoder) { + + super.restoreState(with: coder) + + if let restoredArticleIDs = (try? coder.decodeTopLevelObject(forKey: TimelineViewController.stateRestorationSelectedArticles)) as? [String] { + self.restoreSelection(restoredArticleIDs) + } + } + // MARK: Appearance Change private func fontSizeDidChange() { @@ -618,6 +638,8 @@ extension TimelineViewController: NSTableViewDelegate { } postTimelineSelectionDidChangeNotification(selectedArticles) + + self.invalidateRestorableState() } private func postTimelineSelectionDidChangeNotification(_ selectedArticles: ArticleArray?) {