Fix #547 by implementing state restoration in the sidebar and timeline view controllers.
This commit is contained in:
parent
cd695848f0
commit
c54d2f94cc
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?) {
|
||||
|
|
Loading…
Reference in New Issue