Using a predefined response ID in a GtkDialog in a GtkBuilder XML?

风格不统一 提交于 2019-12-10 14:42:51

问题


Is there any way to use a predefined response (e.g., GTK_RESPONSE_OK) in a GtkDialog, without hard-coding the ID? Glade generates XML with "0" there by default, and gives me a numeric entry. While I suppose I could enter -5, that seems to defeat the point of having a constant.

The Glade XML looks like this:

<action-widgets>
  <action-widget response="0">cancel-button</action-widget>
  <action-widget response="0">connect-button</action-widget>
</action-widgets>

Even the example in the docs:

<action-widgets>
  <action-widget response="3">button_ok</action-widget>
  <action-widget response="-5">button_cancel</action-widget>
</action-widgets>

(Which is a bit hilarious, given that they're using -5 (GTK_RESPONSE_OK) for "button_cancel"…)


回答1:


Since GTK 3.12 you can use nck-names for the response.

commit baa471ec130c360a5c4ae314769bc7b858814219
Author: Jasper St. Pierre <jstpierre@mecheye.net>
Date:   Mon Oct 28 11:19:43 2013 -0400

  gtkdialog: Allow specifying response IDs by nick in <action-widgets>

  This makes it a lot more convenient for developers, as they don't
  have to look up the numeric value of response IDs.

so you can now do

<action-widgets>
  <action-widget response="ok">button_ok</action-widget>
  <action-widget response="cancel">button_cancel</action-widget>
</action-widgets>


来源:https://stackoverflow.com/questions/18297382/using-a-predefined-response-id-in-a-gtkdialog-in-a-gtkbuilder-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!