Disable drag and drop for WebView in favor of one of its observations

I am working on an application other than Mac Mail. I have a webview that allows the user to write a new message. I implemented a drag and drop function so that the user can add an attachment to the message this way.

To make it simple, I have a main view that contains a WebView and other views. I implemented drag and drop on this main view (using the draggingEntered: and executeDragOperation :) methods, and it works as expected.

The problem is that by default, when you drag and drop a file inside a WebView, an image, for example, will be displayed in WebView. But I don't want this, I want it to be added as an attachment, so I turned off 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 in the main view, except for WebView (in this case, calls to the draggingEntered: and executeDragOperation methods will not be called).

I donโ€™t know if Iโ€™m still new to Cocoa to answer the question, so feel free to tell me if you need more information. Another thing, I work with Rubymotion, but if you have a solution in Objective-C, it will also be great!

Thanks for any help or suggestion.

Decision

I subclassed WebView and redefined the performDragOperation method to make it work:

 def performDragOperation(sender) self.UIDelegate.mainView.performDragOperation(sender) end 
+4
source share
1 answer

You can check sender (which implements the NSDraggingInfo protocol) for the target 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 

This is just an assumption, but you should be able to find a solution here.

+1
source

Source: https://habr.com/ru/post/1487290/


All Articles