[vala] gtkmodule: Ensure child gtypes are initialized before creating the template
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] gtkmodule: Ensure child gtypes are initialized before creating the template
- Date: Tue, 28 Jan 2014 22:49:40 +0000 (UTC)
commit 8f9979da7a75cb91a46e47e61bf35a41c8ff8083
Author: Luca Bruno <lucabru src gnome org>
Date: Tue Jan 28 23:47:24 2014 +0100
gtkmodule: Ensure child gtypes are initialized before creating the template
Fixes bug 720282
codegen/valagtkmodule.vala | 18 ++++++++++++++++--
codegen/valagtypemodule.vala | 8 +++++---
2 files changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valagtkmodule.vala b/codegen/valagtkmodule.vala
index 603ec60..b6c9c30 100644
--- a/codegen/valagtkmodule.vala
+++ b/codegen/valagtkmodule.vala
@@ -1,4 +1,3 @@
-
/* valagtkmodule.vala
*
* Copyright (C) 2013 Jürg Billeter
@@ -32,6 +31,8 @@ public class Vala.GtkModule : GSignalModule {
private HashMap<string, Signal> current_handler_to_signal_map = new HashMap<string, Signal>(str_hash,
str_equal);
/* GtkBuilder xml child to Vala class mapping */
private HashMap<string, Class> current_child_to_class_map = new HashMap<string, Class>(str_hash,
str_equal);
+ /* Required custom application-specific gtype classes to be ref'd before initializing the template */
+ private HashSet<Class> current_required_app_classes = new HashSet<Class>();
private void ensure_cclass_to_vala_map () {
// map C name of gtypeinstance classes to Vala classes
@@ -199,6 +200,8 @@ public class Vala.GtkModule : GSignalModule {
call.add_argument (new CCodeIdentifier ("GTK_WIDGET_CLASS (klass)"));
call.add_argument (new CCodeConstant ("\""+cl.get_attribute_string ("GtkTemplate",
"ui")+"\""));
ccode.add_expression (call);
+
+ current_required_app_classes.clear ();
}
public override void visit_field (Field f) {
@@ -261,6 +264,10 @@ public class Vala.GtkModule : GSignalModule {
ccode.add_expression (call);
pop_context ();
+
+ if (!field_class.external && !field_class.external_package) {
+ current_required_app_classes.add (field_class);
+ }
}
public override void visit_method (Method m) {
@@ -307,11 +314,18 @@ public class Vala.GtkModule : GSignalModule {
}
- public override void generate_instance_init (Class cl) {
+ public override void end_instance_init (Class cl) {
if (cl == null || cl.error || !is_gtk_template (cl)) {
return;
}
+ foreach (var req in current_required_app_classes) {
+ /* ensure custom application widgets are initialized */
+ var call = new CCodeFunctionCall (new CCodeIdentifier ("g_type_ensure"));
+ call.add_argument (get_type_id_expression (SemanticAnalyzer.get_data_type_for_symbol
(req)));
+ ccode.add_expression (call);
+ }
+
var call = new CCodeFunctionCall (new CCodeIdentifier ("gtk_widget_init_template"));
call.add_argument (new CCodeIdentifier ("GTK_WIDGET (self)"));
ccode.add_expression (call);
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 5fd74a0..26778eb 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1166,7 +1166,7 @@ public class Vala.GTypeModule : GErrorModule {
public virtual void generate_class_init (Class cl) {
}
- public virtual void generate_instance_init (Class cl) {
+ public virtual void end_instance_init (Class cl) {
}
private void begin_class_init_function (Class cl) {
@@ -1573,12 +1573,14 @@ public class Vala.GTypeModule : GErrorModule {
func.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"),
"priv"), ccall);
}
- generate_instance_init (cl);
-
pop_context ();
}
private void add_instance_init_function (Class cl) {
+ push_context (instance_init_context);
+ end_instance_init (cl);
+ pop_context ();
+
cfile.add_function (instance_init_context.ccode);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]