[gtranslator] Use property instead of function to set tab for GtrMessageTable



commit 944f515a591cfdd76dbd8dc9bf8cdc8c1ca0df94
Author: Seán de Búrca <leftmostcat gmail com>
Date:   Fri Sep 6 09:04:30 2013 -0600

    Use property instead of function to set tab for GtrMessageTable

 src/gtr-message-table.c |   73 +++++++++++++++++++++++++++++++++++++++++------
 src/gtr-message-table.h |    2 -
 src/gtr-tab.c           |    2 -
 src/gtr-tab.ui          |    1 +
 4 files changed, 65 insertions(+), 13 deletions(-)
---
diff --git a/src/gtr-message-table.c b/src/gtr-message-table.c
index e8f25ab..11be93a 100644
--- a/src/gtr-message-table.c
+++ b/src/gtr-message-table.c
@@ -37,6 +37,12 @@
 #include <glib-object.h>
 #include <gtk/gtk.h>
 
+enum
+{
+  PROP_0,
+  PROP_TAB
+};
+
 typedef struct
 {
   GtkWidget *treeview;
@@ -241,12 +247,70 @@ gtr_message_table_finalize (GObject * object)
 }
 
 static void
+gtr_message_table_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  GtrMessageTable *table = GTR_MESSAGE_TABLE (object);
+  GtrMessageTablePrivate *priv;
+
+  priv = gtr_message_table_get_instance_private (table);
+
+  switch (prop_id)
+    {
+    case PROP_TAB:
+      priv->tab = GTR_TAB (g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gtr_message_table_get_property (GObject    *object,
+                                guint       prop_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+  GtrMessageTable *table = GTR_MESSAGE_TABLE (object);
+  GtrMessageTablePrivate *priv;
+
+  priv = gtr_message_table_get_instance_private (table);
+
+  switch (prop_id)
+    {
+    case PROP_TAB:
+      g_value_set_object (value, priv->tab);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
 gtr_message_table_class_init (GtrMessageTableClass * klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   object_class->finalize = gtr_message_table_finalize;
+  object_class->set_property = gtr_message_table_set_property;
+  object_class->get_property = gtr_message_table_get_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_TAB,
+                                   g_param_spec_object ("tab",
+                                                        "TAB",
+                                                        "The active tab",
+                                                        GTR_TYPE_TAB,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY));
 
   gtk_widget_class_set_template_from_resource (widget_class,
                                                "/org/gnome/gtranslator/ui/gtr-message-table.ui");
@@ -278,15 +342,6 @@ gtr_message_table_new (void)
   return GTK_WIDGET (obj);
 }
 
-void
-gtr_message_table_set_tab (GtrMessageTable *table, GtrTab *tab)
-{
-  GtrMessageTablePrivate *priv;
-
-  priv = gtr_message_table_get_instance_private (table);
-  priv->tab = tab;
-}
-
 /**
  * gtr_message_table_populate:
  * @table: a #GtrMessageTable
diff --git a/src/gtr-message-table.h b/src/gtr-message-table.h
index 68cfa0c..65cb4fa 100644
--- a/src/gtr-message-table.h
+++ b/src/gtr-message-table.h
@@ -76,8 +76,6 @@ gtr_message_table_get_type (void)
 
      GtkWidget *gtr_message_table_new (void);
 
-     void gtr_message_table_set_tab (GtrMessageTable *table, GtrTab *tab);
-
      void gtr_message_table_populate (GtrMessageTable * table,
                                       GtrMessageContainer * container);
 
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index 26c7864..6cdb719 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -808,8 +808,6 @@ gtr_tab_new (GtrPo * po)
   /* Now we have to initialize the number of msgstr tabs */
   gtr_tab_add_msgstr_tabs (tab);
 
-  gtr_message_table_set_tab (GTR_MESSAGE_TABLE (priv->message_table), tab);
-
   gtr_message_table_populate (GTR_MESSAGE_TABLE (priv->message_table),
                               GTR_MESSAGE_CONTAINER (priv->po));
 
diff --git a/src/gtr-tab.ui b/src/gtr-tab.ui
index 787bbb3..6c14da7 100644
--- a/src/gtr-tab.ui
+++ b/src/gtr-tab.ui
@@ -19,6 +19,7 @@
               <object class="GtrMessageTable" id="message_table">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="tab">GtrTab</property>
               </object>
               <packing>
                 <property name="expand">True</property>


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