From 98f768009939e3b06f2777ccb4307245f0637f36 Mon Sep 17 00:00:00 2001 From: Xan Lopez Date: Fri, 25 Apr 2003 16:06:19 +0000 Subject: Implement ephy_node_reorder_children (from Rhythmbox). Implement ephy_node_reorder_children (from Rhythmbox). --- lib/ephy-node.c | 53 ++++++++++++++++++++++++++++++++++++++ lib/ephy-node.h | 6 +++-- lib/widgets/ephy-tree-model-node.c | 16 ++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/ephy-node.c b/lib/ephy-node.c index f3283cc88..42477c6f3 100644 --- a/lib/ephy-node.c +++ b/lib/ephy-node.c @@ -93,6 +93,7 @@ enum CHILD_ADDED, CHILD_CHANGED, CHILD_REMOVED, + CHILDREN_REORDERED, LAST_SIGNAL }; @@ -202,6 +203,16 @@ ephy_node_class_init (EphyNodeClass *klass) G_TYPE_NONE, 1, EPHY_TYPE_NODE); + ephy_node_signals[CHILDREN_REORDERED] = + g_signal_new ("children_reordered", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EphyNodeClass, children_reordered), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, + 1, + G_TYPE_POINTER); } static gboolean @@ -1225,6 +1236,48 @@ ephy_node_has_child (EphyNode *node, return ret; } +void +ephy_node_reorder_children (EphyNode *node, + int *new_order) +{ + GPtrArray *newkids; + int i; + + g_return_if_fail (EPHY_IS_NODE (node)); + g_return_if_fail (new_order != NULL); + + lock_gdk (); + + g_static_rw_lock_writer_lock (node->priv->lock); + + newkids = g_ptr_array_new (); + g_ptr_array_set_size (newkids, node->priv->children->len); + + for (i = 0; i < node->priv->children->len; i++) { + EphyNode *child; + EphyNodeParent *node_info; + + child = g_ptr_array_index (node->priv->children, i); + + g_ptr_array_index (newkids, new_order[i]) = child; + + node_info = g_hash_table_lookup (child->priv->parents, + GINT_TO_POINTER (node->priv->id)); + node_info->index = new_order[i]; + } + + g_ptr_array_free (node->priv->children, FALSE); + node->priv->children = newkids; + + write_lock_to_read_lock (node); + + g_signal_emit (G_OBJECT (node), ephy_node_signals[CHILDREN_REORDERED], 0, new_order); + + g_static_rw_lock_reader_unlock (node->priv->lock); + + unlock_gdk (); +} + GPtrArray * ephy_node_get_children (EphyNode *node) { diff --git a/lib/ephy-node.h b/lib/ephy-node.h index f257ebb1e..8c142d528 100644 --- a/lib/ephy-node.h +++ b/lib/ephy-node.h @@ -53,8 +53,7 @@ typedef struct void (*child_added) (EphyNode *node, EphyNode *child); void (*child_changed) (EphyNode *node, EphyNode *child); - void (*child_reordered) (EphyNode *node, EphyNode *child, - int old_index, int new_index); + void (*children_reordered) (EphyNode *node, int *new_order); void (*child_removed) (EphyNode *node, EphyNode *child); } EphyNodeClass; @@ -122,6 +121,9 @@ void ephy_node_remove_child (EphyNode *node, gboolean ephy_node_has_child (EphyNode *node, EphyNode *child); +void ephy_node_reorder_children (EphyNode *node, + int *new_order); + /* Note that ephy_node_get_children freezes the node; you'll have to thaw it when done. * This is to prevent the data getting changed from another thread. */ GPtrArray *ephy_node_get_children (EphyNode *node); diff --git a/lib/widgets/ephy-tree-model-node.c b/lib/widgets/ephy-tree-model-node.c index 180e24879..6ea3544e9 100644 --- a/lib/widgets/ephy-tree-model-node.c +++ b/lib/widgets/ephy-tree-model-node.c @@ -74,6 +74,9 @@ static void root_child_added_cb (EphyNode *node, static void root_child_changed_cb (EphyNode *node, EphyNode *child, EphyTreeModelNode *model); +static void root_children_reordered_cb (EphyNode *node, + int *new_order, + EphyTreeModelNode *model); static inline void ephy_tree_model_node_update_node (EphyTreeModelNode *model, EphyNode *node, int idx); @@ -263,6 +266,11 @@ ephy_tree_model_node_set_property (GObject *object, G_CALLBACK (root_child_changed_cb), G_OBJECT (model), 0); + g_signal_connect_object (G_OBJECT (model->priv->root), + "children_reordered", + G_CALLBACK (root_children_reordered_cb), + G_OBJECT (model), + 0); g_signal_connect_object (G_OBJECT (model->priv->root), "destroyed", G_CALLBACK (root_destroyed_cb), @@ -714,6 +722,14 @@ root_child_changed_cb (EphyNode *node, ephy_tree_model_node_update_node (model, child, -1); } +static void +root_children_reordered_cb (EphyNode *node, + int *new_order, + EphyTreeModelNode *model) +{ + gtk_tree_model_rows_reordered (GTK_TREE_MODEL (model), NULL, NULL, new_order); +} + static void root_destroyed_cb (EphyNode *node, EphyTreeModelNode *model) -- cgit