Re: dynamic menus



David NeÄas (Yeti) wrote:
On Wed, Feb 21, 2007 at 10:40:07PM -0500, Dan McMahill wrote:

Question #1

- is it possible to keep certain menuitems in the xml and the associated GtkActionEntry but toggle if they are visible or not? Something like gtk_widget_hide() and gtk_widget_show()? Or do I have to basically tear down the menus, regen the xml and create the menus again?


1. GtkAction has "visibility" property.
2. GtkUIManager can demerge UIs.

Choose what's more suitable for your use case...


Question #2

- What does it take to change the text in some menus that already exist? Do I have to do
  gtk_ui_manager_remove_action_group()

then create a new action group, insert to the ui manager and call gtk_action_group_add_actions?

Or is there a simpler way?


GtkAction has "label" property.

Thanks! The visibility property worked for me. For the sake of completeness in the archives here, what I ended up doing was something like this:

update_menu()
{
  GValue setfalse = { 0 };
  GValue settrue = { 0 };
  GValue setlabel = { 0 };
  GtkAction *a;

  g_value_init (&setfalse, G_TYPE_BOOLEAN);
  g_value_init (&settrue, G_TYPE_BOOLEAN);

  g_value_set_boolean (&setfalse, FALSE);
  g_value_set_boolean (&settrue, TRUE);

  g_value_init (&setlabel, G_TYPE_STRING);
  g_value_set_string (&setlabel, "my new menu text");

  a = gtk_action_group_get_action (main_actions, "MyAction");
g_object_set_property (G_OBJECT (a), "visible", want_it_to_be_visible
       ? &settrue : &setfalse);
  g_object_set_property (G_OBJECT (a), "label", &setlabel);
}

Seems to work nicely. Note: I have an old (2.4) gtk install on one system so I didn't use gtk_action_set_visible() which appeared in gtk-2.6.

-Dan



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