[gnome-documents] places-links: don't use selection changed signal to emit link-activated



commit 9b9b81887cb9b113cf9dfe512c7cf504f632c4a1
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Jan 17 16:34:02 2013 -0500

    places-links: don't use selection changed signal to emit link-activated
    
    Instead, explicitly listen for button-release events and row-activated
    signals on the treeview. This makes both the dialog navigable with a
    keyboard and avoids popping up the controls after the mouse button is
    released, since the dialog was destroyed as soon as the mouse button was
    pressed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691567

 src/lib/gd-places-links.c |   38 ++++++++++++++++++++------------------
 1 files changed, 20 insertions(+), 18 deletions(-)
---
diff --git a/src/lib/gd-places-links.c b/src/lib/gd-places-links.c
index aab1ca2..b0635ba 100644
--- a/src/lib/gd-places-links.c
+++ b/src/lib/gd-places-links.c
@@ -36,7 +36,6 @@
 struct _GdPlacesLinksPrivate {
         GtkWidget *tree_view;
 
-        guint selection_id;
         guint page_changed_id;
         guint link_activated_id;
 
@@ -109,19 +108,28 @@ emit_link_activated (GdPlacesLinks *self)
 }
 
 static void
-selection_changed_cb (GtkTreeSelection *selection,
-                      GdPlacesLinks    *self)
+schedule_emit_link_activated (GdPlacesLinks *self)
 {
-        g_return_if_fail (self->priv->document != NULL);
-
         /* jump through some hoops to avoid destroying in the middle
-           of a button press handler */
+           of a button release handler */
         if (self->priv->link_activated_id == 0) {
-                self->priv->link_activated_id = g_idle_add ((GSourceFunc)emit_link_activated, self);
+                self->priv->link_activated_id = g_idle_add ((GSourceFunc) emit_link_activated, self);
         }
 }
 
 static gboolean
+button_release_event_cb (GtkWidget *widget,
+                         GdkEventButton *event,
+                         GdPlacesLinks *self)
+{
+        if (event->button == GDK_BUTTON_PRIMARY) {
+                schedule_emit_link_activated (self);
+        }
+
+        return FALSE;
+}
+
+static gboolean
 update_page_cb_foreach (GtkTreeModel  *model,
                         GtkTreePath   *path,
                         GtkTreeIter   *iter,
@@ -192,13 +200,9 @@ gd_places_links_set_current_page (GdPlacesLinks *self,
          * a GtkTreeModelSort here to make it faster, if it turns out to be
          * slow.
          */
-        g_signal_handler_block (selection, self->priv->selection_id);
-
         gtk_tree_model_foreach (model,
                                 (GtkTreeModelForeachFunc)update_page_cb_foreach,
                                 self);
-
-        g_signal_handler_unblock (selection, self->priv->selection_id);
 }
 
 static void
@@ -228,13 +232,6 @@ job_finished_cb (EvJobLinks     *job,
 
         gtk_tree_view_expand_all (GTK_TREE_VIEW (priv->tree_view));
 
-        if (priv->selection_id <= 0) {
-                priv->selection_id =
-                        g_signal_connect (selection, "changed",
-                                          G_CALLBACK (selection_changed_cb),
-                                          self);
-        }
-
         if (priv->page_changed_id <= 0) {
                 priv->page_changed_id =
                         g_signal_connect_swapped (priv->document_model, "page-changed",
@@ -288,6 +285,11 @@ gd_places_links_construct (GdPlacesLinks *self)
         /* Create tree view */
         priv->tree_view = gtk_tree_view_new ();
 
+        g_signal_connect (priv->tree_view, "button-release-event",
+                          G_CALLBACK (button_release_event_cb), self);
+        g_signal_connect_swapped (priv->tree_view, "row-activated",
+                                  G_CALLBACK (schedule_emit_link_activated), self);
+
         gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (priv->tree_view), FALSE);
         gtk_tree_view_set_level_indentation (GTK_TREE_VIEW (priv->tree_view), 20);
 



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