# TreeModelFilter based TreeView Drag Dest

**URL:** <https://www.ruby-forum.com/t/treemodelfilter-based-treeview-drag-dest/116823>\
**Category:** Ruby-Gnome 2\
**Created:** [October 10, 2007, 2:27am UTC](https://www.ruby-forum.com/t/treemodelfilter-based-treeview-drag-dest/116823 "2007-10-10T02:27:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [October 10, 2007, 2:27am UTC](https://www.ruby-forum.com/t/treemodelfilter-based-treeview-drag-dest/116823/1 "2007-10-10T02:27:38Z")

</div>

So I’ve been struggling with this for a while, can someone help?

Below is an example of what I’m trying to do, which is, drag items  
from one treeview into another which uses a filtered model.  
Basically, I’m trying to implement “tagging” and the first model is a  
list of tags and the second is an association of items with these  
tags. [though this example just uses random numbers in place of tags]

First, how do I actually get the selection in the drag destination  
signal handler.

Second, how do I get rid of this message:  
“Gtk-WARNING \*\*:You must override the default ‘drag\_data\_received’  
handler on GtkTreeView when using models that don’t support the  
GtkTreeDragDest interface and enabling drag-and-drop. The simplest way  
to do this is to connect to ‘drag\_data\_received’ and call  
g\_signal\_stop\_emission\_by\_name() in your signal handler to prevent the  
default handler from running. Look at the source code for the default  
handler in gtktreeview.c to get an idea what your handler should do.  
(gtktreeview.c is in the GTK source code.) If you’re using GTK from a  
language other than C, there may be a more natural way to override  
default handlers, e.g. via derivation.”

thanks,  
Alex

* * *

require ‘gtk2’

DND\_ME = [[“GTK\_TREE\_MODEL\_ROW”, Gtk::Drag::TARGET\_SAME\_APP, 0]]

#create two stores, both with random values in them  
m1 = Gtk::ListStore.new(Float)  
m2 = Gtk::ListStore.new(Integer, Float)

#put some random data in there  
(0…10).each do |i|  
iter = m1.append  
iter[0] = rand  
end

# put some random data in there, iter[0] can be seen as an id of an item

# and iter[1] could be a tag.

(0…100).each do |i|  
iter = m2.append  
iter[0] = i % 10  
iter[1] = rand  
end

#create a view  
v1 = Gtk::TreeView.new(m1)  
renderer = Gtk::CellRendererText.new  
col = Gtk::TreeViewColumn.new(“Source”, renderer, :text =\> 0)  
v1.append\_column(col)

#create a filtered tree model  
fm = Gtk::TreeModelFilter.new(m2)  
fm.set\_visible\_func{|model, iter|  
if iter[0] == 0  
next true  
else  
next false  
end  
}  
fm.refilter

#make a view with the filtered model  
v2 = Gtk::TreeView.new(fm)  
renderer = Gtk::CellRendererText.new  
col = Gtk::TreeViewColumn.new(“Dest [Filtered]”, renderer, :text =\> 1)  
v2.append\_column(col)

#make the first view a drag source  
v1.enable\_model\_drag\_source(Gdk::Window::BUTTON1\_MASK, DND\_ME,  
Gdk::DragContext::ACTION\_LINK)  
#make the second view [with the filtered model] a drag destination  
v2.enable\_model\_drag\_dest(DND\_ME, Gdk::DragContext::ACTION\_LINK)

#create the signal handlers  
v2.signal\_connect(“drag\_data\_received”) do |w, dc, x, y,  
selectiondata, info, time|  
puts “got something!”  
puts selectiondata.type  
puts selectiondata.format  
puts selectiondata.target

#XXX i need help here!

true  
end

#make the windows  
w1 = Gtk::Window.new(“floatme: source”)  
w2 = Gtk::Window.new(“floatme: dest”)  
w1.add(v1)  
w2.add(v2)  
w1.show\_all  
w2.show\_all

Gtk::main
