diff options
author | Benjamin Otte <otte@redhat.com> | 2011-12-14 13:49:31 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2011-12-16 04:53:15 +0100 |
commit | 070124b0a54166b17f8609bbdf942eb08f3f5ec3 (patch) | |
tree | ca63ed5998ec8f0808cf6ad41962a81acd17e6fd /tests/testtreechanging.c | |
parent | f5621a3a8e8d91a8bc1e310eb38763c703a913d8 (diff) | |
download | gtk+-070124b0a54166b17f8609bbdf942eb08f3f5ec3.tar.gz |
tests: Add test resetting the model
We first set a NULL model and then reset the old model, just to get the
effect of clearing and then resetting.
We reset the cursor and selection afterwards, so the reset doesn't
destroy all the work we did.
Diffstat (limited to 'tests/testtreechanging.c')
-rw-r--r-- | tests/testtreechanging.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/tests/testtreechanging.c b/tests/testtreechanging.c index f8b90ff2d5..106fc3704a 100644 --- a/tests/testtreechanging.c +++ b/tests/testtreechanging.c @@ -63,7 +63,7 @@ log_operation_for_path (GtkTreePath *path, { char *path_string; - path_string = gtk_tree_path_to_string (path); + path_string = path ? gtk_tree_path_to_string (path) : g_strdup (""); g_printerr ("%10s %s\n", operation_name, path_string); @@ -288,6 +288,39 @@ unselect (GtkTreeView *treeview) &iter); } +static void +reset_model (GtkTreeView *treeview) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GList *list, *selected; + GtkTreePath *cursor; + + selection = gtk_tree_view_get_selection (treeview); + model = g_object_ref (gtk_tree_view_get_model (treeview)); + + log_operation_for_path (NULL, "reset"); + + selected = gtk_tree_selection_get_selected_rows (selection, NULL); + gtk_tree_view_get_cursor (treeview, &cursor, NULL); + + gtk_tree_view_set_model (treeview, NULL); + gtk_tree_view_set_model (treeview, model); + + if (cursor) + { + gtk_tree_view_set_cursor (treeview, cursor, NULL, FALSE); + gtk_tree_path_free (cursor); + } + for (list = selected; list; list = list->next) + { + gtk_tree_selection_select_path (selection, list->data); + } + g_list_free_full (selected, (GDestroyNotify) gtk_tree_path_free); + + g_object_unref (model); +} + /* sanity checks */ static void @@ -363,7 +396,8 @@ dance (gpointer treeview) expand, collapse, select_, - unselect + unselect, + reset_model }; guint i; |