[gtk+] gtk-demo: Make double-click work again



commit f123fe7fe710a8254ce9d13eefd64705cadc6920
Author: Benjamin Otte <otte redhat com>
Date:   Fri Dec 13 16:01:18 2013 +0100

    gtk-demo: Make double-click work again

 demos/gtk-demo/main.c |   53 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 40 insertions(+), 13 deletions(-)
---
diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c
index 4e239d5..ac8e5d8 100644
--- a/demos/gtk-demo/main.c
+++ b/demos/gtk-demo/main.c
@@ -105,23 +105,16 @@ window_closed_cb (GtkWidget *window, gpointer data)
 }
 
 static void
-activate_run (GSimpleAction *action,
-              GVariant      *parameter,
-              gpointer       user_data)
+run_example_for_row (GtkWidget    *window,
+                     GtkTreeModel *model,
+                     GtkTreeIter  *iter)
 {
-  GtkWidget *window = user_data;
-  GtkTreeSelection *selection;
-  GtkTreeModel *model;
-  GtkTreeIter iter;
   PangoStyle style;
   GDoDemoFunc func;
   GtkWidget *demo;
 
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
-  gtk_tree_selection_get_selected (selection, &model, &iter);
-
   gtk_tree_model_get (GTK_TREE_MODEL (model),
-                      &iter,
+                      iter,
                       FUNC_COLUMN, &func,
                       STYLE_COLUMN, &style,
                       -1);
@@ -129,7 +122,7 @@ activate_run (GSimpleAction *action,
   if (func)
     {
       gtk_tree_store_set (GTK_TREE_STORE (model),
-                          &iter,
+                          iter,
                           STYLE_COLUMN, (style == PANGO_STYLE_ITALIC ? PANGO_STYLE_NORMAL : 
PANGO_STYLE_ITALIC),
                           -1);
       demo = (func) (window);
@@ -140,7 +133,7 @@ activate_run (GSimpleAction *action,
 
           cbdata = g_new (CallbackData, 1);
           cbdata->model = model;
-          cbdata->path = gtk_tree_model_get_path (model, &iter);
+          cbdata->path = gtk_tree_model_get_path (model, iter);
 
           if (gtk_widget_is_toplevel (demo))
             {
@@ -154,6 +147,22 @@ activate_run (GSimpleAction *action,
     }
 }
 
+static void
+activate_run (GSimpleAction *action,
+              GVariant      *parameter,
+              gpointer       user_data)
+{
+  GtkWidget *window = user_data;
+  GtkTreeSelection *selection;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  gtk_tree_selection_get_selected (selection, &model, &iter);
+
+  run_example_for_row (window, model, &iter);
+}
+
 /* Stupid syntax highlighting.
  *
  * No regex was used in the making of this highlighting.
@@ -918,6 +927,22 @@ startup (GApplication *app)
 }
 
 static void
+row_activated_cb (GtkWidget         *tree_view,
+                  GtkTreePath       *path,
+                  GtkTreeViewColumn *column)
+{
+  GtkTreeIter iter;
+  GtkWidget *window;
+  GtkTreeModel *model;
+
+  window = gtk_widget_get_toplevel (tree_view);
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
+  gtk_tree_model_get_iter (model, &iter, path);
+
+  run_example_for_row (window, model, &iter);
+}
+
+static void
 activate (GApplication *app)
 {
   GtkBuilder *builder;
@@ -956,6 +981,8 @@ activate (GApplication *app)
 
   populate_model (model);
 
+  g_signal_connect (treeview, "row-activated", G_CALLBACK (row_activated_cb), model);
+
   widget = (GtkWidget *)gtk_builder_get_object (builder, "treeview-selection");
   g_signal_connect (widget, "changed", G_CALLBACK (selection_cb), model);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]