good news - nautilus to gtk2-perl DND



After some trial and error and error and error, I finally discovered how
to capture a drop event from nautilus to a Gtk2.pm app.  Figured I'd share
in case anyone else is interested in doing something similar.

The magic lies in using the right target atom, which turned out to be
"text/uri-list" and $data->data is a newline seperated list of URIs
(probably beginning with file:// if they're local files)

# ---- BEGIN CODE ----

$widget->drag_dest_set(["drop","motion","highlight"], ["copy","private","default","move","link","ask"]);
$widget->signal_connect(drag_data_received => \&drop_handler);

my $target_list = Gtk2::TargetList->new();
my $atom = Gtk2::Gdk::Atom->new("text/uri-list");
$target_list->add($atom, 0, 0);
$widget->drag_dest_set_target_list($target_list);

sub drop_handler {
  my ($treeview, $context, $widget_x, $widget_y, $data, $info, $time) = @_;
  my @uris = split /\n/, $data->data;
  for my $uri (@uris) {
    print "received $uri\n";
  }
}

# ---- END CODE ----

        Dave O



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]