use strict;
use warnings;
use Gtk2 '-init';
use Gtk2::Ex::Simple::List;
use Glib qw /TRUE FALSE/;
use Data::Dumper;

# Declare a simple list
my $slist = Gtk2::Ex::Simple::List->new(
	'Bool Field'    => 'bool',
	'Text Field'    => 'text'
);

# Populate it
while(<DATA>) {
	chomp;
	next if /^$/;
	push @{$slist->{data}}, [0, $_];
}

# Create a search box
my $entry = Gtk2::Entry->new;
my $button = Gtk2::Button->new_from_stock('gtk-search');
$entry->set_activates_default(TRUE);
$button->signal_connect( 'realize' => sub {
	$button->set_flags ('can-default');
	$button->grab_default;
});
$button->signal_connect( 'clicked' => sub {
	$slist->get_model->refilter;
});

# Set up filtering logic
my $filter_model = Gtk2::TreeModelFilter->new($slist->get_model);
$filter_model->set_visible_func(sub {
	my ($model, $iter, $data) = @_;	
	my @list = $model->get_value($iter);
	my $pattern = $entry->get_text;
	return TRUE if !$pattern;
	foreach my $element (@list) {
		return TRUE if ($element and $element =~ m/$pattern/i);
	}
	return FALSE;
});
$slist->set_model($filter_model);

# Pack the widgets and display
my $scroll = Gtk2::ScrolledWindow->new;
$scroll->set_policy('never','automatic');
$scroll->add($slist);

my $hbox = Gtk2::HBox->new(FALSE);
$hbox->pack_start($entry, FALSE, TRUE, 0);
$hbox->pack_start($button, FALSE, TRUE, 0);

my $vbox = Gtk2::VBox->new(FALSE);
$vbox->pack_start($hbox, FALSE, TRUE, 0);
$vbox->pack_start($scroll, TRUE, TRUE, 0);

my $window = Gtk2::Window->new;
$window->signal_connect(destroy => sub { Gtk2->main_quit; });
$window->add($vbox);
$window->set_default_size(400,350);
$window->show_all;
Gtk2->main;

__DATA__

What is GNOME?

The GNOME project provides two things: The GNOME desktop environment, an intuitive and 
attractive desktop for users, and the GNOME development platform, an extensive framework 
for building applications that integrate into the rest of the desktop. You can learn 
more about how GNOME can work for you in our Why Choose GNOME? page.
GNOME is...
Free

GNOME is Free Software and part of the GNU project, dedicated to giving users and 
developers the ultimate level of control over their desktops, their software, and 
their data. Find out more about the GNU project and Free Software at gnu.org.
Usable

GNOME understands that usability is about creating software that is easy for everyone 
to use, not about piling on features. GNOME's community of professional and volunteer 
usability experts have created Free Software's first and only Human Interface Guidelines, 
and all core GNOME software is adopting these principles. Find out more about GNOME and 
usability at the GNOME Usability Project.
Accessible

Free Software is about enabling software freedom for everyone, including users and 
developers with disabilities. GNOME's Accessibility framework is the result of 
several years of effort, and makes GNOME the most accessible desktop for any Unix platform. 
Find out more at the GNOME Accessibility Project.
International

GNOME is used, developed and documented in dozens of languages, and we strive to ensure 
that every piece of GNOME software can be translated into all languages. Find out more at 
the GNOME Translation Project.
Developer-friendly

Developers are not tied to a single language with GNOME. You can use C, C++, Python, 
Perl, Java, even C#, to produce high-quality applications that integrate smoothly into 
the rest of your Unix or Linux desktop.
Organized

GNOME strives to be an organized community, with a foundation of several hundred members, 
usability, accessibility, and QA teams, and an elected board. GNOME releases are defined 
by the GNOME Release Team and are scheduled to occur every six months.
Supported

Beyond the worldwide GNOME Community, GNOME is supported by the leading companies in 
Linux and Unix, including HP, MandrakeSoft, Novell, Red Hat, and Sun. Find out more at 
foundation.gnome.org.
A community

Perhaps more than anything else, GNOME is a worldwide community of volunteers who hack, 
translate, design, QA, and generally have fun together. Find out more at GNOME Developer's site.
