[MacRuby-devel] How do I handle file drop events in HotCocoa?

Laurent Sansonetti lsansonetti at apple.com
Mon Mar 16 11:02:50 PDT 2009


Hi Jeff,

(Sorry for the late reply.)

On Mar 14, 2009, at 9:09 PM, Jeff Cohen wrote:

> Hello,
>
> I'm just getting started with MacRuby and HotCocoa (was a  
> longtime .NET developer, and wasn't interested in learning Cocoa  
> until MacRuby came along).  I have a simple HotCocoa app with just a  
> table view, and I'd like the user to be able to drop a filename from  
> the Finder onto the table view (or anywhere in my app). I can call  
> registerForDraggedTypes() on my table view object successfully.  But  
> I'm not sure how to have events delegated to my Application class  
> (or if that's even possible).
>
> Looking at the hotcocoa source for wrapping NSView (view.rb), I  
> don't see delegate mappings for the draggingEntered or  
> performDragOperation events.  I think I need to do something like  
> the mapping code does and write code like this:
>
> delegating "draggingEntered", :to => :dragging_entered
>
> but I don't know where I can or should do that, or if I'm even on  
> the right track.
>
> Any hint of where I should get started would be appreciated.

I don't think HotCocoa exposes drag and drop facilities yet. In  
general drag and drop in Cocoa is non trivial to do (esp. if you want  
to integrate it with complex views such as NSTableViews).

The following article describes how to implement drag and drop in Cocoa:

http://developer.apple.com/documentation/Cocoa/Conceptual/DragandDrop/DragandDrop.html

It even has a special section dedicated to NSTableViews.

You should be able to do everything  described in this article using  
"pure" MacRuby code but if you want to use some kind of syntax sugar  
via HotCocoa I'm afraid you will have to wait until someone implements  
them.

HTH,
Laurent


More information about the MacRuby-devel mailing list