Add expand and collapse all folders shortcuts

This commit is contained in:
Maurice Parker 2019-09-05 16:38:33 -05:00
parent 734ce4bc67
commit 6d24ea642a
2 changed files with 39 additions and 4 deletions

View File

@ -418,6 +418,16 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
}
}
@objc func expandAll(_ sender: Any?) {
coordinator.expandAllSectionsAndFolders()
self.applyChanges(animate: true)
}
@objc func collapseAllExceptForGroupItems(_ sender: Any?) {
coordinator.collapseAllFolders()
self.applyChanges(animate: true)
}
// MARK: API
func updateFeedSelection() {

View File

@ -437,9 +437,10 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
}
func expandSection(_ section: Int) {
guard let expandNode = treeController.rootNode.childAtIndex(section) else {
guard let expandNode = treeController.rootNode.childAtIndex(section), !expandedNodes.contains(expandNode) else {
return
}
expandedNodes.append(expandNode)
animatingChanges = true
@ -463,6 +464,20 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
animatingChanges = false
}
func expandAllSectionsAndFolders() {
for (sectionIndex, sectionNode) in treeController.rootNode.childNodes.enumerated() {
expandSection(sectionIndex)
for topLevelNode in sectionNode.childNodes {
if topLevelNode.representedObject is Folder, let indexPath = indexPathFor(topLevelNode) {
expandFolder(indexPath)
}
}
}
}
func expandFolder(_ indexPath: IndexPath) {
let expandNode = shadowTable[indexPath.section][indexPath.row]
guard !expandedNodes.contains(expandNode) else { return }
@ -481,12 +496,12 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
}
func collapseSection(_ section: Int) {
animatingChanges = true
guard let collapseNode = treeController.rootNode.childAtIndex(section) else {
guard let collapseNode = treeController.rootNode.childAtIndex(section), expandedNodes.contains(collapseNode) else {
return
}
animatingChanges = true
if let removeNode = expandedNodes.firstIndex(of: collapseNode) {
expandedNodes.remove(at: removeNode)
}
@ -496,6 +511,16 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
animatingChanges = false
}
func collapseAllFolders() {
for sectionNode in treeController.rootNode.childNodes {
for topLevelNode in sectionNode.childNodes {
if topLevelNode.representedObject is Folder, let indexPath = indexPathFor(topLevelNode) {
collapseFolder(indexPath)
}
}
}
}
func collapseFolder(_ indexPath: IndexPath) {
animatingChanges = true