[Glade-users] Dynamically adding menu items to menu bar



On Thu, 19 Feb 2009 20:19:46 -0500
Jonathan Lane <lanej at horizon.com> wrote:

GtkWidget *cmds_menu;
GtkAction *action;
GtkWidget *w;

cmds_menu = gtk_menu_new();
action = GTK_ACTION(gtk_builder_get_object(builder,  
"commands_menuitem"));
w = gtk_action_create_menu_item(action);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(w), cmds_menu);

/* Applications from cfg file
*/
for (i = 0; i < g_list_length(app_cfg->procs); i++) {
    struct app_proc *proc = g_list_nth_data(app_cfg->procs, i);
    assert(proc != NULL);

    action = gtk_action_new(proc->name, proc->desc, NULL, NULL);
    w = gtk_action_create_menu_item(action);
    gtk_menu_shell_insert(GTK_MENU_SHELL(cmds_menu), w, -1);
    gtk_widget_show(w);
}


This is about the same I tried to do. The cast GTK_MENU_SHELL(cmds_menu)
gave a runtime problem, because the type of cmds_menu wasn't MENUSHELL.
if I recall rightly. If you look it up inside the .xml, you'll see that
the menu structure is somewhat separate from the rest.

I did find an example where the menu is directly built in XML inside  
the
source file, then read in.

Do you have a link for that?  I'd really appreciate it.

It's a bit longish:

http://www.delorie.com/pcb/cvs/src/hid/gtk/gui-top-window.c

Tristan observed that using the 3.5.7 version of Glade (probably any
3.5.x), Glade can export the GtkBuilder files directly and supports
the 'normal' 'oldie' GtkMenuItems and GtkMenus - no Actions. Then,  
adding
items was quite a bit easier!

If you can, change to the newer version.

The problem is that I am set to release tomorrow.  I have to finish  
this tonight, and I noticed other issues (namely with toolbars) going  
from 3.4.5 (debian/unstable) to 3.5.2 (debian/experimental).  And I'm  
already quite tired :)

I have a couple of toolbars which work fine, but I believe I can't define
new ones. Tried, and gave up. A buttonbar did the same for me. Teh
advantages of 3.5.7 (which I compiled myself) are enough to take a few
other problems along.

John




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