mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-27 09:21:21 +01:00
Added delete to the sidebar context and gear menus. Issue #328
This commit is contained in:
parent
d738bff2ad
commit
89bdcc7a61
@ -73,6 +73,12 @@ extension SidebarViewController {
|
||||
|
||||
@objc func deleteFromContextualMenu(_ sender: Any?) {
|
||||
|
||||
guard let menuItem = sender as? NSMenuItem, let objects = menuItem.representedObject as? [AnyObject] else {
|
||||
return
|
||||
}
|
||||
|
||||
let nodes = objects.compactMap { treeController.nodeInTreeRepresentingObject($0) }
|
||||
deleteNodes(nodes)
|
||||
}
|
||||
|
||||
@objc func renameFromContextualMenu(_ sender: Any?) {
|
||||
@ -141,7 +147,7 @@ private extension SidebarViewController {
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
|
||||
menu.addItem(renameMenuItem(feed))
|
||||
// menu.addItem(deleteMenuItem([feed]))
|
||||
menu.addItem(deleteMenuItem([feed]))
|
||||
|
||||
return menu
|
||||
}
|
||||
@ -156,7 +162,7 @@ private extension SidebarViewController {
|
||||
}
|
||||
|
||||
menu.addItem(renameMenuItem(folder))
|
||||
// menu.addItem(deleteMenuItem([folder]))
|
||||
menu.addItem(deleteMenuItem([folder]))
|
||||
|
||||
return menu.numberOfItems > 0 ? menu : nil
|
||||
}
|
||||
@ -173,18 +179,16 @@ private extension SidebarViewController {
|
||||
|
||||
func menuForMultipleObjects(_ objects: [Any]) -> NSMenu? {
|
||||
|
||||
// guard allObjectsAreFeedsAndOrFolders(objects) else {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
let menu = NSMenu(title: "")
|
||||
|
||||
if anyObjectInArrayHasNonZeroUnreadCount(objects) {
|
||||
menu.addItem(markAllReadMenuItem(objects))
|
||||
// menu.addItem(NSMenuItem.separator())
|
||||
}
|
||||
|
||||
// menu.addItem(deleteMenuItem(objects))
|
||||
if allObjectsAreFeedsAndOrFolders(objects) {
|
||||
menu.addSeparatorIfNeeded()
|
||||
menu.addItem(deleteMenuItem(objects))
|
||||
}
|
||||
|
||||
return menu.numberOfItems > 0 ? menu : nil
|
||||
}
|
||||
|
@ -127,25 +127,7 @@ import RSCore
|
||||
if outlineView.selectionIsEmpty {
|
||||
return
|
||||
}
|
||||
|
||||
let nodesToDelete = treeController.normalizedSelectedNodes(selectedNodes)
|
||||
|
||||
guard let undoManager = undoManager, let deleteCommand = DeleteFromSidebarCommand(nodesToDelete: nodesToDelete, treeController: treeController, undoManager: undoManager) else {
|
||||
return
|
||||
}
|
||||
|
||||
animatingChanges = true
|
||||
outlineView.beginUpdates()
|
||||
|
||||
let indexSetsGroupedByParent = Node.indexSetsGroupedByParent(nodesToDelete)
|
||||
for (parent, indexSet) in indexSetsGroupedByParent {
|
||||
outlineView.removeItems(at: indexSet, inParent: parent.isRoot ? nil : parent, withAnimation: [.slideDown])
|
||||
}
|
||||
|
||||
outlineView.endUpdates()
|
||||
|
||||
runCommand(deleteCommand)
|
||||
animatingChanges = false
|
||||
deleteNodes(selectedNodes)
|
||||
}
|
||||
|
||||
@IBAction func openInBrowser(_ sender: Any?) {
|
||||
@ -278,6 +260,31 @@ import RSCore
|
||||
|
||||
postSidebarSelectionDidChangeNotification(selectedObjects.isEmpty ? nil : selectedObjects)
|
||||
}
|
||||
|
||||
//MARK: - Node Manipulation
|
||||
|
||||
func deleteNodes(_ nodes: [Node]) {
|
||||
|
||||
let nodesToDelete = treeController.normalizedSelectedNodes(nodes)
|
||||
|
||||
guard let undoManager = undoManager, let deleteCommand = DeleteFromSidebarCommand(nodesToDelete: nodesToDelete, treeController: treeController, undoManager: undoManager) else {
|
||||
return
|
||||
}
|
||||
|
||||
animatingChanges = true
|
||||
outlineView.beginUpdates()
|
||||
|
||||
let indexSetsGroupedByParent = Node.indexSetsGroupedByParent(nodesToDelete)
|
||||
for (parent, indexSet) in indexSetsGroupedByParent {
|
||||
outlineView.removeItems(at: indexSet, inParent: parent.isRoot ? nil : parent, withAnimation: [.slideDown])
|
||||
}
|
||||
|
||||
outlineView.endUpdates()
|
||||
|
||||
runCommand(deleteCommand)
|
||||
animatingChanges = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - NSUserInterfaceValidations
|
||||
|
Loading…
x
Reference in New Issue
Block a user