GNOME 面板小程序上下文菜单中的单选项目

发布于 2024-09-08 09:14:28 字数 221 浏览 0 评论 0原文

有没有办法将单选菜单项放入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往事风中埋 2024-09-15 09:14:28

在定义上下文菜单的 XML 文件中,对于每个单选 type="radio"group 属性设置为名称单选项目组的属性,如下所示:

<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>

您无需像处理普通菜单项那样设置处理程序来响应所选择的项目。相反,您会监听 BonoboUIComponent 上菜单的“ui-event”信号:

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 将是所单击项目的完整路径(见下文)。 state_string 将是该项目的新状态值(见下文)。每次单击单选项目都会发生两个事件:一个是取消选择旧项目,另一个是选择新项目。

要操作按钮的选中状态,请使用 bonobo_ui_component_set_prop 将“state”属性设置为“0”(未选中)或“1”(选中)。为了安全起见,请显式取消选中旧值;在某些特殊情况下,您可能会在同一组中检查多个单选项目(特别是在尚未实际绘制上下文菜单的情况下)。

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);

请注意,您可以通过“/commands/name”来标识单选项目,其中 name 是您在 XML 文件中为该项目指定的名称。

可以同样使用bonobo_ui_component_get_prop来查找检查了哪个单选项目,但您最好使用事件处理程序来检测用户何时单击其中一项。

一般来说,libbonoboui 中 BonoboUIComponent 的文档 应提供有关操作菜单中项目的方法的更多信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文