Re: Help removing GtkListStore rows

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

 



Ok

A fixed "remove" function from the treestoretest.c example:

static void
iter_remove (GtkWidget *button, GtkTreeView *tree_view)
{
	GtkTreeIter selected, selected_sort;
	GtkTreeModel *model;
	GtkTreeModelSort *model_sort;
	GtkTreePath *path_sort, *path;

	if( gtk_tree_selection_get_selected
		( gtk_tree_view_get_selection( tree_view ),
			&model, &selected ) )
	{
		if( GTK_IS_TREE_MODEL_SORT( model ) ) {
			model_sort = GTK_TREE_MODEL_SORT( model );
			model = gtk_tree_model_sort_get_model( model_sort );
			gtk_tree_model_sort_convert_iter_to_child_iter
				( model_sort, &selected_sort, &selected );
			path = gtk_tree_model_get_path( model, &selected_sort );
			path_sort = gtk_tree_model_sort_convert_child_path_to_path
				( model_sort, path );
			gtk_tree_path_free( path );
			gtk_tree_store_remove( GTK_TREE_STORE( model ), &selected_sort );
			if( gtk_tree_model_get_iter( model, &selected, path_sort )
				|| gtk_tree_path_prev( path_sort ) )
			{
				gtk_tree_selection_select_path
					( gtk_tree_view_get_selection( tree_view ), path_sort );
			}
			gtk_tree_path_free( path_sort );
		}
		else if( GTK_IS_TREE_STORE( model ) )
		{
			path = gtk_tree_model_get_path( model, &selected );
			if( gtk_tree_store_remove( GTK_TREE_STORE( model ), &selected ) ) {
				gtk_tree_selection_select_iter
					( gtk_tree_view_get_selection( tree_view ), &selected );
			}
			else {
				if( gtk_tree_path_prev( path ) )
					gtk_tree_selection_select_path
						( gtk_tree_view_get_selection( tree_view ), path );
			}
			gtk_tree_path_free( path );
		}
	}
}

HTH

Jan-Marek
_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux