Hi,
I'm trying to drag an NSTextView from one NSView to another. I'm getting the right events, but the drag animation is not coming up.
Subclassed TextView:
class MyTextView:NSTextView, NSPasteboardItemDataProvider
{
func pasteboard(_ pasteboard: NSPasteboard?, item: NSPasteboardItem, provideDataForType type: NSPasteboard.PasteboardType)
{
NSLog ("Paste")
}
override func mouseDown(with theEvent: NSEvent)
{
let pasteboardItem = NSPasteboardItem()
pasteboardItem.setDataProvider(self, forTypes: [.string])
let draggingItem = NSDraggingItem(pasteboardWriter: pasteboardItem)
draggingItem.setDraggingFrame(self.bounds, contents:.Publisher)
beginDraggingSession(with: [draggingItem], event: theEvent, source: self)
}
override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation
{
return NSDragOperation.copy
}
}
Subclassed NSView to receive the drop event:
class DropView:NSView
{
func EnableDrop ()
{
// Registering for drag drop types
registerForDraggedTypes([NSPasteboard.PasteboardType.string, NSPasteboard.PasteboardType.URL, NSPasteboard.PasteboardType.multipleTextSelection, NSPasteboard.PasteboardType.color])
}
func shouldAllowDrag(_ draggingInfo: NSDraggingInfo) -> Bool
{
return true
}
override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation {
// To show a copy tooltip during drop
return NSDragOperation.copy
}
override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool
{
return true
}
override func performDragOperation(_ draggingInfo: NSDraggingInfo) -> Bool {
let draggedview = draggingInfo.draggingSource as! NSView
NSLog ("Drop received")
return true
}
}
When I create my view in the ViewController, I do "myviewobj.EnableDrop()" to receive drop events. However as stated above, I'm not able to see the drag animation happening, however, I do get events for it.