# Visualruby Now has Drag and Drop

**URL:** <https://www.ruby-forum.com/t/visualruby-now-has-drag-and-drop/224843>\
**Category:** Ruby-Gnome 2\
**Created:** [November 28, 2012, 10:12am UTC](https://www.ruby-forum.com/t/visualruby-now-has-drag-and-drop/224843 "2012-11-28T10:12:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 28, 2012, 10:12am UTC](https://www.ruby-forum.com/t/visualruby-now-has-drag-and-drop/224843/1 "2012-11-28T10:12:34Z")

</div>

Hi:

I’ve just added drag and drop to visualruby. I isn’t documented on  
[visualruby.net](http://visualruby.net) yet, but there is an example program in the latest  
visualruby gem (0.1.2). Its pretty simple. You can do this:

label1 = Gtk::Label.new(“Hello World”)  
label2 = Gtk::Label.new(“Goodbye”)  
button1 = Gtk::Button.new(“I need a Label”)

label1.drag\_to(button1)  
label2.drag\_to(button1)

Then you write a method for the action you want it to take:

def button1\_\_drag\_drop(\*args)  
source\_label = button1.dragged\_widget  
button1.label = source\_label.label  
end

The instance variable, dragged\_widget is added by visualruby in the drag  
process. It holds a reference to the source widget.

Note: the method must be use the naming convention “widget\_\_signal”

I’d like to hear input from you guys because I’m taking a very simple  
approach: dragging one widget onto another then writing a handler. It  
looks like the best solution to me. GTK has special drag-n-drop stuff  
so you can drag treeview rows around, but I can’t get it to copy/move  
records from one treeview to another:

[http://www.ruby-forum.com/topic/127494](http://www.ruby-forum.com/topic/127494)

To see this work, go to [visualruby.net](http://visualruby.net), and download it using the  
instructions. Open the “drag\_drop” example.

Also, the program was having a problem on some machines when it scanned  
the “home” directory for project files because some people had thousands  
of files in their home directory causing a big pause. To correct this,  
the program now creates a folder: home/visualruby to narrow the  
search. However, now everyone will basically be required to keep all  
their projects in the home/visualruby folder. Let me know if this is a  
problem.

Thanks,  
Eric C
