[nautilus-actions] Fix multi-childs insert into



commit 6bdf2eb08c5c0a997c7440ac9b6b33fd8af4d926
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Oct 9 11:33:04 2009 +0200

    Fix multi-childs insert into

 ChangeLog                     |    9 +++++++++
 src/nact/nact-iactions-list.c |   35 +++++++++++++++++------------------
 src/nact/nact-tree-model.c    |   24 +++++++++++++++++++++++-
 3 files changed, 49 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9c5ddf9..c63cd33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-10-09 Pierre Wieser <pwieser trychlos org>
+
+	* src/nact/nact-iactions-list.c (do_insert_into_first):
+	Fix multi-childs insertion.
+	Remove useless do_insert_into_second() function.
+
+	* src/nact/nact-tree-model.c (nact_tree_model_insert):
+	Add debug traces.
+
 2009-10-08 Pierre Wieser <pwieser trychlos org>
 
 	* src/common/na-object-api.h (na_object_remove_item):
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index bea9424..2d080ec 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -137,7 +137,6 @@ static void         decrement_counters( NactIActionsList *instance, IActionsList
 static GtkTreePath *get_selection_first_path( GtkTreeView *treeview );
 static void         do_insert_items( GtkTreeView *treeview, GtkTreeModel *model, GList *items, GtkTreePath *path, GList **parents );
 static NAObject    *do_insert_into_first( GtkTreeView *treeview, GtkTreeModel *model, GList *items, GtkTreePath *insert_path, GtkTreePath **new_path );
-static GtkTreePath *do_insert_into_second( GtkTreeView *treeview, GtkTreeModel *model, NAObject *object, GtkTreePath *insert_path, NAObject **parent );
 static void         increment_counters( NactIActionsList *instance, IActionsListInstanceData *ialid, GList *items );
 static void         update_parents_edition_status( GList *parents, GList *items );
 
@@ -1098,39 +1097,39 @@ do_insert_items( GtkTreeView *treeview, GtkTreeModel *model, GList *items, GtkTr
 static NAObject *
 do_insert_into_first( GtkTreeView *treeview, GtkTreeModel *model, GList *items, GtkTreePath *insert_path, GtkTreePath **new_path )
 {
+	static const gchar *thisfn = "nact_iactions_list_do_insert_into_first";
+	GList *copy;
 	GList *last;
 	NAObject *parent;
+	gchar *insert_path_str;
 	GtkTreePath *inserted_path;
 
+	insert_path_str = gtk_tree_path_to_string( insert_path );
+	g_debug( "%s: treeview=%p, model=%p, items=%p (count=%d), insert_path=%p (%s), new_path=%p",
+			thisfn,
+			( void * ) treeview, ( void * ) model, ( void * ) items, g_list_length( items ),
+			( void * ) insert_path, insert_path_str, ( void * ) new_path );
+	g_free( insert_path_str );
+
 	parent = NULL;
-	last = g_list_last( items );
-	items = g_list_remove_link( items, last );
+	copy = g_list_copy( items );
+	last = g_list_last( copy );
+	copy = g_list_remove_link( copy, last );
 
-	inserted_path = do_insert_into_second( treeview, model, NA_OBJECT( last->data ), insert_path, &parent );
-	do_insert_items( treeview, model, items, inserted_path, NULL );
+	inserted_path = nact_tree_model_insert_into( NACT_TREE_MODEL( model ), NA_OBJECT( last->data ), insert_path, &parent );
+	gtk_tree_view_expand_to_path( treeview, inserted_path );
+	do_insert_items( treeview, model, copy, inserted_path, NULL );
 
 	if( new_path ){
 		*new_path = gtk_tree_path_copy( inserted_path );
 	}
 
+	g_list_free( copy );
 	gtk_tree_path_free( inserted_path );
 
 	return( parent );
 }
 
-static GtkTreePath *
-do_insert_into_second( GtkTreeView *treeview, GtkTreeModel *model, NAObject *object, GtkTreePath *insert_path, NAObject **parent )
-{
-	/*static const gchar *thisfn = "nact_iactions_list_do_insert_into";*/
-	GtkTreePath *new_path;
-
-	new_path = nact_tree_model_insert_into( NACT_TREE_MODEL( model ), object, insert_path, parent );
-
-	gtk_tree_view_expand_to_path( treeview, new_path );
-
-	return( new_path );
-}
-
 static void
 increment_counters( NactIActionsList *instance, IActionsListInstanceData *ialid, GList *items )
 {
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index b9fd3f6..e4301fa 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -741,8 +741,9 @@ fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview,
 void
 nact_tree_model_insert( NactTreeModel *model, const NAObject *object, GtkTreePath *path, NAObject **parent )
 {
-	/*static const gchar *thisfn = "nact_tree_model_insert";*/
+	static const gchar *thisfn = "nact_tree_model_insert";
 	GtkTreeModel *store;
+	gchar *path_str;
 	GtkTreeIter iter;
 	GtkTreeIter parent_iter;
 	GtkTreePath *parent_path;
@@ -752,6 +753,13 @@ nact_tree_model_insert( NactTreeModel *model, const NAObject *object, GtkTreePat
 	NAObject *sibling_obj;
 	gboolean has_sibling;
 
+	path_str = gtk_tree_path_to_string( path );
+	g_debug( "%s: model=%p, object=%p (%s, ref_count=%d), path=%p (%s), parent=%p",
+			thisfn,
+			( void * ) model,
+			( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count,
+			( void * ) path, path_str, ( void * ) parent );
+	g_free( path_str );
 	g_return_if_fail( NACT_IS_TREE_MODEL( model ));
 	g_return_if_fail( NA_IS_OBJECT( object ));
 
@@ -770,6 +778,7 @@ nact_tree_model_insert( NactTreeModel *model, const NAObject *object, GtkTreePat
 			gtk_tree_model_get( store, &sibling_iter, IACTIONS_LIST_NAOBJECT_COLUMN, &sibling_obj, -1 );
 			g_object_unref( sibling_obj );
 		}
+		g_debug( "%s: has_sibling=%s, sibling_obj=%p", thisfn, has_sibling ? "True":"False", ( void * ) sibling_obj );
 
 		if( gtk_tree_path_get_depth( path ) > 1 ){
 
@@ -794,13 +803,18 @@ nact_tree_model_insert( NactTreeModel *model, const NAObject *object, GtkTreePat
 
 			na_object_set_parent( object, parent_obj );
 		}
+		g_debug( "%s: has_parent=%s, parent_obj=%p", thisfn, has_parent ? "True":"False", ( void * ) parent_obj );
 
 		gtk_tree_store_insert_before(
 				GTK_TREE_STORE( store ), &iter,
 				has_parent ? &parent_iter : NULL,
 				has_sibling ? &sibling_iter : NULL );
+		g_debug( "un" );
+		g_debug( "%s: iter_is_valid=%s", thisfn, gtk_tree_store_iter_is_valid( GTK_TREE_STORE( store ), &iter ) ? "True":"False" );
 		gtk_tree_store_set( GTK_TREE_STORE( store ), &iter, IACTIONS_LIST_NAOBJECT_COLUMN, object, -1 );
+		g_debug( "deux" );
 		display_item( GTK_TREE_STORE( store ), model->private->treeview, &iter, object );
+		g_debug( "trois" );
 	}
 }
 
@@ -814,6 +828,13 @@ nact_tree_model_insert_into( NactTreeModel *model, const NAObject *object, GtkTr
 	GtkTreePath *new_path;
 	gchar *path_str;
 
+	path_str = gtk_tree_path_to_string( path );
+	g_debug( "%s: model=%p, object=%p (%s, ref_count=%d), path=%p (%s), parent=%p",
+			thisfn,
+			( void * ) model,
+			( void * ) object, G_OBJECT_TYPE_NAME( object ), G_OBJECT( object )->ref_count,
+			( void * ) path, path_str, ( void * ) parent );
+	g_free( path_str );
 	g_return_val_if_fail( NACT_IS_TREE_MODEL( model ), NULL );
 	g_return_val_if_fail( NA_IS_OBJECT( object ), NULL );
 
@@ -1516,6 +1537,7 @@ idrag_dest_drag_data_received( GtkTreeDragDest *drag_dest, GtkTreePath *dest, Gt
 					} else {
 						g_return_val_if_fail( NA_IS_OBJECT_ACTION( action ), FALSE );
 						object_list = g_list_prepend( NULL, action );
+						na_object_dump( action );
 						nact_iactions_list_insert_at_path( NACT_IACTIONS_LIST( main_window ), object_list, dest );
 						g_list_free( object_list );
 					}



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