Start work on drop validation.

This commit is contained in:
Brent Simmons 2018-09-19 13:22:22 -07:00
parent 0a20b26ed5
commit f29f690625
1 changed files with 24 additions and 8 deletions

View File

@ -10,10 +10,12 @@ import AppKit
import RSTree import RSTree
import Articles import Articles
import RSCore import RSCore
import Account
@objc final class SidebarOutlineDataSource: NSObject, NSOutlineViewDataSource { @objc final class SidebarOutlineDataSource: NSObject, NSOutlineViewDataSource {
let treeController: TreeController let treeController: TreeController
static let dragOperationNone = NSDragOperation(rawValue: 0)
init(treeController: TreeController) { init(treeController: TreeController) {
self.treeController = treeController self.treeController = treeController
@ -38,22 +40,21 @@ import RSCore
func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? { func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? {
let node = nodeForItem(item as AnyObject?) let node = nodeForItem(item as AnyObject?)
guard nodeRepresentsDraggableItem(node) else {
guard !(node.representedObject is PseudoFeed) else {
// We dont 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.
return nil return nil
} }
return (node.representedObject as? PasteboardWriterOwner)?.pasteboardWriter return (node.representedObject as? PasteboardWriterOwner)?.pasteboardWriter
} }
// MARK: - Drag and Drop // MARK: - Drag and Drop
func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation { func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
// let draggingSourceOutlineView = info.draggingSource() as? NSOutlineView let draggingSourceOutlineView = info.draggingSource() as? NSOutlineView
// let isLocalDrop = draggingSourceOutlineView == outlineView let isLocalDrop = draggingSourceOutlineView == outlineView
return NSDragOperation(rawValue: 0) 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 { func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool {
@ -72,4 +73,19 @@ private extension SidebarOutlineDataSource {
} }
return item as! Node return item as! Node
} }
func nodeRepresentsDraggableItem(_ node: Node) -> Bool {
// Dont 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
}
} }