Re: [gtk-list] Destroying popup menus (possible bug)



>  I'm using context-sensitive popup menus, which are created on the fly
>  and are to be deleted as soon as they pop down.
>  
>  To delete the menu I added a 'deactivate' signal to it:
>  
>    gtk_signal_connect_object (GTK_OBJECT (menu), "deactivate",
>          GTK_SIGNAL_FUNC(gtk_widget_destroy),
>          GTK_OBJECT(menu));
>  
>  However, if any menu items are selected, the menu disappears but the
>  menuitem 'activate' signal handlers are not called. I assume the
>  problem is that the menu is destroyed before the handler is called.

This is correct.  

>  Should it be changed so that menuitem 'activate' handlers are called
>  before the menu 'deactivate' handler?

I don't think so.  This would mean that the menu would stay on the
screen while the activate handlers run, which would be a bad thing.

I experienced the exact same problem you had when writing some popups
for the Gnome version of the Midnight Commander.  My solution is to
gtk_signal_connect_object_after to the activate signal of the
menuitems, and put the destroy handler there:

menu = gtk_menu_new ();

item = gtk_menu_item_new_with_label ("Hello world");
gtk_signal_connect (GTK_OBJECT (item), "activate", 
		    (GtkSignalFunc) my_hello_world_handler,
		    NULL);
gtk_signal_connect_object_after (GTK_OBJECT (item), "activate",
				 (GtkSignalFunc) gtk_widget_destroy,
				 GTK_OBJECT (menu));
gtk_menu_append (GTK_MENU (menu), item);
gtk_widget_show (item);

  Quartic



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