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

Tha*_*tos 5 gtk glade

有没有办法在a中使用预定义的响应(例如GTK_RESPONSE_OK)GtkDialog,而无需对ID进行硬编码?默认情况下,Glade会在那里生成带"0"的XML,并为我提供一个数字条目.虽然我想我可以进入-5,但这似乎打败了一个常数.

Glade XML看起来像这样:

<action-widgets>
  <action-widget response="0">cancel-button</action-widget>
  <action-widget response="0">connect-button</action-widget>
</action-widgets>
Run Code Online (Sandbox Code Playgroud)

甚至文档中的示例:

<action-widgets>
  <action-widget response="3">button_ok</action-widget>
  <action-widget response="-5">button_cancel</action-widget>
</action-widgets>
Run Code Online (Sandbox Code Playgroud)

(这有点搞笑,因为他们使用-5(GTK_RESPONSE_OK)表示" button_cancel"...)

小智 1

从 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.
Run Code Online (Sandbox Code Playgroud)

所以你现在可以做

<action-widgets>
  <action-widget response="ok">button_ok</action-widget>
  <action-widget response="cancel">button_cancel</action-widget>
</action-widgets>
Run Code Online (Sandbox Code Playgroud)