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.
Share
In the XML file defining the context menu, for each radio
<menuitem>settype="radio"and thegroupproperty to the name of the radio item group, like this: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:
pathwill be the full path (see below) of the item that was clicked.state_stringwill 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_propto 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).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_propto 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.