Problem with drag events in MacRuby app

It has been some time since I did any Cocoa development, and I'm trying to make this very fast and dirty (and simple) application wrapped up. I decided to use MacRuby because it was a good excuse to learn it, and the application is simple enough to make sense.

I'm having trouble getting a custom view to respond to drag and drop events.

class ImportPanel < Panel def initWithFrame(frame) registerForDraggedTypes(NSArray.arrayWithObjects(NSPasteboardTypeSound, nil)) super(frame) end def mouseDown(event) NSLog('click') end def draggingEntered(sender) NSLog('drag') end end 

The panel, in this case, is simply an NSView that adds a border. This custom view (ImportPanel) responds correctly to click events, but does not respond to event drag and drop. I tried several different types of cardboard and configurations for registerForDraggedTypes: but none of them give any results.

+4
source share
1 answer

This code worked for me.

AppDelegate.rb

 class AppDelegate attr_accessor :window attr_accessor :panel def applicationDidFinishLaunching(a_notification) # nothing special here end def initialize @panel = Panel.new # Just for debug puts @panel end end 

And this is my player.rb :

 class Panel < NSView def awakeFromNib registerForDraggedTypes(NSArray.arrayWithObjects(NSFilenamesPboardType, NSURLPboardType, NSStringPboardType, nil)) end def mouseDown(event) NSLog('click') end def draggingEntered(sender) NSLog('drag') return NSDragOperationNone end end 

An array of drag-and-drop types that helps me test various drag-and-drop operations (URL, file, etc.). Note that draggingEntered should return NSDragOperation i used by NSDragOperationNone to see if it works.

0
source

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


All Articles