Re: How to destroy a GtkMenu?

On 18 March 2011 19:42, Vikram Ambrose <noel ambrose gmail com> 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

        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 );



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