package menu;

use strict;

use Gtk2;
use Gtk2::SimpleMenu;

# bar menu
my $menu_tree = [
    _File  => {item_type  => '<Branch>',
        children => [
            '_Open Database' => {
                callback => \&::db::opendb,
                accelerator => '<ctrl>O',
            },
            '_Close Database' => {
                                callback => \&::db::closedb,
                accelerator => '<ctrl>C',
            },
            Separator => {
                item_type => '<Separator>',
             },
            _Exit => {
                callback => sub { Gtk2->main_quit; },
                accelerator => '<ctrl>E',
            },
        ],
    },
    _Tools  => {
        item_type => '<Branch>',
        children => [
            Tearoff => {
                item_type => '<Tearoff>',
            },
            "Resample" => {
                callback => \&::tools::addtool,
                callback_action => 1,
            },
            "Methods" => {
                item_type => '<Branch>',
                children => [
                    "Boostap-t" => {
                        item_type => '<RadioItem>',
			callback => \&::tools::setmethod,
			callback_action => 13,
                        groupid => 1,
                    },
                    "Nested Bootstap-t" => {
                        item_type => '<RadioItem>',
			callback => \&::tools::setmethod,
			callback_action => 11,
                        groupid => 1,
                    },
                    "Bootstap Percentile" => {
                        item_type => '<RadioItem>',
			callback => \&::tools::setmethod,
			callback_action => 12,
                        groupid => 1,
                    },
                ],
            },
	    "Univaried"  => {
                item_type => '<Branch>',
                children => [
                    "Mean" => {
                        callback => \&::tools::addtool,
                        callback_action => 21,
                    },
                    "Median" => {
                        callback => \&::tools::addtool,
                        callback_action => 22,
                    },
                ],
            },
            "Bi-variance" => {
                item_type => '<Branch>',
                children => [
                    "Mean" => {
                        callback => \&::tools::addtool,
                        callback_action => 31,
                    },
                ],
            },
            "Percentile Intervale" => {
                callback => \&::tools::addtool,
                callback_action => 2,
            },
        ],
    },
    _Display => {
        item_type => '<Branch>',
        children => [
            Tearoff => {
                item_type => '<Tearoff>',
            },
            "Table" => {
                callback => \&::displays::adddisplay,
                callback_action => 1,
            },
            "Avg. value" => {
                callback => \&::displays::adddisplay,
                callback_action => 2,
            },
            "Graph" => {
                callback => \&::displays::adddisplay,
                callback_action => 3,
            },
            "Histogram" => {
                callback => \&::displays::adddisplay,
                callback_action => 4,
            },
            "Adapt. Hist." => {
                callback => \&::displays::adddisplay,
                callback_action => 5,
            },
        ],
    },
    _Help => {
        item_type => '<LastBranch>',
        children => [
            _Introduction => {
                callback => \&::misc::help,
            },
            _About => {
                callback => \&::misc::about,
            }
        ],
    },
];

our $bar = Gtk2::SimpleMenu->new(menu_tree => $menu_tree);

# box context menu
my $context_item1 = Gtk2::MenuItem->new("Show");
my $context_item2 = Gtk2::MenuItem->new("Properties");
my $context_item3 = Gtk2::MenuItem->new();
my $context_item4 = Gtk2::MenuItem->new("Close");

$context_item1->signal_connect(activate => \&box::show);
$context_item2->signal_connect(activate => \&box::property);
$context_item4->signal_connect(activate => \&box::close);

$context_item1->show();
$context_item2->show();
$context_item3->show();
$context_item4->show();

our $context = Gtk2::Menu->new();

$context->append($context_item1);
$context->{item}->{show} = $context_item1;
$context->append($context_item2);
$context->{item}->{properties} = $context_item2;
$context->append($context_item3);
$context->append($context_item4);
$context->{item}->{close} = $context_item4;

1;
