From f29f690625cb1d31924af09f18434f5215469724 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 19 Sep 2018 13:22:22 -0700 Subject: [PATCH] Start work on drop validation. --- .../Sidebar/SidebarOutlineDataSource.swift | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/NetNewsWire/MainWindow/Sidebar/SidebarOutlineDataSource.swift b/NetNewsWire/MainWindow/Sidebar/SidebarOutlineDataSource.swift index 84138d1bc..137021972 100644 --- a/NetNewsWire/MainWindow/Sidebar/SidebarOutlineDataSource.swift +++ b/NetNewsWire/MainWindow/Sidebar/SidebarOutlineDataSource.swift @@ -10,10 +10,12 @@ import AppKit import RSTree import Articles import RSCore +import Account @objc final class SidebarOutlineDataSource: NSObject, NSOutlineViewDataSource { let treeController: TreeController + static let dragOperationNone = NSDragOperation(rawValue: 0) init(treeController: TreeController) { self.treeController = treeController @@ -38,22 +40,21 @@ import RSCore func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? { let node = nodeForItem(item as AnyObject?) - - guard !(node.representedObject is PseudoFeed) else { - // We don’t allow the built-in smart feeds to be dragged. - // This will have to be revisited later when there are user-created smart feeds that *can* be dragged. + guard nodeRepresentsDraggableItem(node) else { return nil } - return (node.representedObject as? PasteboardWriterOwner)?.pasteboardWriter } // MARK: - Drag and Drop func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation { -// let draggingSourceOutlineView = info.draggingSource() as? NSOutlineView -// let isLocalDrop = draggingSourceOutlineView == outlineView - return NSDragOperation(rawValue: 0) + let draggingSourceOutlineView = info.draggingSource() as? NSOutlineView + let isLocalDrop = draggingSourceOutlineView == outlineView + if isLocalDrop { + return validateLocalDrop(info, proposedItem: item, proposedChildIndex: index) + } + return SidebarOutlineDataSource.dragOperationNone } func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool { @@ -72,4 +73,19 @@ private extension SidebarOutlineDataSource { } return item as! Node } + + func nodeRepresentsDraggableItem(_ node: Node) -> Bool { + // Don’t allow PseudoFeed or Folder to be dragged. + // This will have to be revisited later. For instance, + // user-created smart feeds should be draggable, maybe. + // And we might allow dragging folders between accounts. + return node.representedObject is Feed + } + + func validateLocalDrop(_ info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation { + +// let node = nodeForItem(item) + return SidebarOutlineDataSource.dragOperationNone + + } }