How to remove multiple selected rows from GtkTreeView/GtkListStore ?



gtk+2.1

Hi,

I am trying to remove all the rows that are selected in a GtkTreeView from the underlying GtkListStore. As we all know, in the docs it says that you cannot modify the model from within the function passed to gtk_tree_selection_selected_foreach(), so I am using gtk_tree_selection_get_selected_rows() and gtk_tree_row_reference_new_proxy()
as they recommend in the docs.

So, now I have a GList* of GtkTreePath's, and I use gtk_tree_row_reference_new_proxy() to
get a GtkTreeRowReference for each element from inside the function passed to g_list_foreach().

Now that I have a GtkTreeRowReference, and I want to remove a row from the GtkListStore, what
do I do?

This is what I have so far:
========================================================

void callback(GtkWidget* pWidget)
{
	GList* pRowList = gtk_tree_selection_get_selected_rows(pSelection,
							    &model);
     
	g_list_foreach(pRowList, delete_rows_foreach_func, model);
}

static void
delete_rows_foreach_func(gpointer data, gpointer user_data)
{
     GtkTreeIter* pIter;
     GtkTreePath* pTreePath;
     GObject* pProxy = G_OBJECT(g_object_new(G_TYPE_OBJECT, NULL));

     GtkTreeRowReference* pRowReference
	  = gtk_tree_row_reference_new_proxy(pProxy,
					     GTK_TREE_MODEL(user_data),
					     (GtkTreePath*)data);
     
     pTreePath = gtk_tree_row_reference_get_path(pRowReference);

     // *** This right here causes a segfault ***
     gtk_tree_model_get_iter(GTK_TREE_MODEL(user_data),
			     pIter,
			     pTreePath);

	// Now delete the row from the model
}

====================================================

This doesn't make sense... going from a GtkTreePath to a
GtkRowReference to a GtkTreePath to a GtkTreeIter seems real messy.
So I assume that what I'm doing is wrong -- but I don't know what else
to do.

What is the role of pProxy?

Thanks for any help.



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