GNOME 面板小程序上下文菜单中的单选项目
有没有办法将单选菜单项放入 GNOME 面板小程序的上下文菜单中,然后控制哪些项目被标记为活动? 官方文档帮助不大,并且所有我的计算机上安装的小程序使用普通的菜单项,因此我无法查看它们的源代码以获取任何指导。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在定义上下文菜单的 XML 文件中,对于每个单选
将
type="radio"
和group
属性设置为名称单选项目组的属性,如下所示:您无需像处理普通菜单项那样设置处理程序来响应所选择的项目。相反,您会监听 BonoboUIComponent 上菜单的“ui-event”信号:
path
将是所单击项目的完整路径(见下文)。state_string
将是该项目的新状态值(见下文)。每次单击单选项目都会发生两个事件:一个是取消选择旧项目,另一个是选择新项目。要操作按钮的选中状态,请使用
bonobo_ui_component_set_prop
将“state”属性设置为“0”(未选中)或“1”(选中)。为了安全起见,请显式取消选中旧值;在某些特殊情况下,您可能会在同一组中检查多个单选项目(特别是在尚未实际绘制上下文菜单的情况下)。请注意,您可以通过“/commands/name”来标识单选项目,其中 name 是您在 XML 文件中为该项目指定的名称。
您可以同样使用
bonobo_ui_component_get_prop
来查找检查了哪个单选项目,但您最好使用事件处理程序来检测用户何时单击其中一项。一般来说,libbonoboui 中 BonoboUIComponent 的文档 应提供有关操作菜单中项目的方法的更多信息。
In the XML file defining the context menu, for each radio
<menuitem>
settype="radio"
and thegroup
property 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:
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).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.