Gtk2-Ex-MenuView
view release on metacpan or search on metacpan
lib/Gtk2/Ex/MenuView.pm view on Meta::CPAN
_dirty_menu ($menu);
}
#------------------------------------------------------------------------------
sub item_at_path {
my ($self, $path) = @_;
return $self->item_at_indices ($path->get_indices);
}
sub item_at_indices {
my $self = shift;
### item_at_indices(): @_
$self->{'model'} || return undef;
my $menu = $self;
my $menu_path = Gtk2::TreePath->new; # of $menu
my $item;
while (@_) {
my $i = shift;
$self->_freshen_item ($menu, $menu_path, $i);
(($item = $menu->{'children'}->[$i])
&& ($menu = $item->get_submenu))
or last;
$menu_path->append_index($i);
}
return $item;
}
#------------------------------------------------------------------------------
# _splice_maybe($aref,$offset,$len, $repl...)
# A splice() of @$aref, but only if $aref is not undef and $offset is not
# past its end.
sub _splice_maybe {
if (my $aref = shift) {
if ((my $pos = shift) <= $#$aref) {
splice @$aref, $pos, @_; # $len and values
}
}
}
#------------------------------------------------------------------------------
# sub insert {
# my ($self, $child, $pos) = @_;
# if ($pos >= 0 && $pos < $self->{'model_pos'}) {
# $self->{'model_pos'}--;
# }
# $self->SUPER::insert ($child, $pos);
# }
# sub prepend {
# my ($self, $child) = @_;
# $self->{'model_pos'}--;
# $self->SUPER::prepend ($child);
# }
1;
__END__
=for stopwords TreeModel MenuView Gtk undef menuview iter BUILDABLE menubar popup ComboBox renderer CellView renderers submenu MenuItem CellRenderer Subclassing RadioMenuItems toplevel submenus enum lookups CheckMenuItems CheckMenuItem iters recursin...
=head1 NAME
Gtk2::Ex::MenuView -- menu of items from a TreeModel
=for test_synopsis my ($my_model)
=head1 SYNOPSIS
use Gtk2::Ex::MenuView;
my $menuview = Gtk2::Ex::MenuView->new (model => $my_model);
$menuview->signal_connect (item_create_or_update => \&my_item_create);
$menuview->signal_connect (activate => \&my_item_activate);
sub my_item_create {
my ($menuview, $item, $model, $path, $iter) = @_;
# make item if not already done
if (! $item) {
$item = Gtk2::MenuItem->new_with_label ('');
}
# update its settings to display model data
my $label = $item->get_child;
my $str = $model->get ($iter, 0); # column 0
$label->set_text ($str);
return $item; # created or updated item
}
sub my_item_activate {
my ($menuview, $item, $model, $path, $iter) = @_;
print "an item was activated ...\n";
}
=head1 WIDGET HIERARCHY
C<Gtk2::Ex::MenuView> is a subclass of C<Gtk2::Menu>,
Gtk2::Widget
Gtk2::Container
Gtk2::MenuShell
Gtk2::Menu
Gtk2::Ex::MenuView::Menu
Gtk2::Ex::MenuView
The C<MenuView::Menu> subclass is an implementation detail (things common to
the toplevel menu and submenus), so don't rely on that.
=head1 DESCRIPTION
C<Gtk2::Ex::MenuView> presents rows and sub-rows of a C<Gtk2::TreeModel> as
a menu and sub-menus. The items update with changes in the model.
+--------------+
| Item One |
| Item Two => | +------------+
| Item Three | | Sub-item A |
+--------------+ | Sub-item B |
+------------+
The menu items are created by an C<item-create-or-update> callback signal
described below. It offers flexibility for item class and settings, but
( run in 1.057 second using v1.01-cache-2.11-cpan-364913b4093 )