[devhelp/wip/swilmet/various-code-improvements] book-tree: be able to jump back to the currently selected item



commit 579fb5f833ce7d9aa14cc9e8e23745ae7bfc8e99
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Nov 11 18:04:15 2015 +0100

    book-tree: be able to jump back to the currently selected item
    
    It's already done for the search hitlist in DhSidebar. So do it also for
    the book tree, for consistency and because it's something useful.

 src/dh-book-tree.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/src/dh-book-tree.c b/src/dh-book-tree.c
index fbc3ef1..3f589a0 100644
--- a/src/dh-book-tree.c
+++ b/src/dh-book-tree.c
@@ -698,16 +698,59 @@ dh_book_tree_constructed (GObject *object)
         G_OBJECT_CLASS (dh_book_tree_parent_class)->constructed (object);
 }
 
+/* Make it possible to jump back to the currently selected item, useful when the
+ * html view has been scrolled away.
+ */
+static gboolean
+dh_book_tree_button_press_event (GtkWidget      *widget,
+                                 GdkEventButton *event)
+{
+        DhBookTree *tree = DH_BOOK_TREE (widget);
+        DhBookTreePrivate *priv = dh_book_tree_get_instance_private (tree);
+        GtkTreePath *path;
+
+        gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree),
+                                       event->x, event->y,
+                                       &path, NULL, NULL, NULL);
+
+        if (path != NULL) {
+                GtkTreeIter iter;
+                DhLink *link;
+
+                gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->store), &iter, path);
+
+                gtk_tree_model_get (GTK_TREE_MODEL (priv->store),
+                                    &iter,
+                                    COL_LINK, &link,
+                                    -1);
+
+                g_signal_emit (tree, signals[LINK_SELECTED], 0, link);
+
+                gtk_tree_path_free (path);
+        }
+
+        /* Always propagate the event so the tree view can update
+         * the selection etc.
+         */
+        if (GTK_WIDGET_CLASS (dh_book_tree_parent_class)->button_press_event == NULL)
+                return GDK_EVENT_PROPAGATE;
+
+        return GTK_WIDGET_CLASS (dh_book_tree_parent_class)->button_press_event (widget, event);
+}
+
 static void
 dh_book_tree_class_init (DhBookTreeClass *klass)
 {
         GObjectClass *object_class = G_OBJECT_CLASS (klass);
+        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
         object_class->dispose = dh_book_tree_dispose;
         object_class->get_property = dh_book_tree_get_property;
         object_class->set_property = dh_book_tree_set_property;
         object_class->constructed = dh_book_tree_constructed;
 
+        widget_class->button_press_event = dh_book_tree_button_press_event;
+
         g_object_class_install_property (object_class,
                                          PROP_BOOK_MANAGER,
                                          g_param_spec_object ("book-manager",


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