#!/usr/bin/perl use strict; use warnings; use Glib ':constants'; use Gtk2 -init; use Gtk2::SimpleList; =head1 > How can I paste the clipboard (with Control + V) over a gtktreeview > widget (list) ? > Any idea? So far as i know, you create a key binding (e.g. with a menu item), and then in the handler for that command, pull data from the clipboard and do the appropriate list insertions. Instead of spamming the message with lots of boilerplate code to set up the accelerators and all that, here's a bunch of GtkBuilder XML. The interesting part is the on_paste() callback, near the end, which just grabs the clipboard contents as plain text, splits by whitespace, and inserts each item as its own line. In a real app, you'd do more appropriate parsing and marshaling and whatnot. =cut # by muppet on maillist # # Gtk2::Builder is cool. Now we can express the shortcuts and menu items # and all that as data instead of as tedious code. # my $interface = ' _File gtk-quit gtk-paste gtk-delete 250 500 false automatic automatic false '; my $builder = Gtk2::Builder->new (); $builder->add_from_string ($interface); $builder->connect_signals (); my $slist = Gtk2::SimpleList->new_from_treeview ( $builder->get_object ('treeview'), Words => 'text', ); $builder->get_object ('window')->show_all; Gtk2->main; sub on_window_destroy { Gtk2->main_quit } sub on_quit { $builder->get_object ('window')->destroy; } # # Here's the interesting part. # sub on_paste { my $clipboard = Gtk2::Clipboard->get_for_display ($builder->get_object ('window')->get_display (), Gtk2::Gdk->SELECTION_PRIMARY); my $text = $clipboard->wait_for_text (); foreach (split /\s+/, $text) { push @{ $slist->{data} }, $_ if length; } } sub on_clear { @{ $slist->{data} } = (); } __END__