2010-07-02 16 views

回答

0

在定義上下文菜單,每個無線電<menuitem>的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事件」信號:

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將「狀態」屬性設置爲「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尋找哪個無線電項目被檢查,但你最好使用事件處理程序來檢測用戶何時點擊一個。

通常,documentation for BonoboUIComponent in libbonoboui應該提供更多關於操作菜單中項目的方法的信息。

+0

我*知道*我已經在一段時間之前完成了這項工作,但卻忘記了如何。我終於找到了埋在外部硬盤上的四年前的代碼,這是我用來推導出上述答案的。鑑於迄今爲止缺乏意見,我想我不妨回答我自己的問題。 – 2010-07-03 03:22:42