[vala/staging] codegen: Support automatic properties as GtkChild



commit ac6758f8f8a73e52fb2bec0fbe7eb3d18fc5a09a
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Apr 23 17:12:03 2018 +0200

    codegen: Support automatic properties as GtkChild
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787034

 codegen/valagtkmodule.vala |    4 ++--
 vala/valaproperty.vala     |    5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valagtkmodule.vala b/codegen/valagtkmodule.vala
index 56c839d..bd54f9c 100644
--- a/codegen/valagtkmodule.vala
+++ b/codegen/valagtkmodule.vala
@@ -259,8 +259,8 @@ public class Vala.GtkModule : GSignalModule {
        }
 
        public override void visit_property (Property prop) {
-               if (prop.get_attribute ("GtkChild") != null) {
-                       Report.error (prop.source_reference, "Annotating properties with [GtkChild] is not 
yet supported");
+               if (prop.get_attribute ("GtkChild") != null && prop.field == null) {
+                       Report.error (prop.source_reference, "[GtkChild] is only allowed on automatic 
properties");
                }
 
                base.visit_property (prop);
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index 81bb849..1bc54a5 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -118,6 +118,11 @@ public class Vala.Property : Symbol, Lockable {
                                                _field = new Field ("_%s".printf (name), property_type.copy 
(), initializer, source_reference);
                                                _field.access = SymbolAccessibility.PRIVATE;
                                                _field.binding = binding;
+                                               // apply gtk-child attribute to backing field for 
gtk-template support
+                                               if (get_attribute ("GtkChild") != null) {
+                                                       _field.set_attribute_string ("GtkChild", "name", 
get_attribute_string ("GtkChild", "name", name));
+                                                       _field.set_attribute_bool ("GtkChild", "internal", 
get_attribute_bool ("GtkChild", "internal"));
+                                               }
                                        }
                                }
                                _field_checked = true;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]