diff options
author | Phillip Wood <phillip.wood@dunelm.org.uk> | 2013-12-22 18:17:32 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2014-12-07 18:53:30 -0500 |
commit | 6b26464fbb334ef723c1783c8a62b0c091f592b4 (patch) | |
tree | 2541f3e992f740f19797c7278b14092d410b1114 /demos | |
parent | 06745bc0aadf04a17d9433e0c150eb5f91d1adb5 (diff) | |
download | gtk+-6b26464fbb334ef723c1783c8a62b0c091f592b4.tar.gz |
Editable cells demo: Add new row at cursor
Adding rows to the bottom of the list is confusing as you cannot see
them if the window is small so it is not apparent that anything has
happened. Fix this by adding the new row immediately below the current
row and set the cursor on the new row so it is ready to be edited.
https://bugzilla.gnome.org/show_bug.cgi?id=721939
Diffstat (limited to 'demos')
-rw-r--r-- | demos/gtk-demo/editable_cells.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/demos/gtk-demo/editable_cells.c b/demos/gtk-demo/editable_cells.c index 917a84e4c3..18ff4771ed 100644 --- a/demos/gtk-demo/editable_cells.c +++ b/demos/gtk-demo/editable_cells.c @@ -142,8 +142,11 @@ static void add_item (GtkWidget *button, gpointer data) { Item foo; - GtkTreeIter iter; - GtkTreeModel *model = (GtkTreeModel *)data; + GtkTreeIter current, iter; + GtkTreePath *path; + GtkTreeModel *model; + GtkTreeViewColumn *column; + GtkTreeView *treeview = (GtkTreeView *)data; g_return_if_fail (articles != NULL); @@ -152,12 +155,26 @@ add_item (GtkWidget *button, gpointer data) foo.yummy = 50; g_array_append_vals (articles, &foo, 1); - gtk_list_store_append (GTK_LIST_STORE (model), &iter); + /* 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); + + /* 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, COLUMN_ITEM_YUMMY, foo.yummy, -1); + + /* Move focus to the new row */ + path = gtk_tree_model_get_path (model, &iter); + column = gtk_tree_view_get_column (treeview, 0); + gtk_tree_view_set_cursor (treeview, path, column, FALSE); + + gtk_tree_path_free (path); } static void @@ -368,7 +385,7 @@ do_editable_cells (GtkWidget *do_widget) button = gtk_button_new_with_label ("Add item"); g_signal_connect (button, "clicked", - G_CALLBACK (add_item), items_model); + G_CALLBACK (add_item), treeview); gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); button = gtk_button_new_with_label ("Remove item"); |