summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2013-12-22 18:17:32 +0000
committerMatthias Clasen <mclasen@redhat.com>2014-12-11 09:20:37 -0500
commitc68490ee17941c6ca356a4aabb103053497df40b (patch)
treef9e0567feb66122a240ab21e72de8ae098ed3127
parent7833835930467ac82b22084cb139253f9bde60a4 (diff)
downloadgtk+-c68490ee17941c6ca356a4aabb103053497df40b.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
-rw-r--r--demos/gtk-demo/editable_cells.c25
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, &current, path);
+ gtk_tree_path_free (path);
+
+ /* Set the data for the new row */
+ gtk_list_store_insert_after (GTK_LIST_STORE (model), &iter, &current);
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");