From: Nickolay V. Shmyrev Date: Sun, 28 Jan 2007 13:29:10 +0000 (+0000) Subject: History finally works as expected. X-Git-Tag: EVINCE_0_7_2~62 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=72fc0a73ea845307d6a109678952a0d07f6a1af4;p=evince.git History finally works as expected. 2007-01-28 Nickolay V. Shmyrev * shell/ev-navigation-action.c: (activate_menu_item_cb), (ev_navigation_action_class_init): * shell/ev-navigation-action.h: * shell/ev-page-action.c: (activate_cb): * shell/ev-page-cache.c: (ev_page_cache_class_init), (ev_page_cache_set_current_page_history): * shell/ev-page-cache.h: * shell/ev-sidebar-thumbnails.c: (ev_sidebar_tree_selection_changed), (ev_sidebar_icon_selection_changed), (page_changed_cb): * shell/ev-view-private.h: * shell/ev-view.c: (ev_view_handle_link), (ev_view_class_init): * shell/ev-view.h: * shell/ev-window.c: (page_changed_cb), (history_changed_cb), (ev_window_setup_document), (ev_window_load_job_cb): * shell/ev-window.h: History finally works as expected. svn path=/trunk/; revision=2259 --- diff --git a/ChangeLog b/ChangeLog index 8367a5e3..867c2fd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2007-01-28 Nickolay V. Shmyrev + + * shell/ev-navigation-action.c: (activate_menu_item_cb), + (ev_navigation_action_class_init): + * shell/ev-navigation-action.h: + * shell/ev-page-action.c: (activate_cb): + * shell/ev-page-cache.c: (ev_page_cache_class_init), + (ev_page_cache_set_current_page_history): + * shell/ev-page-cache.h: + * shell/ev-sidebar-thumbnails.c: + (ev_sidebar_tree_selection_changed), + (ev_sidebar_icon_selection_changed), (page_changed_cb): + * shell/ev-view-private.h: + * shell/ev-view.c: (ev_view_handle_link), (ev_view_class_init): + * shell/ev-view.h: + * shell/ev-window.c: (page_changed_cb), (history_changed_cb), + (ev_window_setup_document), (ev_window_load_job_cb): + * shell/ev-window.h: + + History finally works as expected. + 2007-01-28 Carlos Garcia Campos * shell/ev-sidebar-links.c: (ev_sidebar_links_map): diff --git a/shell/ev-navigation-action.c b/shell/ev-navigation-action.c index 490b5f92..88fe67b6 100644 --- a/shell/ev-navigation-action.c +++ b/shell/ev-navigation-action.c @@ -22,7 +22,6 @@ #include "ev-navigation-action.h" #include "ev-navigation-action-widget.h" -#include "ev-window.h" #include #include @@ -33,9 +32,16 @@ #include #include +enum +{ + WIDGET_ACTIVATE_LINK, + WIDGET_N_SIGNALS +}; + +static guint widget_signals[WIDGET_N_SIGNALS] = {0, }; + struct _EvNavigationActionPrivate { - EvWindow *window; EvHistory *history; }; @@ -58,13 +64,6 @@ ev_navigation_action_set_history (EvNavigationAction *action, (gpointer *) &action->priv->history); } -void -ev_navigation_action_set_window (EvNavigationAction *action, - EvWindow *window) -{ - action->priv->window = window; -} - static void activate_menu_item_cb (GtkWidget *widget, EvNavigationAction *action) { @@ -75,16 +74,12 @@ activate_menu_item_cb (GtkWidget *widget, EvNavigationAction *action) index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "index")); ev_history_set_current_index (action->priv->history, index); - if (action->priv->window) { + if (action->priv->history) { EvLink *link; - EvLinkAction *link_action; - EvLinkDest *dest; link = ev_history_get_link_nth (action->priv->history, index); - link_action = ev_link_get_action (link); - dest = ev_link_action_get_dest (link_action); - ev_window_goto_dest (action->priv->window, dest); + g_signal_emit (action, widget_signals[WIDGET_ACTIVATE_LINK], 0, link); } } @@ -223,5 +218,14 @@ ev_navigation_action_class_init (EvNavigationActionClass *class) action_class->create_tool_item = create_tool_item; action_class->connect_proxy = connect_proxy; + widget_signals[WIDGET_ACTIVATE_LINK] = g_signal_new ("activate_link", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EvNavigationActionClass, activate_link), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + G_TYPE_OBJECT); + g_type_class_add_private (object_class, sizeof (EvNavigationActionPrivate)); } diff --git a/shell/ev-navigation-action.h b/shell/ev-navigation-action.h index c801c392..2ac58487 100644 --- a/shell/ev-navigation-action.h +++ b/shell/ev-navigation-action.h @@ -24,7 +24,7 @@ #include #include "ev-history.h" -#include "ev-window.h" +#include "ev-link.h" G_BEGIN_DECLS @@ -50,13 +50,14 @@ struct _EvNavigationAction struct _EvNavigationActionClass { GtkActionClass parent_class; + + void (* activate_link) (EvNavigationAction *action, + EvLink *link); }; GType ev_navigation_action_get_type (void); void ev_navigation_action_set_history (EvNavigationAction *action, EvHistory *history); -void ev_navigation_action_set_window (EvNavigationAction *action, - EvWindow *window); G_END_DECLS diff --git a/shell/ev-page-action.c b/shell/ev-page-action.c index 744729d7..0571b6d1 100644 --- a/shell/ev-page-action.c +++ b/shell/ev-page-action.c @@ -118,6 +118,7 @@ activate_cb (GtkWidget *entry, GtkAction *action) EvLinkDest *link_dest; EvLinkAction *link_action; EvLink *link; + gchar *link_text; text = gtk_entry_get_text (GTK_ENTRY (entry)); page_cache = page->priv->page_cache; @@ -125,11 +126,13 @@ activate_cb (GtkWidget *entry, GtkAction *action) link_dest = ev_link_dest_new_page_label (text); link_action = ev_link_action_new_dest (link_dest); - link = ev_link_new (text, link_action); + link_text = g_strdup_printf ("Page: %s", text); + link = ev_link_new (link_text, link_action); g_signal_emit (action, signals[ACTIVATE_LINK], 0, link); g_object_unref (link); + g_free (link_text); /* rest the entry to the current page if we were unable to * change it */ diff --git a/shell/ev-page-cache.c b/shell/ev-page-cache.c index c1af7d22..a6d7bd9e 100644 --- a/shell/ev-page-cache.c +++ b/shell/ev-page-cache.c @@ -45,11 +45,13 @@ struct _EvPageCacheClass GObjectClass parent_class; void (* page_changed) (EvPageCache *page_cache, gint page); + void (* history_changed) (EvPageCache *page_cache, gint page); }; enum { PAGE_CHANGED, + HISTORY_CHANGED, N_SIGNALS, }; @@ -87,6 +89,16 @@ ev_page_cache_class_init (EvPageCacheClass *class) G_TYPE_NONE, 1, G_TYPE_INT); + signals [HISTORY_CHANGED] = + g_signal_new ("history-changed", + EV_TYPE_PAGE_CACHE, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EvPageCacheClass, history_changed), + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, + G_TYPE_INT); + } static void @@ -324,6 +336,16 @@ ev_page_cache_set_current_page (EvPageCache *page_cache, g_signal_emit (page_cache, signals[PAGE_CHANGED], 0, page); } +void +ev_page_cache_set_current_page_history (EvPageCache *page_cache, + int page) +{ + if (page != page_cache->current_page) + g_signal_emit (page_cache, signals [HISTORY_CHANGED], 0, page); + + ev_page_cache_set_current_page (page_cache, page); +} + gboolean ev_page_cache_set_page_label (EvPageCache *page_cache, const char *page_label) diff --git a/shell/ev-page-cache.h b/shell/ev-page-cache.h index 0ad20e84..d0ee0021 100644 --- a/shell/ev-page-cache.h +++ b/shell/ev-page-cache.h @@ -66,6 +66,8 @@ gboolean ev_page_cache_get_dual_even_left (EvPageCache *page_cache); gint ev_page_cache_get_current_page (EvPageCache *page_cache); void ev_page_cache_set_current_page (EvPageCache *page_cache, int page); +void ev_page_cache_set_current_page_history (EvPageCache *page_cache, + int page); gboolean ev_page_cache_set_page_label (EvPageCache *page_cache, const char *page_label); diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c index eac7073f..aa83dee4 100644 --- a/shell/ev-sidebar-thumbnails.c +++ b/shell/ev-sidebar-thumbnails.c @@ -433,7 +433,7 @@ ev_sidebar_tree_selection_changed (GtkTreeSelection *selection, page = gtk_tree_path_get_indices (path)[0]; gtk_tree_path_free (path); - ev_page_cache_set_current_page (priv->page_cache, page); + ev_page_cache_set_current_page_history (priv->page_cache, page); } static void @@ -458,7 +458,7 @@ ev_sidebar_icon_selection_changed (GtkIconView *icon_view, gtk_tree_path_free (path); g_list_free (selected); - ev_page_cache_set_current_page (priv->page_cache, page); + ev_page_cache_set_current_page_history (priv->page_cache, page); } static void @@ -563,7 +563,17 @@ page_changed_cb (EvPageCache *page_cache, gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE); gtk_tree_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0); } else if (sidebar->priv->icon_view) { + + g_signal_handlers_block_by_func + (sidebar->priv->icon_view, + G_CALLBACK (ev_sidebar_icon_selection_changed), sidebar); + gtk_icon_view_select_path (GTK_ICON_VIEW (sidebar->priv->icon_view), path); + + g_signal_handlers_unblock_by_func + (sidebar->priv->icon_view, + G_CALLBACK (ev_sidebar_icon_selection_changed), sidebar); + gtk_icon_view_set_cursor (GTK_ICON_VIEW (sidebar->priv->icon_view), path, NULL, FALSE); } diff --git a/shell/ev-view-private.h b/shell/ev-view-private.h index cdc6a96c..cab09417 100644 --- a/shell/ev-view-private.h +++ b/shell/ev-view-private.h @@ -161,6 +161,8 @@ struct _EvViewClass { EvScrollType scroll, gboolean horizontal); void (*zoom_invalid) (EvView *view); + void (*handle_link) (EvView *view, + EvLink *link); void (*external_link) (EvView *view, EvLinkAction *action); void (*popup_menu) (EvView *view, diff --git a/shell/ev-view.c b/shell/ev-view.c index fec6435a..37ab5366 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -66,6 +66,7 @@ enum { enum { SIGNAL_BINDING_ACTIVATED, SIGNAL_ZOOM_INVALID, + SIGNAL_HANDLE_LINK, SIGNAL_EXTERNAL_LINK, SIGNAL_POPUP_MENU, N_SIGNALS, @@ -1312,7 +1313,7 @@ goto_dest (EvView *view, EvLinkDest *dest) view->current_page); } -void +static void ev_view_goto_dest (EvView *view, EvLinkDest *dest) { EvLinkDestType type; @@ -1364,6 +1365,7 @@ ev_view_handle_link (EvView *view, EvLink *link) g_signal_emit (view, signals[SIGNAL_EXTERNAL_LINK], 0, action); break; } + g_signal_emit (view, signals[SIGNAL_HANDLE_LINK], 0, link); } static gchar * @@ -3191,6 +3193,14 @@ ev_view_class_init (EvViewClass *class) NULL, NULL, ev_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE); + signals[SIGNAL_HANDLE_LINK] = g_signal_new ("handle-link", + G_TYPE_FROM_CLASS (object_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); signals[SIGNAL_EXTERNAL_LINK] = g_signal_new ("external-link", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, diff --git a/shell/ev-view.h b/shell/ev-view.h index ba736ca3..77a4ba37 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -141,8 +141,6 @@ void ev_view_scroll (EvView *view, gboolean horizontal); void ev_view_handle_link (EvView *view, EvLink *link); -void ev_view_goto_dest (EvView *view, - EvLinkDest *dest); gboolean ev_view_next_page (EvView *view); gboolean ev_view_previous_page (EvView *view); diff --git a/shell/ev-window.c b/shell/ev-window.c index f14bd31e..51b8abde 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -263,6 +263,9 @@ static gboolean fullscreen_motion_notify_cb (GtkWidget *widget, static gboolean fullscreen_leave_notify_cb (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data); +static void view_handle_link_cb (EvView *view, + EvLink *link, + EvWindow *window); G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW) @@ -635,19 +638,20 @@ page_changed_cb (EvPageCache *page_cache, gint page, EvWindow *ev_window) { - gchar *label; - ev_window_update_actions (ev_window); - if (ev_window->priv->history) { - label = ev_page_cache_get_page_label (ev_window->priv->page_cache, page); - ev_history_add_page (ev_window->priv->history, page, label); - g_free (label); - } - if (!ev_window_is_empty (ev_window)) ev_metadata_manager_set_int (ev_window->priv->uri, "page", page); } +static void +history_changed_cb (EvPageCache *page_cache, + gint page, + EvWindow *ev_window) +{ + ev_history_add_page (ev_window->priv->history, page, + ev_page_cache_get_page_label (ev_window->priv->page_cache, page)); + return; +} static void update_document_mode (EvWindow *window, EvDocumentMode mode) @@ -903,6 +907,7 @@ ev_window_setup_document (EvWindow *ev_window) document = ev_window->priv->document; ev_window->priv->page_cache = ev_page_cache_get (ev_window->priv->document); g_signal_connect (ev_window->priv->page_cache, "page-changed", G_CALLBACK (page_changed_cb), ev_window); + g_signal_connect (ev_window->priv->page_cache, "history-changed", G_CALLBACK (history_changed_cb), ev_window); if (EV_IS_DOCUMENT_FIND (document)) { g_signal_connect_object (G_OBJECT (document), @@ -930,7 +935,6 @@ ev_window_setup_document (EvWindow *ev_window) ev_window->priv->history = ev_history_new (); action = gtk_action_group_get_action (ev_window->priv->action_group, NAVIGATION_ACTION); ev_navigation_action_set_history (EV_NAVIGATION_ACTION (action), ev_window->priv->history); - ev_navigation_action_set_window (EV_NAVIGATION_ACTION (action), ev_window); if (ev_window->priv->properties) { ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties), @@ -1099,8 +1103,15 @@ ev_window_load_job_cb (EvJobLoad *job, ev_window_setup_document (ev_window); - if (job->dest) - ev_window_goto_dest (ev_window, job->dest); + if (job->dest) { + EvLink *link; + EvLinkAction *link_action; + + link_action = ev_link_action_new_dest (g_object_ref (job->dest)); + link = ev_link_new (NULL, link_action); + ev_view_handle_link (EV_VIEW (ev_window->priv->view), link); + g_object_unref (link); + } switch (job->mode) { case EV_WINDOW_MODE_FULLSCREEN: @@ -1269,12 +1280,6 @@ ev_window_open_uri (EvWindow *ev_window, ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH); } -void -ev_window_goto_dest (EvWindow *ev_window, EvLinkDest *dest) -{ - ev_view_goto_dest (EV_VIEW (ev_window->priv->view), dest); -} - static void file_open_dialog_response_cb (GtkWidget *chooser, gint response_id, @@ -4023,6 +4028,12 @@ static const GtkActionEntry attachment_popup_entries [] = { NULL, G_CALLBACK (ev_attachment_popup_cmd_save_attachment_as) }, }; +static void +sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window) +{ + ev_view_handle_link (EV_VIEW (window->priv->view), link); +} + static void activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window) { @@ -4030,6 +4041,18 @@ activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window) gtk_widget_grab_focus (window->priv->view); } +static void +navigation_action_activate_link_cb (EvNavigationAction *action, EvLink *link, EvWindow *window) +{ + + g_signal_handlers_block_by_func + (window->priv->view, G_CALLBACK (view_handle_link_cb), window); + ev_view_handle_link (EV_VIEW (window->priv->view), link); + g_signal_handlers_unblock_by_func + (window->priv->view, G_CALLBACK (view_handle_link_cb), window); + gtk_widget_grab_focus (window->priv->view); +} + static void register_custom_actions (EvWindow *window, GtkActionGroup *group) { @@ -4066,6 +4089,8 @@ register_custom_actions (EvWindow *window, GtkActionGroup *group) "stock_id", GTK_STOCK_GO_DOWN, "tooltip", _("Move across visited pages"), NULL); + g_signal_connect (action, "activate_link", + G_CALLBACK (navigation_action_activate_link_cb), window); gtk_action_group_add_action (group, action); g_object_unref (action); } @@ -4223,12 +4248,6 @@ window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer return FALSE; } -static void -sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window) -{ - ev_view_handle_link (EV_VIEW (window->priv->view), link); -} - static void launch_action (EvWindow *window, EvLinkAction *action) { @@ -4318,6 +4337,12 @@ do_action_named (EvWindow *window, EvLinkAction *action) } } +static void +view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window) +{ + ev_history_add_link (window->priv->history, link); +} + static void view_external_link_cb (EvView *view, EvLinkAction *action, EvWindow *window) { @@ -4768,6 +4793,10 @@ ev_window_init (EvWindow *ev_window) g_signal_connect_object (ev_window->priv->view, "external-link", G_CALLBACK (view_external_link_cb), ev_window, 0); + g_signal_connect_object (ev_window->priv->view, "handle-link", + G_CALLBACK (view_handle_link_cb), + ev_window, 0); + g_signal_connect_object (ev_window->priv->view, "popup", G_CALLBACK (view_menu_popup_cb), diff --git a/shell/ev-window.h b/shell/ev-window.h index 667f1370..a60b123d 100644 --- a/shell/ev-window.h +++ b/shell/ev-window.h @@ -78,8 +78,6 @@ void ev_window_open_uri (EvWindow *ev_window, EvLinkDest *dest, EvWindowRunMode mode, gboolean unlink_temp_file); -void ev_window_goto_dest (EvWindow *ev_window, - EvLinkDest *dest); gboolean ev_window_is_empty (const EvWindow *ev_window); #ifdef WITH_PRINT void ev_window_print_range (EvWindow *ev_window,