From adb312bccb1bc3dda0984c16fcf2bd0192852fc2 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 4 Mar 2020 18:16:58 -0700 Subject: [PATCH] Add article state restoration. --- .../Sidebar/SidebarViewController.swift | 1 + .../Timeline/TimelineViewController.swift | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index c60f1b4d1..5f42cd10c 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -124,6 +124,7 @@ protocol SidebarDelegate: class { treeController.visitNodes(selectFeedsVisitor(node:)) outlineView.selectRowIndexes(selectIndexes, byExtendingSelection: false) + focus() isReadFiltered = coder.decodeBool(forKey: UserInfoKey.readFeedsFilterState) } diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 52fe9b57f..6e1de56b5 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -253,6 +253,10 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr readArticlesFilterState[key.userInfo] = readFilterEnabledTable[key] } coder.encode(readArticlesFilterState, forKey: UserInfoKey.readArticlesFilterState) + + if selectedArticles.count == 1 { + coder.encode(selectedArticles.first!.pathUserInfo, forKey: UserInfoKey.articlePath) + } } func restoreState(from coder: NSCoder) { @@ -263,6 +267,25 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr } } } + + guard let articlePathUserInfo = try? coder.decodeTopLevelObject(forKey: UserInfoKey.articlePath) as? [AnyHashable : Any], + let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String, + let account = AccountManager.shared.existingAccount(with: accountID), + let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else { + return + } + + if isReadFiltered ?? true { + exceptionArticleFetcher = SingleArticleFetcher(account: account, articleID: articleID) + fetchAndReplaceArticlesSync() + } + + if let selectedIndex = articles.firstIndex(where: { $0.articleID == articleID }) { + tableView.selectRow(selectedIndex) + tableView.scrollTo(row: selectedIndex) + focus() + } + } // MARK: - Actions @@ -783,6 +806,7 @@ extension TimelineViewController: NSTableViewDelegate { private func selectionDidChange(_ selectedArticles: ArticleArray?) { delegate?.timelineSelectionDidChange(self, selectedArticles: selectedArticles) + delegate?.timelineInvalidatedRestorationState(self) } private func configureTimelineCell(_ cell: TimelineTableCellView, article: Article) {