[MacRuby-devel] How do I handle file drop events in HotCocoa?
Jeff Cohen
cohen.jeff at gmail.com
Tue Mar 17 06:34:57 PDT 2009
Hi Matt,
I think the problem is that I'm trying to add more event handlers for an
already-defined HotCocoa class. Here's a snippet of the top of my
application.rb:
# application.rb
require 'hotcocoa'
require 'logger'
# Replace the following code with your own hotcocoa code
HotCocoa::Mappings.map :view => :NSView do
delegating "draggingEntered", :to => :dragging_entered
end
class Application...
[snip]
Now, inside my Application#start method, I eventually have code like this:
[line 50] def create_table_view
[line 51] @grid_view = layout_view :layout => {:expand => [:width,
:height]}, :margin => 0, :spacing => 0 do |view|
and when I have my custom mappings at the top of the file, I then get this
error when I try to run macrake (I don't get this error if I comment out my
custom mapping lines at the top):
$ railsinfo: macrake
(in /Users/jcohen/dev/sandbox/railsinfo)
/Library/Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/hotcocoa/mapper.rb:59:in
`eval': undefined method `layout=' for #<HotCocoa::LayoutView:0x800598de0>
(NoMethodError)
from
/Library/Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/hotcocoa/mapper.rb:59:in
`eval'
from
/Library/Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/hotcocoa/mapper.rb:59:in
`block (2 levels) in map_method'
from
/Library/Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/hotcocoa/mapper.rb:51:in
`each'
from
/Library/Frameworks/MacRuby.framework/Versions/0.4/usr/lib/ruby/1.9.1/hotcocoa/mapper.rb:51:in
`block in map_method'
from
/Users/jcohen/dev/hotcocoa/railsinfo/Railsinfo.app/Contents/Resources/lib/application.rb:51:in
`create_table_view'
Unless I'm wrong, with your ProgressIndicator exmaple, you were defining a
completely new class mapping. But since I'm trying to "reopen" NSView so to
speak, I tihnk the HotCocoa::Mappings.map call might be messing up what was
already mapped for NSView.
I'll keep investigating... let me know if you think I might be right, or if
I'm off my rocker.
Thanks again!
Jeff
2009/3/17 Matt Aimonetti <mattaimonetti at gmail.com>
> You can define your own mapping within your app or extend the existing
> ones, delegation can also be added on each instance of any object.
>
> Here is a sample app I wrote with a custom mapping (which was later on
> merged in HotCocoa):
>
> http://github.com/mattetti/macruby-examples/blob/fe06617645c8809183fb15bca025016937e1c84b/download/lib/progress_indicator.rb
>
> You can see that I defined my mapping like any other mappings and just
> required the file in my application.rb file:
> http://github.com/mattetti/macruby-examples/blob/fe06617645c8809183fb15bca025016937e1c84b/download/lib/application.rb#L5
>
> - Matt
>
> 2009/3/16 Jeff Cohen <cohen.jeff at gmail.com>
>
> Hi Laurant,
>>
>> Thanks a lot for your reply. And perhaps I misspoke somewhat - I'm not
>> trying to implement full drag and drop within my application, but only
>> receive simple filename drop events that originate from outside the
>> application. I think that it's just a matter of adding a few extra delegate
>> mappings, but I don't understand how to "extend" more mappings into the
>> hotcocoa wrapper classes.
>>
>> Perhaps instead I will try to build from source and add the mappings
>> there, and use a local build to test with. If a miracle occurs and I can
>> figure it out, I will submit a patch. :-)
>>
>> Thanks again!
>> Jeff
>>
>>
>>
>> On Mon, Mar 16, 2009 at 1:02 PM, Laurent Sansonetti <
>> lsansonetti at apple.com> wrote:
>>
>>> 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
>>> _______________________________________________
>>> MacRuby-devel mailing list
>>> MacRuby-devel at lists.macosforge.org
>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>>
>>
>>
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>
>>
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20090317/556b108c/attachment-0001.html>
More information about the MacRuby-devel
mailing list