Make the sidebar contextual menu refer to the clicked row rather than the selected row.

This commit is contained in:
Brent Simmons 2018-02-07 13:25:17 -08:00
parent d59058c014
commit 4491c5f443
3 changed files with 17 additions and 5 deletions

View File

@ -20,7 +20,7 @@ import AppKit
menu.removeAllItems()
guard let contextualMenu = sidebarViewController.contextualMenuForSelectedObjects() else {
guard let contextualMenu = sidebarViewController.contextualMenuForClickedRows() else {
return
}

View File

@ -14,10 +14,6 @@ import AppKit
public func menuNeedsUpdate(_ menu: NSMenu) {
guard let sidebarViewController = sidebarViewController else {
return
}
// Save the first item, since its the gear icon itself.
guard let gearMenuItem = menu.item(at: 0) else {
assertionFailure("Expected sidebar gear menu to have at least one item.")
@ -26,6 +22,9 @@ import AppKit
menu.removeAllItems()
menu.addItem(gearMenuItem)
guard let sidebarViewController = sidebarViewController else {
return
}
guard let contextualMenu = sidebarViewController.contextualMenuForSelectedObjects() else {
return
}

View File

@ -200,6 +200,19 @@ import RSCore
return menu(for: selectedObjects)
}
func contextualMenuForClickedRows() -> NSMenu? {
// TODO: If the clickedRow is part of the selected rows, then do a contextual menu for all the selected rows.
let row = outlineView.clickedRow
guard row != -1, let node = nodeForRow(row) else {
return nil
}
let object = node.representedObject
return menu(for: [object])
}
// MARK: NSOutlineViewDelegate
func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {