使用vala和glade ui,我没有在林间空地分配信号签名。但是我确实在glade中创建了一个名为“new_action”的Gtk.Action对象:
<object class="GtkAction" id="new_action">
<property name="label" translatable="yes">New</property>
<property name="short_label" translatable="yes">New</property>
<property name="tooltip" translatable="yes">Create a new DESKTOP file</property>
<property name="stock_id">gtk-new</property>
<property name="is_important">True</property>
</object>
稍后,这是使用“new_action”的按钮:
<object class="GtkToolButton" id="new_toolbutton">
<property name="related_action">new_action</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="related_action">new_action</property>
<property name="label" translatable="yes">New</property>
<property name="use_underline">True</property>
</object>
在代码中我首先得到Gtk.Builder:
Gtk.Builder builder.add_from_file ("azoth.ui");
然后我创建我的动作对象并分配lambda函数:
this.connect_components (); /* my code - shown below in this question */
this.builder.connect_signals (this);
然后在vala中(使用Gtk.Builder)我从构建器中分配了一个var new_action:
this.new_action = this.builder.get_object ("new_action") as Gtk.Action;
然后我在代码中为它创建了一个lambda:
this.new_action.activate.connect (() => {
stdout.printf ("You activated the NEW action!\n");
}
运行时,我点击“新建”按钮,没有输出到stdout。我觉得我可能会错过一个步骤,因为概念很简单,并且很容易在代码中生成动作回调,而不必在glade中定义回调。