在GtkBuilder XML中的GtkDialog中使用预定义的响应ID?

前端之家收集整理的这篇文章主要介绍了在GtkBuilder XML中的GtkDialog中使用预定义的响应ID?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法在GtkDialog中使用预定义的响应(例如,GTK_RESPONSE_OK),而无需对ID进行硬编码?默认情况下,Glade会在那里生成带“0”的 @L_403_0@,并为我提供一个数字条目.虽然我想我可以进入-5,但这似乎打败了一个常数.

Glade XML看起来像这样:

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

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

(这有点搞笑,因为他们使用-5(GTK_RESPONSE_OK)作为“button_cancel”……)

解决方法

从GTK 3.12开始,您可以使用nck-names作为响应.

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.

所以你现在可以做

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

猜你在找的XML相关文章