Is there a way to put radio menu items in a GNOME panel applet's context menu, and then control which of the items is marked as active? The official documentation is less than helpful, and all of the applets installed on my computer use normal menu items, so I can't look at their source code for any guidance.
In the XML file defining the context menu, for each radio <menuitem>
set type="radio"
and the group
property to the name of the radio item group, like this:
<Root>
<popups>
<popup name="button3">
<menuitem name="Foo" verb="DoFoo" label="Foo is awesome" type="radio" group="mygroup"/>
<menuitem name="Bar" verb="DoBar" label="Bar is cool" type="radio" group="mygroup"/>
<menuitem name="Baz" verb="DoBaz" label="Baz rocks" type="radio" group="mygroup"/>
</popup>
</popups>
</Root>
You don't set up handlers to respond to the items being selected the same way you would for normal menu items. Instead, you listen for the "ui-event" signal on the BonoboUIComponent for the menu:
BonoboUIComponent *component = panel_applet_get_popup_component (applet);
g_signal_connect (component, "ui-event", G_CALLBACK (popup_component_ui_event_cb), NULL);
/* ... */
static void
popup_component_ui_event_cb (BonoboUIComponent *component,
const gchar *path,
Bonobo_UIComponent_EventType type,
const gchar *state_string,
gpointer data)
{
}
path
will be the full path (see below) of the item that was clicked. state_string
will be the new state value of the item (see below). There will be two events for each click of a radio item: one to deselect the old item, and one to select the new one.
To manipulate the checked state of the buttons, use bonobo_ui_component_set_prop
to set the "state" property to "0" (unchecked) or "1" (checked). To be safe, explicitly uncheck the old value; there are some corner cases where you could otherwise wind up with multiple radio items in the same group checked (particularly if the context menu hasn't yet actually been drawn).
BonoboUIComponent *component = panel_applet_get_popup_component (applet);
bonobo_ui_component_set_prop (component, "/commands/Foo", "state", "1", NULL);
bonobo_ui_component_set_prop (component, "/commands/Bar", "state", "0", NULL);
bonobo_ui_component_set_prop (component, "/commands/Baz", "state", "0", NULL);
Note that you identify the radio item by "/commands/name", where name is the name you gave the item in the XML file.
You could likewise use bonobo_ui_component_get_prop
to look for which radio item is checked, but you're better off using the event handlers to detect when the user clicks on one.
In general, the documentation for BonoboUIComponent in libbonoboui should provide more information about ways to manipulate items in the menu.