Multiple menu popups with a single Gtk2::SimpleList



Hi,


I'm trying to display a popup menu in a Gtk2::SimpleList which can have different menu choices depending on the data in the Gtk2::SimpleList.


The menu popup choices are driven by the value selected from a Gtk2::ComboBox. There is a signal on the combobox that runs the popup sub below when the value changes.


The first time the popup menu is invoked it displays correctly; displaying the appropriate popup menu. The next time I select a different value from the Gtk2::ComboBox and right click it a row in the Gtk2::SimpleList, it continues to show the old popup in addition to the new one.


It's seems the Gtk2::SimpleList won't let go of menus you associate.


Here is a sample code snippet of what's not working.

sub popup {

my $menu;

if ($type eq 'type1') {
$menu = Gtk2::Menu->new();
my $menu_item = Gtk2::MenuItem->('Properties');
$menu_item->signal_connect(activate => sub {
# do something
});

$menu->append($menu_item);

} elsif ($type eq 'type2') {
$menu = Gtk2::Menu->new();
my $menu_item = Gtk2::MenuItem->('View');
$menu_item->signal_connect(activate => sub {
# do something else
});

$menu->append($menu_item);
}

$simple_list =>signal_connect('button-press-event' => sub {
my ($widget, $event) = @_;
return FALSE unless $event->button eq 3;
$menu->popup (
undef,
undef,
undef,
undef,
$event->button,
$event->time);
}

$menu->show_all;

}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]