I'm working on an application featured like Mac Mail. I have a WebView which allow the user to write a new message. I implemented the drag and drop feature so that a user can add an attachment to the message that way.
To make it simple, I have a main view which contains a WebView and other views. I implemented the drag and drop on this main view (with the draggingEntered: and performDragOperation: methods) and it works as expected.
The problem is that by default, when dragging a file inside a WebView, an image for instance, the image will be displayed in the WebView. But I don't want that, I want it to be added as an attachment, that's why I disabled the drag and drop inside the WebView:
def webView(sender, dragDestinationActionMaskForDraggingInfo:draggingInfo)
WebDragDestinationActionNone
end
But now my file will be added as an attachment if I drag it anywhere inside the main view, except in the WebView (the draggingEntered: and performDragOperation: methods are not called in this case).
I don't know if my question is clear enough to find an answer, I am still new in Cocoa development, so don't hesitate to tell me if you need more details. Another thing, i'm working with Rubymotion but if you got a solution in Objective-C, that would also be perfect!
Thanks for any help or suggestion.
Solution
I subclassed the WebView and overrode the performDragOperation
method to make it work:
def performDragOperation(sender)
self.UIDelegate.mainView.performDragOperation(sender)
end
You could check the sender
(which implements the NSDraggingInfo
protocol) for the destination window:
http://developer.apple.com/library/Mac/#documentation/Cocoa/Reference/ApplicationKit/Protocols/NSDraggingInfo_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSDraggingInfo/draggingDestinationWindow
def performDragOperation(sender)
if sender.draggingDestinationWindow == @web_view
# Attach file
else
# Let it do the normal drag operation
end
true
end
That's just a guess, but you should be able to figure out a solution from here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With