#!/usr/bin/perl -w

use Gtk2;

Gtk2->init;

$m{'win'} = new Gtk2::Window('toplevel');
# $m{'win'}->signal_connect('delete-event', sub { Gtk2->main_quit; });
$m{'win'}->signal_connect('destroy', sub { Gtk2->main_quit; });

$m{'win'}->set_title("TEST");

$m{'vbox'} = new Gtk2::VBox(0,1);
$m{'win'}->add($m{'vbox'});

@menu_items = ( { path            => '/Main',
		  item_type       => '<Branch>' },
		{ path            => '/Main/_TV',
		  accelerator     => '<control>T',
		  callback        => \&do_tv },
		{ path            => '/Main/_Print',
		  accelerator     => '<control>P',
		  callback        => \&do_print },
		{ path            => '/Main/_Exit',
		  accelerator     => '<control>E',
		  callback        => sub { Gtk2->main_quit; } },

		{ path            => '/_Perfs',
		  item_type       => '<Branch>' },
		{ path            => '/Perfs/_Settings',
 		  accelerator     => '<control>S',
		  callback        => \&do_settings },

		{ path            => '/_Help',
		  item_type       => '<LastBranch>' },
		{ path            => '/Help/About',
		  callback        => \&do_about } );

$m{'menubar'} = create_menubar( $m{'win'} );
$m{'vbox'}->pack_start($m{'menubar'}, 0, 1, 0);

sub create_menubar {
        my  ( $window ) = @_;
        my $item_factory;
        my $accel_group;
        $accel_group = new Gtk2::AccelGroup();
        $item_factory = new Gtk2::ItemFactory( 'Gtk2::MenuBar',
					       '<main>', $accel_group);
        $item_factory->create_items( @menu_items);
        $window->add_accel_group($accel_group);
        return ($item_factory->get_widget('<main>'));
}

$m{'win'}->show_all;


main Gtk2;
exit(0);

sub do_print
{
  print "Menu Print\n";
}

sub do_tv
{
  print "Menu TV\n";
}
sub do_settings
{
  print "Menu Settings\n";
}
sub do_about
{
  print "Menu About\n";
}
