在GtkBuilder XML的GtkDialog中使用预定义的响应ID? [英] Using a predefined response ID in a GtkDialog in a GtkBuilder XML?

查看:133
本文介绍了在GtkBuilder XML的GtkDialog中使用预定义的响应ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 GtkDialog 中使用预定义的响应(例如, GTK_RESPONSE_OK ),编码ID? Glade默认生成带有0的XML,并给我一个数字输入。虽然我想我可以输入-5,这似乎打破了一个常数点。

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.

Glade XML看起来像这样:

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>

即使文档中的例子

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

(这有点搞笑,因为它们使用-5( GTK_RESPONSE_OK )for < button_cancel ...)

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

推荐答案

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

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>

这篇关于在GtkBuilder XML的GtkDialog中使用预定义的响应ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆