hi all,
a question about setting #DataSelection in a drag and drop… can i
drag an array?
i’m making a music directory browser, and i’ve got a TreeView with a
bunch of song titles in it set as a drag source. the TreeView is set
for multiple selection.
the thing is, i’m not interested in dragging the titles, but rather
the full paths to the songs - so…
i set up a hash, with the keys being the song titles, and the paths as
the values. then, in the TreeView#signal_connect(“drag_data_get”)
block, i load all the song titles selected into an array, which is then
passed through a block which treats each song title as a key, and passes
the key’s value (the song’s path) into another array.
what i’m trying to do is pass this array of paths into the
Gdk::DataSelection associated with the “drag_data_get” block.
sorry if my explanation hasn’t made too much sense - basically i just
want to drag an array!
here’s a look at what i’m working with:
#############
(@view is my TreeView, @listselection is the TreeView#selection
@selarray = []
@hash = {}
@dragdata = []
Gtk::Drag.source_set(@view, Gdk::Window::BUTTON1_MASK,
[[“text/plain”, 0, 0]],
Gdk::DragContext::ACTION_COPY|Gdk::DragContext::ACTION_MOVE
)
@view.signal_connect(“drag_data_get”) {|w, c, data, i, t|
@listselection.selected_each{|m, path, iter| @selarray << iter[0]}
@selarray.collect{|entry| @dragdata << @hash[entry]}
data.set(Gdk::Selection::TYPE_STRING, @dragdata.to_s)
}
##############
this works, but returns a string of the array (obviously, as the
last line would indicate,) and not the array itself. i’ve searched
through the Gdk::Selection types, and the Gdk::DataSelection methods,
but haven’t seen anything that lets me pass the array as an array rather
than a string.
any ideas? is this just a ridiculous thing to do in the first place?
thanks -
-j