Stubbed out menu item keyboard shortcuts and implemented the numbered ones

This commit is contained in:
Maurice Parker
2019-09-05 13:14:14 -05:00
parent 8a5ae8c2a8
commit ac37443dbb
4 changed files with 90 additions and 19 deletions

View File

@@ -421,6 +421,21 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
}
}
func ensureSectionIsExpanded(_ sectionIndex: Int, completion: (() -> Void)? = nil) {
guard let sectionNode = coordinator.rootNode.childAtIndex(sectionIndex) else {
return
}
if !coordinator.isExpanded(sectionNode) {
coordinator.expand(section: sectionIndex)
self.applyChanges(animate: true) {
completion?()
}
} else {
completion?()
}
}
func discloseFeed(_ feed: Feed, completion: (() -> Void)? = nil) {
guard let node = coordinator.rootNode.descendantNodeRepresentingObject(feed as AnyObject) else {
@@ -481,12 +496,10 @@ private extension MasterFeedViewController {
}
func reloadNode(_ node: Node) {
let savedNode = selectedNode()
var snapshot = dataSource.snapshot()
snapshot.reloadItems([node])
dataSource.apply(snapshot, animatingDifferences: false) { [weak self] in
self?.selectRow(node: savedNode)
self?.restoreSelectionIfNecessary()
}
}
@@ -504,21 +517,6 @@ private extension MasterFeedViewController {
completion?()
}
}
func selectedNode() -> Node? {
if let selectedIndexPath = tableView.indexPathForSelectedRow {
return coordinator.nodeFor(selectedIndexPath)
} else {
return nil
}
}
func selectRow(node: Node?) {
if let nodeToSelect = node, let selectingIndexPath = coordinator.indexPathFor(nodeToSelect) {
tableView.selectRow(at: selectingIndexPath, animated: false, scrollPosition: .none)
}
}
func makeDataSource() -> UITableViewDiffableDataSource<Int, Node> {
return MasterFeedDataSource(coordinator: coordinator, errorHandler: ErrorHandler.present(self), tableView: tableView, cellProvider: { [weak self] tableView, indexPath, node in