Deleting multiple selections from list store
- From: Linus Walleij <triad df lth se>
- To: gtk-list gnome org
- Subject: Deleting multiple selections from list store
- Date: Thu, 22 May 2003 18:06:17 +0200 (MEST)
I've been having a hard time devising a routine that deletes all the
selected rows in a view from a list store using the new GTK+-2.0 MVC
component. I sort of came up with this rather idiomatic way of doing
things, and want to know if I'm doing it right:
void remove_selected(GtkListStore *s, GtkTreeView *v)
{
GtkTreeModel *model = GTK_TREE_MODEL(s);
GList *selection;
GtkTreeSelection *select = gtk_tree_view_get_selection(v);
selection = gtk_tree_selection_get_selected_rows(select, &model);
while (selection != NULL) {
GList *tmp;
GtkTreeIter iter;
tmp = g_list_first(selection);
/* Get the iterator for the first row and remove it */
if (gtk_tree_model_get_iter(GTK_TREE_MODEL(get_store(listtype)),
&iter,
(GtkTreePath *) tmp->data)) {
gtk_list_store_remove(get_store(listtype), &iter);
}
/*
* We have to free this selection list and get the
* paths again, because when we removed the line
* all path references changed and are now invalid.
*/
g_list_foreach (selection, (GFunc) gtk_tree_path_free, NULL);
g_list_free(selection);
select = gtk_tree_view_get_selection(v);
selection = gtk_tree_selection_get_selected_rows(select, &model);
}
}
This seems so awkward and most of all inefficient, that one intuitively
believe that there is either another way, or that you're simply not
supposed to remove multiple selections from the store, cause that's
complicated :-)
Yours,
Linus Walleij
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]