[gnome-builder] object: add vfuncs for getter/setter and use them



commit 6153940bb53e917e0855cc433ac41921e0f614f3
Author: Christian Hergert <chergert redhat com>
Date:   Sat Mar 11 01:45:13 2017 -0800

    object: add vfuncs for getter/setter and use them
    
    Chain up here instead of doing our funky only chain-up after setting
    phase. This should make things more predictable for subclasses that
    need to do anything funny, and Vala.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779891

 libide/ide-object.c |   28 ++++++++++++++++++++++------
 libide/ide-object.h |    7 ++++---
 2 files changed, 26 insertions(+), 9 deletions(-)
---
diff --git a/libide/ide-object.c b/libide/ide-object.c
index ec53777..49af07e 100644
--- a/libide/ide-object.c
+++ b/libide/ide-object.c
@@ -94,6 +94,14 @@ ide_object_release_context (gpointer  data,
   ide_object_destroy (self);
 }
 
+static IdeContext *
+ide_object_real_get_context (IdeObject *self)
+{
+  IdeObjectPrivate *priv = ide_object_get_instance_private (self);
+
+  return priv->context;
+}
+
 /**
  * ide_object_get_context:
  *
@@ -104,17 +112,25 @@ ide_object_release_context (gpointer  data,
 IdeContext *
 ide_object_get_context (IdeObject *self)
 {
-  IdeObjectPrivate *priv = ide_object_get_instance_private (self);
-
   g_return_val_if_fail (IDE_IS_OBJECT (self), NULL);
 
-  return priv->context;
+  return IDE_OBJECT_GET_CLASS (self)->get_context (self);
 }
 
 void
 ide_object_set_context (IdeObject  *self,
                         IdeContext *context)
 {
+  g_return_if_fail (IDE_IS_OBJECT (self));
+  g_return_if_fail (!context || IDE_IS_CONTEXT (context));
+
+  IDE_OBJECT_GET_CLASS (self)->set_context (self, context);
+}
+
+static void
+ide_object_real_set_context (IdeObject  *self,
+                             IdeContext *context)
+{
   IdeObjectPrivate *priv = ide_object_get_instance_private (self);
 
   g_assert (IDE_IS_OBJECT (self));
@@ -138,9 +154,6 @@ ide_object_set_context (IdeObject  *self,
                              self);
         }
 
-      if (IDE_OBJECT_GET_CLASS (self)->set_context)
-        IDE_OBJECT_GET_CLASS (self)->set_context (self, context);
-
       g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CONTEXT]);
     }
 }
@@ -211,6 +224,9 @@ ide_object_class_init (IdeObjectClass *klass)
   object_class->get_property = ide_object_get_property;
   object_class->set_property = ide_object_set_property;
 
+  klass->get_context = ide_object_real_get_context;
+  klass->set_context = ide_object_real_set_context;
+
   properties [PROP_CONTEXT] =
     g_param_spec_object ("context",
                          "Context",
diff --git a/libide/ide-object.h b/libide/ide-object.h
index 642723b..6169939 100644
--- a/libide/ide-object.h
+++ b/libide/ide-object.h
@@ -33,9 +33,10 @@ struct _IdeObjectClass
 {
   GObjectClass parent;
 
-  void (*destroy)     (IdeObject  *self);
-  void (*set_context) (IdeObject  *self,
-                       IdeContext *context);
+  void        (*destroy)     (IdeObject  *self);
+  IdeContext *(*get_context) (IdeObject  *self);
+  void        (*set_context) (IdeObject  *self,
+                              IdeContext *context);
 };
 
 IdeContext *ide_object_get_context             (IdeObject            *self);


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