Re: How to destroy a GtkMenu?

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

 



On 18 March 2011 19:42, Vikram Ambrose <noel.ambrose@xxxxxxxxx> wrote:
> My Menus are not static. Depending on what you've right-clicked on you get
> different options.
>
> I need to destroy them.

For dynamic menus, I think the best solution is to treat them like
static menus for the purposes of lifetime management, but to modify
them as they pop up.

I connect to the "map" signal on the outermost menu, and in that
handler, scoop out the insides of the menu and rebuild it. Something
like:

        mainw->recent_menu = ...
        g_signal_connect( mainw->recent_menu, "map",
                G_CALLBACK( mainw_recent_map_cb ), mainw );


static void
mainw_recent_map_cb( GtkWidget *widget, Mainw *mainw )
{
        GtkWidget *menu = mainw->recent_menu;
        GtkWidget *item;

        gtk_container_foreach( GTK_CONTAINER( menu ),
                (GtkCallback) gtk_widget_destroy, NULL );

                item = gtk_menu_item_new_with_label( _( "Recent Images" ) );
                gtk_menu_append( GTK_MENU( menu ), item );
                gtk_widget_show( item );

etc.

John
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list


[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux