[Glade-users] Dynamically adding menu items to menu bar
Jonathan Lane
lanej at horizon.com
Thu Feb 19 20:19:46 EST 2009
On Feb 19, 2009, at 7:29 PM, John Coppens wrote:
> On Thu, 19 Feb 2009 16:27:15 -0500
> Jonathan Lane <lanej at horizon.com> wrote:
>
>> I have a blank menu item in the menu bar named "commands_menuitem"
>> and
>> I want to add a submenu to it with menu items from a configuration
>> file. But whenever I ask gtk builder for the menu item, it returns a
>> GtkAction.
>
> Hi Jonathan,
>
> I couldn't find any way to make it work with Actions. That is, I
> managed
> to add a GtkAction to the Action group and all, but then I came to the
> conclusion that there wasn't an easy way to add it to the menu,
> which is
> separate in the glade file.
Can you think of any reason why this wouldn't work?
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);
}
> 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.
> 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 :)
-Jonathan
More information about the Glade-users
mailing list