support notify attribute for properties
authorJuerg Billeter <j@bitron.ch>
Thu, 20 Sep 2007 09:21:32 +0000 (09:21 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 20 Sep 2007 09:21:32 +0000 (09:21 +0000)
2007-09-20  Juerg Billeter  <j@bitron.ch>

* vala/valaproperty.vala, gobject/valaccodegenerator.vala: support
  notify attribute for properties

svn path=/trunk/; revision=621

ChangeLog
gobject/valaccodegenerator.vala
vala/valaproperty.vala

index 80c44f9..893712f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
+2007-09-20  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaproperty.vala, gobject/valaccodegenerator.vala: support
+         notify attribute for properties
+
 2007-09-19  Alberto Ruiz <aruiz@gnome.org>
+
        * vala-1.0.pc.in: add vapigen variable,
          fixes bug 477111
 
index 56b03ff..e4bcc8c 100644 (file)
@@ -643,6 +643,14 @@ public class Vala.CCodeGenerator : CodeGenerator {
                                function.block = (CCodeBlock) acc.body.ccodenode;
 
                                function.block.prepend_statement (create_property_type_check_statement (prop, acc.readable, t, true, "self"));
+
+                               // notify on property changes
+                               if (prop.notify && (acc.writable || acc.construction)) {
+                                       var notify_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_notify"));
+                                       notify_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("self"), "GObject *"));
+                                       notify_call.add_argument (prop.get_canonical_cconstant ());
+                                       function.block.add_statement (new CCodeExpressionStatement (notify_call));
+                               }
                        }
                        
                        source_type_member_definition.append (function);
index 89995b6..444c9c6 100644 (file)
@@ -45,7 +45,13 @@ public class Vala.Property : Member, Lockable {
         * Represents the generated ´this' parameter in this property.
         */
        public FormalParameter this_parameter { get; set; }
-       
+
+       /**
+        * Specifies whether a `notify' signal should be emitted on property
+        * changes.
+        */
+       public bool notify { get; set; }
+
        /**
         * Specifies whether the implementation of this property does not
         * provide getter/setter methods.
@@ -168,7 +174,9 @@ public class Vala.Property : Member, Lockable {
         */
        public void process_attributes () {
                foreach (Attribute a in attributes) {
-                       if (a.name == "NoAccessorMethod") {
+                       if (a.name == "Notify") {
+                               notify = true;
+                       } else if (a.name == "NoAccessorMethod") {
                                no_accessor_method = true;
                        }
                }