Make sidebar expand/collapse keyboard shortcuts work.

This commit is contained in:
Brent Simmons 2017-12-21 11:09:07 -08:00
parent 70000c1d31
commit 84845c21b3
4 changed files with 84 additions and 26 deletions

View File

@ -6,41 +6,25 @@
<key>key</key> <key>key</key>
<string>,</string> <string>,</string>
<key>action</key> <key>action</key>
<string>sidebarCollapse:</string> <string>collapseSelectedRows:</string>
</dict>
<dict>
<key>key</key>
<string>[leftarrow]</string>
<key>action</key>
<string>sidebarCollapse:</string>
<key>commandModifier</key>
<true/>
</dict> </dict>
<dict> <dict>
<key>key</key> <key>key</key>
<string>.</string> <string>.</string>
<key>action</key> <key>action</key>
<string>sidebarExpand:</string> <string>expandSelectedRows:</string>
</dict>
<dict>
<key>key</key>
<string>[rightarrow]</string>
<key>action</key>
<string>sidebarExpand:</string>
<key>commandModifier</key>
<true/>
</dict> </dict>
<dict> <dict>
<key>key</key> <key>key</key>
<string>;</string> <string>;</string>
<key>action</key> <key>action</key>
<string>sidebarCollapseAll:</string> <string>collapseAllExceptForGroupItems:</string>
</dict> </dict>
<dict> <dict>
<key>key</key> <key>key</key>
<string>[leftarrow]</string> <string>[leftarrow]</string>
<key>action</key> <key>action</key>
<string>sidebarCollapseAll:</string> <string>collapseAllExceptForGroupItems:</string>
<key>commandModifier</key> <key>commandModifier</key>
<true/> <true/>
<key>optionModifier</key> <key>optionModifier</key>
@ -50,13 +34,13 @@
<key>key</key> <key>key</key>
<string>&apos;</string> <string>&apos;</string>
<key>action</key> <key>action</key>
<string>sidebarExpandAll:</string> <string>expandAll:</string>
</dict> </dict>
<dict> <dict>
<key>key</key> <key>key</key>
<string>[rightarrow]</string> <string>[rightarrow]</string>
<key>action</key> <key>action</key>
<string>sidebarExpandAll:</string> <string>expandAll:</string>
<key>commandModifier</key> <key>commandModifier</key>
<true/> <true/>
<key>optionModifier</key> <key>optionModifier</key>

View File

@ -135,7 +135,6 @@ import RSCore
// MARK: Navigation // MARK: Navigation
func canGoToNextUnread() -> Bool { func canGoToNextUnread() -> Bool {
if let _ = rowContainingNextUnread() { if let _ = rowContainingNextUnread() {

View File

@ -52,9 +52,9 @@
<tr><td colspan="2">&nbsp;<br /></td></tr> <tr><td colspan="2">&nbsp;<br /></td></tr>
<tr><td colspan="2" class="tableTitleRow">Left sidebar only…</td></tr> <tr><td colspan="2" class="tableTitleRow">Left sidebar only…</td></tr>
<tr class="backgroundColorRow"><td>Collapse</td><td>, or cmd-leftArrow</td></tr> <tr class="backgroundColorRow"><td>Collapse</td><td>, or option-leftArrow</td></tr>
<tr><td>Expand</td><td>. or cmd-rightArrow</td></tr> <tr><td>Expand</td><td>. or option-rightArrow</td></tr>
<tr class="backgroundColorRow"><td>Collapse All</td><td>; or option-cmd-leftArrow</td></tr> <tr class="backgroundColorRow"><td>Collapse All (except for group items)</td><td>; or option-cmd-leftArrow</td></tr>
<tr><td>Expand All</td><td>' or option-cmd-rightArrow</td></tr> <tr><td>Expand All</td><td>' or option-cmd-rightArrow</td></tr>
<tr class="backgroundColorRow"><td>Move focus to headlines</td><td>rightArrow</td></tr> <tr class="backgroundColorRow"><td>Move focus to headlines</td><td>rightArrow</td></tr>

View File

@ -22,4 +22,79 @@ public extension NSOutlineView {
} }
} }
} }
@IBAction func collapseSelectedRows(_ sender: Any?) {
for item in selectedItems {
if isExpandable(item) && isItemExpanded(item) {
collapseItem(item)
}
}
}
@IBAction func expandSelectedRows(_ sender: Any?) {
for item in selectedItems {
if isExpandable(item) && !isItemExpanded(item) {
expandItem(item)
}
}
}
@IBAction func expandAll(_ sender: Any?) {
expandAllChildren(of: nil)
}
@IBAction func collapseAllExceptForGroupItems(_ sender: Any?) {
collapseAllChildren(of: nil, exceptForGroupItems: true)
}
func expandAllChildren(of item: Any?) {
guard let childItems = children(of: item) else {
return
}
for child in childItems {
if !isItemExpanded(child) && isExpandable(child) {
expandItem(child, expandChildren: true)
}
expandAllChildren(of: child)
}
}
func collapseAllChildren(of item: Any?, exceptForGroupItems: Bool) {
guard let childItems = children(of: item) else {
return
}
for child in childItems {
collapseAllChildren(of: child, exceptForGroupItems: exceptForGroupItems)
if exceptForGroupItems && isGroupItem(child) {
continue
}
if isItemExpanded(child) {
collapseItem(child, collapseChildren: true)
}
}
}
func children(of item: Any?) -> [Any]? {
var children = [Any]()
for indexOfItem in 0..<numberOfChildren(ofItem: item) {
if let child = child(indexOfItem, ofItem: item) {
children.append(child)
}
}
return children.isEmpty ? nil : children
}
func isGroupItem(_ item: Any) -> Bool {
return delegate?.outlineView?(self, isGroupItem: item) ?? false
}
} }