#!/usr/bin/perl -w

use strict;

use constant FALSE => 0;
use constant TRUE  => 1;

use Gtk2 -init;

my $mw = Gtk2::Window->new('toplevel');
$mw->set_default_size(300, 150);
$mw->set_border_width(5);

my $ts = Gtk2::TreeStore->new("Glib::String");
my $tv = Gtk2::TreeView->new();
$tv->show();
$tv->set_model($ts);
$tv->set_headers_visible(FALSE);
$tv->set_reorderable(TRUE);

my $cell = Gtk2::CellRendererText->new();
my $col = Gtk2::TreeViewColumn->new_with_attributes("Row", $cell, "text", 0);
$tv->append_column($col);

my $it = $ts->append(undef);
$ts->set($it, 0, "Row 1");
my $it2 = $ts->append($it);
$ts->set($it2, 0, "Row 2");
my $it3 = $ts->append($it2);
$ts->set($it3, 0, "Row 3");
my $it4 = $ts->append($it2);
$ts->set($it4, 0, "Row 4");

$ts->signal_connect('row-inserted', \&row_moved);

$mw->add($tv);
$mw->show();

$mw->signal_connect('destroy', sub { exit; });

Gtk2->main;

sub row_moved {
	my ($model, $path, $iter) = @_;

	my $name = $model->get($iter, 0); # $name is undefined!

	print "Updated location of row $name!\n";
}
