[epiphany/wip/mcatanzaro/fedora-needs-upstreamed: 23/32] Add ephy_tree_model_node_add_column_full



commit b25e979719fc5faa242ebc75c1ed7de47c8a0369
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Thu Dec 11 18:29:18 2014 +0100

    Add ephy_tree_model_node_add_column_full
    
    Allow creating a tree model column that derives its values from a
    property, but is modified by a function for display.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710004

 lib/widgets/ephy-tree-model-node.c |   54 ++++++++++++++++++++++--------------
 lib/widgets/ephy-tree-model-node.h |    6 ++++
 2 files changed, 39 insertions(+), 21 deletions(-)
---
diff --git a/lib/widgets/ephy-tree-model-node.c b/lib/widgets/ephy-tree-model-node.c
index bf97b7f..2859db5 100644
--- a/lib/widgets/ephy-tree-model-node.c
+++ b/lib/widgets/ephy-tree-model-node.c
@@ -335,19 +335,24 @@ ephy_tree_model_node_new (EphyNode *root)
 }
 
 /**
- * ephy_tree_model_node_add_prop_column:
+ * ephy_tree_model_node_add_column_full:
  * @model: an #EphyTreeModelNode
  * @value_type: type held by the new column
  * @prop_id: column in @model to get the value for this column
+ * @func: data function to be used to modify the value of the new column
+ * @user_data: optional user data for @func
  *
- * Add a new column to @model obtaining its value from @prop_id in @model.
+ * Add a new column to @model obtaining its value from @prop_id in @model,
+ * modified by @func.
  *
  * Returns: the id of the new column
  **/
 int
-ephy_tree_model_node_add_prop_column (EphyTreeModelNode *model,
+ephy_tree_model_node_add_column_full (EphyTreeModelNode *model,
                                      GType value_type,
-                                     int prop_id)
+                                     int prop_id,
+                                     EphyTreeModelNodeValueFunc func,
+                                     gpointer user_data)
 {
        EphyTreeModelNodeColData *col;
        int col_id;
@@ -355,8 +360,8 @@ ephy_tree_model_node_add_prop_column (EphyTreeModelNode *model,
        col = g_new0 (EphyTreeModelNodeColData, 1);
        col->prop_id = prop_id;
        col->type = value_type;
-       col->func = NULL;
-       col->user_data = NULL;
+       col->func = func;
+       col->user_data = user_data;
 
        g_ptr_array_add (model->priv->columns, col);
        col_id = model->priv->columns_num;
@@ -365,6 +370,25 @@ ephy_tree_model_node_add_prop_column (EphyTreeModelNode *model,
        return col_id;
 }
 
+
+/**
+ * ephy_tree_model_node_add_prop_column:
+ * @model: an #EphyTreeModelNode
+ * @value_type: type held by the new column
+ * @prop_id: column in @model to get the value for this column
+ *
+ * Add a new column to @model obtaining its value from @prop_id in @model.
+ *
+ * Returns: the id of the new column
+ **/
+int
+ephy_tree_model_node_add_prop_column (EphyTreeModelNode *model,
+                                     GType value_type,
+                                     int prop_id)
+{
+       return ephy_tree_model_node_add_column_full (model, value_type, prop_id, NULL, NULL);
+}
+
 /**
  * ephy_tree_model_node_add_func_column:
  * @model: an #EphyTreeModelNode
@@ -382,20 +406,7 @@ ephy_tree_model_node_add_func_column (EphyTreeModelNode *model,
                                      EphyTreeModelNodeValueFunc func,
                                      gpointer user_data)
 {
-       EphyTreeModelNodeColData *col;
-       int col_id;
-
-       col = g_new0 (EphyTreeModelNodeColData, 1);
-       col->prop_id = -1;
-       col->type = value_type;
-       col->func = func;
-       col->user_data = user_data;
-
-       g_ptr_array_add (model->priv->columns, col);
-       col_id = model->priv->columns_num;
-       model->priv->columns_num++;
-
-       return col_id;
+       return ephy_tree_model_node_add_column_full (model, value_type, -1, func, user_data);
 }
 
 static int
@@ -453,7 +464,8 @@ ephy_tree_model_node_get_value (GtkTreeModel *tree_model,
                        }
                }
        }
-       else
+
+       if (col->func)
        {
                col->func (node, value, col->user_data);
        }
diff --git a/lib/widgets/ephy-tree-model-node.h b/lib/widgets/ephy-tree-model-node.h
index 9a1053a..6ea68fa 100644
--- a/lib/widgets/ephy-tree-model-node.h
+++ b/lib/widgets/ephy-tree-model-node.h
@@ -56,6 +56,12 @@ GType              ephy_tree_model_node_get_type         (void);
 
 EphyTreeModelNode *ephy_tree_model_node_new              (EphyNode *root);
 
+int               ephy_tree_model_node_add_column_full  (EphyTreeModelNode* model,
+                                                         GType value_type,
+                                                         int prop_id,
+                                                         EphyTreeModelNodeValueFunc func,
+                                                         gpointer user_data);
+
 int                ephy_tree_model_node_add_prop_column  (EphyTreeModelNode *model,
                                                          GType value_type,
                                                          int prop_id);


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