[evince] history: Move some responsibilities out of EvHistory.



commit 38a52df3e256c157ef956b315b455d468faf0671
Author: Casey Jao <casey jao gmail com>
Date:   Mon Jul 31 06:18:49 2017 -0700

    history: Move some responsibilities out of EvHistory.
    
    EvHistory no longer listens to "page-changed" events. Instead links
    are mostly added by EvWindow.  When adding links to history we take
    care to also add the old page if necessary.
    
    libview/ev-view.c:
    libview/ev-view-private.h:
      * Modified "handle-link" signal to also supply the old page.
    
    shell/ev-history.h:
    shell/ev-history.c:
      * Deleted callback for "page-changed" signals.
      * Made ev_history_add_link_for_page public.
    
    shell/ev-window.c:
      * view_handle_link_cb now adds the old page to the history.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785627
    Partially fixes #810 (1/5)

 libview/ev-view-private.h |  1 +
 libview/ev-view.c         | 12 ++++++------
 shell/ev-history.c        | 31 ++++---------------------------
 shell/ev-history.h        |  2 ++
 shell/ev-window.c         |  6 ++++--
 5 files changed, 17 insertions(+), 35 deletions(-)
---
diff --git a/libview/ev-view-private.h b/libview/ev-view-private.h
index 02562ddd..d090c758 100644
--- a/libview/ev-view-private.h
+++ b/libview/ev-view-private.h
@@ -270,6 +270,7 @@ struct _EvViewClass {
                                       GtkScrollType   scroll,
                                       GtkOrientation  orientation);
         void     (*handle_link)       (EvView         *view,
+                                      gint            old_page,
                                       EvLink         *link);
         void     (*external_link)     (EvView         *view,
                                       EvLinkAction   *action);
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 046cd6c5..6b5150f0 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -2017,8 +2017,8 @@ ev_view_handle_link (EvView *view, EvLink *link)
        switch (type) {
                case EV_LINK_ACTION_TYPE_GOTO_DEST: {
                        EvLinkDest *dest;
-                       
-                       g_signal_emit (view, signals[SIGNAL_HANDLE_LINK], 0, link);
+                       gint old_page = ev_document_model_get_page (view->model);
+                       g_signal_emit (view, signals[SIGNAL_HANDLE_LINK], 0, old_page, link);
                
                        dest = ev_link_action_get_dest (action);
                        ev_view_goto_dest (view, dest);
@@ -7951,9 +7951,9 @@ ev_view_class_init (EvViewClass *class)
                         G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                         G_STRUCT_OFFSET (EvViewClass, handle_link),
                         NULL, NULL,
-                        g_cclosure_marshal_VOID__OBJECT,
-                        G_TYPE_NONE, 1,
-                        G_TYPE_OBJECT);
+                        NULL,
+                        G_TYPE_NONE, 2,
+                        G_TYPE_INT, G_TYPE_OBJECT);
        signals[SIGNAL_EXTERNAL_LINK] = g_signal_new ("external-link",
                         G_TYPE_FROM_CLASS (object_class),
                         G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
@@ -7961,7 +7961,7 @@ ev_view_class_init (EvViewClass *class)
                         NULL, NULL,
                         g_cclosure_marshal_VOID__OBJECT,
                         G_TYPE_NONE, 1,
-                        G_TYPE_OBJECT);
+                        G_TYPE_OBJECT);
        signals[SIGNAL_POPUP_MENU] = g_signal_new ("popup",
                         G_TYPE_FROM_CLASS (object_class),
                         G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
diff --git a/shell/ev-history.c b/shell/ev-history.c
index e3e03df8..7e254fb2 100644
--- a/shell/ev-history.c
+++ b/shell/ev-history.c
@@ -41,7 +41,6 @@ typedef struct {
         GList           *current;
 
         EvDocumentModel *model;
-        gulong           page_changed_handler_id;
 
         guint            frozen;
 } EvHistoryPrivate;
@@ -184,9 +183,7 @@ ev_history_activate_current_link (EvHistory *history)
         g_assert (priv->current);
 
         ev_history_freeze (history);
-        g_signal_handler_block (priv->model, priv->page_changed_handler_id);
         g_signal_emit (history, signals[ACTIVATE_LINK], 0, priv->current->data);
-        g_signal_handler_unblock (priv->model, priv->page_changed_handler_id);
         ev_history_thaw (history);
 
         g_signal_emit (history, signals[CHANGED], 0);
@@ -418,9 +415,9 @@ ev_history_get_current_page (EvHistory *history)
         return -1;
 }
 
-static void
-ev_history_add_link_for_page (EvHistory *history,
-                              gint       page)
+void
+ev_history_add_page (EvHistory *history,
+                     gint       page)
 {
         EvHistoryPrivate *priv = GET_PRIVATE (history);
         EvDocument   *document;
@@ -459,23 +456,13 @@ ev_history_add_link_for_page (EvHistory *history,
         g_object_unref (link);
 }
 
-static void
-page_changed_cb (EvDocumentModel *model,
-                 gint             old_page,
-                 gint             new_page,
-                 EvHistory       *history)
-{
-        if (ABS (new_page - old_page) > 1)
-                ev_history_add_link_for_page (history, new_page);
-}
-
 static void
 document_changed_cb (EvDocumentModel *model,
                      GParamSpec      *pspec,
                      EvHistory       *history)
 {
         ev_history_clear (history);
-        ev_history_add_link_for_page (history, ev_document_model_get_page (model));
+        ev_history_add_page (history, ev_document_model_get_page (model));
 }
 
 static void
@@ -490,12 +477,6 @@ ev_history_set_model (EvHistory       *history,
         if (priv->model) {
                 g_object_remove_weak_pointer (G_OBJECT (priv->model),
                                               (gpointer)&priv->model);
-
-                if (priv->page_changed_handler_id) {
-                        g_signal_handler_disconnect (priv->model,
-                                                     priv->page_changed_handler_id);
-                        priv->page_changed_handler_id = 0;
-                }
         }
 
         priv->model = model;
@@ -508,10 +489,6 @@ ev_history_set_model (EvHistory       *history,
         g_signal_connect (priv->model, "notify::document",
                           G_CALLBACK (document_changed_cb),
                           history);
-        priv->page_changed_handler_id =
-                g_signal_connect (priv->model, "page-changed",
-                                  G_CALLBACK (page_changed_cb),
-                                  history);
 }
 
 EvHistory *
diff --git a/shell/ev-history.h b/shell/ev-history.h
index 62bbb892..af633b94 100644
--- a/shell/ev-history.h
+++ b/shell/ev-history.h
@@ -54,6 +54,8 @@ GType           ev_history_get_type         (void);
 EvHistory      *ev_history_new              (EvDocumentModel *model);
 void            ev_history_add_link         (EvHistory       *history,
                                              EvLink          *link);
+void            ev_history_add_page         (EvHistory       *history,
+                                             gint            page);
 gboolean        ev_history_can_go_back      (EvHistory       *history);
 void            ev_history_go_back          (EvHistory       *history);
 gboolean        ev_history_can_go_forward   (EvHistory       *history);
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 3a7d05b8..30618179 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -361,7 +361,8 @@ static void ev_window_popup_cmd_open_attachment     (GSimpleAction    *action,
 static void    ev_window_popup_cmd_save_attachment_as  (GSimpleAction    *action,
                                                         GVariant         *parameter,
                                                         gpointer          user_data);
-static void    view_handle_link_cb                     (EvView           *view, 
+static void    view_handle_link_cb                     (EvView           *view,
+                                                        gint              old_page,
                                                         EvLink           *link, 
                                                         EvWindow         *window);
 static void     activate_link_cb                        (GObject          *object,
@@ -919,7 +920,7 @@ ev_window_find_title_for_link (EvWindow *window,
 }
 
 static void
-view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window)
+view_handle_link_cb (EvView *view, gint old_page, EvLink *link, EvWindow *window)
 {
        EvWindowPrivate *priv = GET_PRIVATE (window);
        EvLink *new_link = NULL;
@@ -949,6 +950,7 @@ view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window)
                        g_free (title);
                }
        }
+       ev_history_add_page (priv->history, old_page);
        ev_history_add_link (priv->history, new_link ? new_link : link);
        if (new_link)
                g_object_unref (new_link);


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