diff options
author | Matthias Clasen <mclasen@redhat.com> | 2015-01-19 07:32:31 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2015-01-19 07:36:08 -0500 |
commit | 531fa7860135cd339475d5411dd8630313990e91 (patch) | |
tree | c0533e2a9321c155e51b589709209bb20db68b39 /demos | |
parent | dc952e3d949644b101ab819eca0502a3661e897e (diff) | |
download | gtk+-531fa7860135cd339475d5411dd8630313990e91.tar.gz |
gtk-demo: Make editable cells demo more robust
When removing all rows, trying to add rows would not work
and throw criticals. This is fallout from a recent change
to insert rows at the right position. Fix this by handling
the 'empty model' case separately.
https://bugzilla.gnome.org/show_bug.cgi?id=743157
Diffstat (limited to 'demos')
-rw-r--r-- | demos/gtk-demo/editable_cells.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/demos/gtk-demo/editable_cells.c b/demos/gtk-demo/editable_cells.c index 18ff4771ed..717bf50fdc 100644 --- a/demos/gtk-demo/editable_cells.c +++ b/demos/gtk-demo/editable_cells.c @@ -158,11 +158,18 @@ add_item (GtkWidget *button, gpointer data) /* Insert a new row below the current one */ gtk_tree_view_get_cursor (treeview, &path, NULL); model = gtk_tree_view_get_model (treeview); - gtk_tree_model_get_iter (model, ¤t, path); - gtk_tree_path_free (path); + if (path) + { + gtk_tree_model_get_iter (model, ¤t, path); + gtk_tree_path_free (path); + gtk_list_store_insert_after (GTK_LIST_STORE (model), &iter, ¤t); + } + else + { + gtk_list_store_insert (GTK_LIST_STORE (model), &iter, -1); + } /* Set the data for the new row */ - gtk_list_store_insert_after (GTK_LIST_STORE (model), &iter, ¤t); gtk_list_store_set (GTK_LIST_STORE (model), &iter, COLUMN_ITEM_NUMBER, foo.number, COLUMN_ITEM_PRODUCT, foo.product, |