Reputation: 783
I'm building an NSOutlineView using Swift. I have the view in place and now I'm starting on drag and drop to move items around in the view. I'm using This as my starting point. I have drag working, click and drag around the outline, but I can't make the drop part work; I'm not seeing the horizontal marker and I get nothing but a beep when I drop. I'm missing something obvious but I can't for the life of me see it.
This is my d&d code from my NSOutlineViewDelegate:
func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? {
let pp = NSPasteboardItem()
// working as expected here
if let fi = item as? FileItem {
pp.setString( fi.Path, forType: "public.text" )
print( "pb write \(fi.Name)")
} else {
print( "pb write, not a file item \(item)")
}
return pp
}
func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
print( "validate: \(item)")
return NSDragOperation.move
//
}
func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool {
print( "accept drop: \(item)")
return true
}
And I've registered for drag types in ViewDidLoad():
OutlineViewOutlet.register( forDraggedTypes: ["public.txt"] )
Any thoughts appreciated, thanks.
Upvotes: 0
Views: 1447
Reputation: 783
Answering my own question; wrong type in register(). This works:
OutlineViewOutlet.register( forDraggedTypes: ["public.data"] )
Upvotes: 0