[evince] shell: Fix navigation with annotation already selected in sidebar



commit 86a5c5468ed3e9680fa66e17dbae9fb14ec40c5b
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Tue Sep 26 16:33:15 2017 -0300

    shell: Fix navigation with annotation already selected in sidebar
    
    This fixes the issue when an annotation is selected in the
    sidebar, the user navigates the document, and when if the
    user clicks on the same annotation, then nothing happens.
    But Evince should go to the page of the annotation selected.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=680880

 libview/ev-view.c              |    3 --
 shell/ev-sidebar-annotations.c |   60 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 52 insertions(+), 11 deletions(-)
---
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 197cd3d..ae49674 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -2220,9 +2220,6 @@ _ev_view_set_focused_element (EvView *view,
        GdkRectangle    view_rect;
        cairo_region_t *region = NULL;
 
-       if (view->focused_element == element_mapping)
-               return;
-
        if (view->accessible)
                ev_view_accessible_set_focused_element (EV_VIEW_ACCESSIBLE (view->accessible), 
element_mapping, page);
 
diff --git a/shell/ev-sidebar-annotations.c b/shell/ev-sidebar-annotations.c
index b73573f..2815f82 100644
--- a/shell/ev-sidebar-annotations.c
+++ b/shell/ev-sidebar-annotations.c
@@ -219,21 +219,61 @@ ev_sidebar_annotations_annot_removed (EvSidebarAnnotations *sidebar_annots)
 }
 
 static void
-selection_changed_cb (GtkTreeSelection     *selection,
-                     EvSidebarAnnotations *sidebar_annots)
+ev_sidebar_annotations_activate_result_at_iter (EvSidebarAnnotations *sidebar_annots,
+                                                GtkTreeModel  *model,
+                                                GtkTreeIter   *iter)
 {
-       GtkTreeModel *model;
-       GtkTreeIter   iter;
-
-       if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
                EvMapping *mapping = NULL;
 
-               gtk_tree_model_get (model, &iter,
+               gtk_tree_model_get (model, iter,
                                    COLUMN_ANNOT_MAPPING, &mapping,
                                    -1);
                if (mapping)
                        g_signal_emit (sidebar_annots, signals[ANNOT_ACTIVATED], 0, mapping);
-       }
+}
+
+static void
+selection_changed_cb (GtkTreeSelection     *selection,
+                     EvSidebarAnnotations *sidebar_annots)
+{
+       GtkTreeModel *model;
+       GtkTreeIter   iter;
+
+       if (gtk_tree_selection_get_selected (selection, &model, &iter))
+           ev_sidebar_annotations_activate_result_at_iter (sidebar_annots, model, &iter);
+}
+
+static gboolean
+sidebar_tree_button_press_cb (GtkTreeView    *view,
+                              GdkEventButton *event,
+                              EvSidebarAnnotations  *sidebar_annots)
+{
+        GtkTreeModel         *model;
+        GtkTreePath          *path;
+        GtkTreeIter           iter;
+        GtkTreeSelection     *selection;
+
+        gtk_tree_view_get_path_at_pos (view, event->x, event->y, &path,
+                                       NULL, NULL, NULL);
+        if (!path)
+                return FALSE;
+        
+        selection = gtk_tree_view_get_selection (view);
+        if (!gtk_tree_selection_path_is_selected (selection, path)) {
+                gtk_tree_path_free (path);
+                return FALSE;
+        }
+
+        model = gtk_tree_view_get_model (view);
+        gtk_tree_model_get_iter (model, &iter, path);
+        gtk_tree_path_free (path);
+
+        ev_sidebar_annotations_activate_result_at_iter (sidebar_annots, model, &iter);
+
+        /* Always return FALSE so the tree view gets the event and can update
+         * the selection etc.
+         */
+        return FALSE;
 }
 
 static void
@@ -274,6 +314,10 @@ job_finished_callback (EvJobAnnots          *job,
                                          G_CALLBACK (selection_changed_cb),
                                          sidebar_annots);
        }
+    g_signal_connect (priv->tree_view, "button-press-event",
+                      G_CALLBACK (sidebar_tree_button_press_cb),
+                      sidebar_annots);
+
 
        model = gtk_tree_store_new (N_COLUMNS,
                                    G_TYPE_STRING,


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