X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=shell%2Fev-window.c;h=d46d98d98de386107eea5d865576a730a0e887b6;hb=d3ea391eeabb901a8dfe269edc5980f0f800aa65;hp=a1e86548c70aeeeef44e892d8650d98f72e38edf;hpb=81ab197b294eaaba8b6b99bf2c259c5adb1e2251;p=evince.git diff --git a/shell/ev-window.c b/shell/ev-window.c index a1e86548..d46d98d9 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -29,12 +29,16 @@ #endif #include "ev-window.h" +#include "ev-navigation-action.h" +#include "ev-page-action.h" #include "ev-sidebar.h" -#include "ev-sidebar-bookmarks.h" +#include "ev-sidebar-links.h" #include "ev-sidebar-thumbnails.h" #include "ev-view.h" +#include "ev-password.h" #include "ev-print-job.h" #include "ev-document-find.h" +#include "ev-document-security.h" #include "eggfindbar.h" #include "pdf-document.h" @@ -43,6 +47,7 @@ #include #include + #include #include @@ -65,12 +70,14 @@ struct _EvWindowPrivate { GtkWidget *main_box; GtkWidget *hpaned; GtkWidget *sidebar; + GtkWidget *thumbs_sidebar; GtkWidget *find_bar; GtkWidget *view; GtkActionGroup *action_group; GtkUIManager *ui_manager; GtkWidget *statusbar; guint help_message_cid; + guint view_message_cid; GtkWidget *exit_fullscreen_popup; char *uri; @@ -79,6 +86,10 @@ struct _EvWindowPrivate { gboolean fullscreen_mode; }; +#define NAVIGATION_BACK_ACTION "NavigationBack" +#define NAVIGATION_FORWARD_ACTION "NavigationForward" +#define PAGE_SELECTOR_ACTION "PageSelector" + #if 0 /* enable these to add support for signals */ static guint ev_window_signals [N_SIGNALS] = { 0 }; @@ -98,7 +109,7 @@ const char * ev_window_get_attribute (EvWindow *self) { g_return_val_if_fail (self != NULL && EV_IS_WINDOW (self), NULL); - + return self->priv->attribute; } @@ -142,9 +153,9 @@ ev_window_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *param_spec) { EvWindow *self; - + self = EV_WINDOW (object); - + switch (prop_id) { case PROP_ATTRIBUTE: ev_window_set_attribute (self, g_value_get_string (value)); @@ -171,27 +182,91 @@ set_action_sensitive (EvWindow *ev_window, static void update_action_sensitivity (EvWindow *ev_window) { - int n_pages; - int page; + EvDocument *document; + EvView *view; + + gboolean can_go_back = FALSE; + gboolean can_go_forward = FALSE; + + document = ev_window->priv->document; + + view = EV_VIEW (ev_window->priv->view); + + if (document) { + can_go_back = ev_view_can_go_back (view); + can_go_forward = ev_view_can_go_forward (view); + } - if (ev_window->priv->document) - n_pages = ev_document_get_n_pages (ev_window->priv->document); + /* File menu */ + /* "FileOpen": always sensitive */ + set_action_sensitive (ev_window, "FileSaveAs", document!=NULL); + set_action_sensitive (ev_window, "FilePrint", document!=NULL); + /* "FileCloseWindow": always sensitive */ + + /* Edit menu */ + set_action_sensitive (ev_window, "EditCopy", document!=NULL); + set_action_sensitive (ev_window, "EditSelectAll", document!=NULL); + + if (document) + set_action_sensitive (ev_window, "EditFind", EV_IS_DOCUMENT_FIND (document)); else - n_pages = 1; + set_action_sensitive (ev_window, "EditFind", FALSE); - page = ev_view_get_page (EV_VIEW (ev_window->priv->view)); + /* View menu */ + set_action_sensitive (ev_window, "ViewZoomIn", document!=NULL); + set_action_sensitive (ev_window, "ViewZoomOut", document!=NULL); + set_action_sensitive (ev_window, "ViewNormalSize", document!=NULL); + set_action_sensitive (ev_window, "ViewBestFit", document!=NULL); + set_action_sensitive (ev_window, "ViewPageWidth", document!=NULL); - set_action_sensitive (ev_window, "GoFirstPage", page > 1); - set_action_sensitive (ev_window, "GoPreviousPage", page > 1); - set_action_sensitive (ev_window, "GoNextPage", page < n_pages); - set_action_sensitive (ev_window, "GoLastPage", page < n_pages); + /* Go menu */ + set_action_sensitive (ev_window, "GoBack", can_go_back); + set_action_sensitive (ev_window, "GoForward", can_go_forward); + if (document) { + int n_pages; + int page; + + page = ev_view_get_page (EV_VIEW (ev_window->priv->view)); + n_pages = ev_document_get_n_pages (document); + + set_action_sensitive (ev_window, "GoPageDown", page > 1); + set_action_sensitive (ev_window, "GoPageUp", page < n_pages); + set_action_sensitive (ev_window, "GoFirstPage", page > 1); + set_action_sensitive (ev_window, "GoLastPage", page < n_pages); + } else { + set_action_sensitive (ev_window, "GoFirstPage", FALSE); + set_action_sensitive (ev_window, "GoPageDown", FALSE); + set_action_sensitive (ev_window, "GoPageUp", FALSE); + set_action_sensitive (ev_window, "GoLastPage", FALSE); + } + + /* Help menu */ + /* "HelpContents": always sensitive */ + /* "HelpAbout": always sensitive */ + + /* Toolbar-specific actions: */ + set_action_sensitive (ev_window, NAVIGATION_BACK_ACTION, can_go_back); + set_action_sensitive (ev_window, NAVIGATION_FORWARD_ACTION, can_go_forward); + set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, document!=NULL); +} + +void +ev_window_open_page (EvWindow *ev_window, int page) +{ + ev_view_set_page (EV_VIEW (ev_window->priv->view), page); +} + +void +ev_window_open_link (EvWindow *ev_window, EvLink *link) +{ + ev_view_go_to_link (EV_VIEW (ev_window->priv->view), link); } gboolean ev_window_is_empty (const EvWindow *ev_window) { g_return_val_if_fail (EV_IS_WINDOW (ev_window), FALSE); - + return ev_window->priv->document == NULL; } @@ -218,33 +293,33 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) { GSList *formats, *list; gboolean retval = FALSE; - + formats = gdk_pixbuf_get_formats (); - + list = formats; while (list) { GdkPixbufFormat *format = list->data; int i; gchar **mime_types; - + if (gdk_pixbuf_format_is_disabled (format)) continue; mime_types = gdk_pixbuf_format_get_mime_types (format); - + for (i = 0; mime_types[i] != NULL; i++) { if (strcmp (mime_types[i], mime_type) == 0) { retval = TRUE; break; } } - + if (retval) break; - + list = list->next; } - + g_slist_free (formats); return retval; @@ -260,7 +335,7 @@ update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_windo } else { title = ev_document_get_title (document); - if (title == NULL) { + if (title == NULL || (title && strlen (title) == 0)) { title = g_path_get_basename (ev_window->priv->uri); } } @@ -270,12 +345,70 @@ update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_windo g_free (title); } +static void +update_total_pages (EvWindow *ev_window) +{ + GtkAction *action; + int pages; + + pages = ev_document_get_n_pages (ev_window->priv->document); + action = gtk_action_group_get_action + (ev_window->priv->action_group, PAGE_SELECTOR_ACTION); + ev_page_action_set_total_pages (EV_PAGE_ACTION (action), pages); +} + +/* This function assumes that ev_window just had ev_window->document set. + */ +static void +ev_window_setup_document (EvWindow *ev_window) +{ + EvDocument *document; + EvHistory *history; + EvView *view = EV_VIEW (ev_window->priv->view); + EvSidebar *sidebar = EV_SIDEBAR (ev_window->priv->sidebar); + GtkAction *action; + + document = ev_window->priv->document; + + ev_sidebar_set_document (sidebar, document); + ev_view_set_document (view, document); + + history = ev_history_new (); + ev_view_set_history (view, history); + g_object_unref (history); + + action = gtk_action_group_get_action + (ev_window->priv->action_group, NAVIGATION_BACK_ACTION); + ev_navigation_action_set_history + (EV_NAVIGATION_ACTION (action), history); + + action = gtk_action_group_get_action + (ev_window->priv->action_group, NAVIGATION_FORWARD_ACTION); + ev_navigation_action_set_history + (EV_NAVIGATION_ACTION (action), history); + + update_total_pages (ev_window); + update_action_sensitivity (ev_window); +} + + +static gchar * +ev_window_get_password (GtkWidget *password_dialog) +{ + gchar *password = NULL; + + if (gtk_dialog_run (GTK_DIALOG (password_dialog)) == GTK_RESPONSE_OK) + password = ev_password_dialog_get_password (password_dialog); + + return password; +} + void ev_window_open (EvWindow *ev_window, const char *uri) { EvDocument *document = NULL; char *mime_type; - + g_free (ev_window->priv->uri); ev_window->priv->uri = g_strdup (uri); @@ -289,32 +422,62 @@ ev_window_open (EvWindow *ev_window, const char *uri) document = g_object_new (PS_TYPE_DOCUMENT, NULL); else if (mime_type_supported_by_gdk_pixbuf (mime_type)) document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL); - + if (document) { GError *error = NULL; + GtkWidget *password_dialog = NULL; g_signal_connect_object (G_OBJECT (document), "notify::title", G_CALLBACK (update_window_title), ev_window, 0); - if (ev_document_load (document, uri, &error)) { - if (ev_window->priv->document) - g_object_unref (ev_window->priv->document); - ev_window->priv->document = document; + /* If we get an error while loading the document, we try to fix + * it and try again. This is an ugly loop that could do with + * some refactoring.*/ + while (TRUE) { + gboolean result; - ev_view_set_document (EV_VIEW (ev_window->priv->view), - document); - ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar), - document); + result = ev_document_load (document, uri, &error); + + if (result) { + if (ev_window->priv->document) + g_object_unref (ev_window->priv->document); + ev_window->priv->document = document; + ev_window_setup_document (ev_window); + + if (password_dialog) + gtk_widget_destroy (password_dialog); + break; + } - update_action_sensitivity (ev_window); - - } else { g_assert (error != NULL); + + if (error->domain == EV_DOCUMENT_ERROR && + error->code == EV_DOCUMENT_ERROR_ENCRYPTED) { + char *password; + + if (password_dialog == NULL) + password_dialog = ev_password_dialog_new (GTK_WIDGET (ev_window), uri); + else + ev_password_dialog_set_bad_pass (password_dialog); + password = ev_window_get_password (password_dialog); + if (password) { + ev_document_security_set_password (EV_DOCUMENT_SECURITY (document), + password); + g_free (password); + g_error_free (error); + error = NULL; + continue; + } else { + gtk_widget_destroy (password_dialog); + } + } else { + unable_to_load (ev_window, error->message); + } g_object_unref (document); - unable_to_load (ev_window, error->message); g_error_free (error); + break; } } else { char *error_message; @@ -334,6 +497,119 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window) ev_application_open (EV_APP, NULL); } +/* FIXME +static gboolean +overwrite_existing_file (GtkWindow *window, const gchar *file_name) +{ + GtkWidget *msgbox; + gchar *utf8_file_name; + AtkObject *obj; + gint ret; + + utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL); + msgbox = gtk_message_dialog_new ( + window, + (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + _("A file named \"%s\" already exists."), + utf8_file_name); + g_free (utf8_file_name); + + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (msgbox), + _("Do you want to replace it with the one you are saving?")); + + gtk_dialog_add_button (GTK_DIALOG (msgbox), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + + gtk_dialog_add_button (GTK_DIALOG (msgbox), + _("_Replace"), GTK_RESPONSE_YES); + + gtk_dialog_set_default_response (GTK_DIALOG (msgbox), + GTK_RESPONSE_CANCEL); + + obj = gtk_widget_get_accessible (msgbox); + + if (GTK_IS_ACCESSIBLE (obj)) + atk_object_set_name (obj, _("Question")); + + ret = gtk_dialog_run (GTK_DIALOG (msgbox)); + gtk_widget_destroy (msgbox); + + return (ret == GTK_RESPONSE_YES); +} +*/ + +static void +save_error_dialog (GtkWindow *window, const gchar *file_name) +{ + GtkWidget *error_dialog; + + error_dialog = gtk_message_dialog_new ( + window, + (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("The file could not be saved as \"%s\"."), + file_name); + + /* Easy way to make the text bold while keeping the string + * above free from pango markup (FIXME ?) */ + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (error_dialog), " "); + + gtk_dialog_run (GTK_DIALOG (error_dialog)); + gtk_widget_destroy (error_dialog); +} + +static void +ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window) +{ + GtkWidget *fc; + GtkFileFilter *pdf_filter, *all_filter; + gchar *uri = NULL; + + fc = gtk_file_chooser_dialog_new ( + _("Save a Copy"), + NULL, GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_OK, + NULL); + gtk_window_set_modal (GTK_WINDOW (fc), TRUE); + + pdf_filter = gtk_file_filter_new (); + gtk_file_filter_set_name (pdf_filter, _("PDF Documents")); + gtk_file_filter_add_mime_type (pdf_filter, "application/pdf"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), pdf_filter); + + all_filter = gtk_file_filter_new (); + gtk_file_filter_set_name (all_filter, _("All Files")); + gtk_file_filter_add_pattern (all_filter, "*"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), all_filter); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fc), pdf_filter); + + gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK); + + gtk_widget_show (fc); + + while (gtk_dialog_run (GTK_DIALOG (fc)) == GTK_RESPONSE_OK) { + uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc)); + +/* FIXME + if (g_file_test (uri, G_FILE_TEST_EXISTS) && + !overwrite_existing_file (GTK_WINDOW (fc), uri)) + continue; +*/ + + if (ev_document_save (ev_window->priv->document, uri, NULL)) + break; + else + save_error_dialog (GTK_WINDOW (fc), uri); + } + gtk_widget_destroy (fc); +} + static gboolean using_postscript_printer (GnomePrintConfig *config) { @@ -342,20 +618,20 @@ using_postscript_printer (GnomePrintConfig *config) driver = gnome_print_config_get ( config, (const guchar *)"Settings.Engine.Backend.Driver"); - + transport = gnome_print_config_get ( config, (const guchar *)"Settings.Transport.Backend"); - + if (driver) { if (!strcmp ((const gchar *)driver, "gnome-print-ps")) return TRUE; - else + else return FALSE; } else if (transport) { if (!strcmp ((const gchar *)transport, "CUPS")) return TRUE; } - + return FALSE; } @@ -379,11 +655,11 @@ ev_window_print (EvWindow *ev_window) gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog), GNOME_PRINT_DIALOG_RESPONSE_PREVIEW, FALSE); - + while (TRUE) { int response; response = gtk_dialog_run (GTK_DIALOG (print_dialog)); - + if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT) break; @@ -392,7 +668,7 @@ ev_window_print (EvWindow *ev_window) */ if (!using_postscript_printer (config)) { GtkWidget *dialog; - + dialog = gtk_message_dialog_new ( GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, @@ -415,11 +691,13 @@ ev_window_print (EvWindow *ev_window) NULL); break; } - + gtk_widget_destroy (print_dialog); - if (print_job != NULL) + if (print_job != NULL) { ev_print_job_print (print_job, GTK_WINDOW (ev_window)); + g_object_unref (print_job); + } } static void @@ -444,7 +722,7 @@ find_not_supported_dialog (EvWindow *ev_window) /* If you change this so it isn't modal, be sure you don't * allow multiple copies of the dialog... */ - + dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, @@ -456,6 +734,14 @@ find_not_supported_dialog (EvWindow *ev_window) gtk_widget_destroy (dialog); } +static void +ev_window_cmd_edit_select_all (GtkAction *action, EvWindow *ev_window) +{ + g_return_if_fail (EV_IS_WINDOW (ev_window)); + + ev_view_select_all (EV_VIEW (ev_window->priv->view)); +} + static void ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window) { @@ -468,9 +754,9 @@ ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window) } else { gtk_widget_show (ev_window->priv->find_bar); - if (ev_window->priv->exit_fullscreen_popup) + if (ev_window->priv->exit_fullscreen_popup) update_fullscreen_popup (ev_window); - + egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar)); } } @@ -480,7 +766,7 @@ ev_window_cmd_edit_copy (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - /* FIXME */ + ev_view_copy (EV_VIEW (ev_window->priv->view)); } static void @@ -494,7 +780,7 @@ update_fullscreen_popup (EvWindow *window) if (!popup) return; - + popup_width = popup->requisition.width; popup_height = popup->requisition.height; @@ -509,10 +795,10 @@ update_fullscreen_popup (EvWindow *window) GtkRequisition req; gtk_widget_size_request (window->priv->find_bar, &req); - + screen_rect.height -= req.height; } - + if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL) { gtk_window_move (GTK_WINDOW (popup), @@ -605,7 +891,7 @@ ev_window_fullscreen (EvWindow *window) main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu"); gtk_widget_hide (main_menu); gtk_widget_hide (window->priv->statusbar); - + update_fullscreen_popup (window); gtk_widget_show (popup); @@ -615,21 +901,21 @@ static void ev_window_unfullscreen (EvWindow *window) { GtkWidget *main_menu; - + window->priv->fullscreen_mode = FALSE; main_menu = gtk_ui_manager_get_widget (window->priv->ui_manager, "/MainMenu"); gtk_widget_show (main_menu); gtk_widget_show (window->priv->statusbar); - + destroy_exit_fullscreen_popup (window); } - + static void ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *ev_window) { gboolean fullscreen; - + g_return_if_fail (EV_IS_WINDOW (ev_window)); fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); @@ -679,7 +965,7 @@ static gboolean ev_window_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *ev_window) { gtk_window_unfullscreen (GTK_WINDOW (ev_window)); - + return FALSE; } @@ -729,7 +1015,7 @@ ev_window_cmd_go_back (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - /* FIXME */ + ev_view_go_back (EV_VIEW (ev_window->priv->view)); } static void @@ -737,11 +1023,11 @@ ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - /* FIXME */ + ev_view_go_forward (EV_VIEW (ev_window->priv->view)); } static void -ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window) +ev_window_cmd_go_page_up (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); @@ -750,7 +1036,7 @@ ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window) } static void -ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window) +ev_window_cmd_go_page_down (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); @@ -799,7 +1085,7 @@ ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window) N_("Evince is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" "the Free Software Foundation; either version 2 of the License, or\n" - "(at your option) any later version.\n"), + "(at your option) any later version.\n"), N_("Evince is distributed in the hope that it will be useful,\n" "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" @@ -881,7 +1167,7 @@ menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window) action = g_object_get_data (G_OBJECT (proxy), "gtk-action"); g_return_if_fail (action != NULL); - + g_object_get (G_OBJECT (action), "tooltip", &message, NULL); if (message) { gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar), @@ -922,25 +1208,59 @@ disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action, } } +static void +update_current_page (EvWindow *ev_window, + EvView *view) +{ + int page; + GtkAction *action; + EvSidebarThumbnails *thumbs; + + thumbs = EV_SIDEBAR_THUMBNAILS (ev_window->priv->thumbs_sidebar); + ev_sidebar_thumbnails_select_page (thumbs, ev_view_get_page (view)); + + action = gtk_action_group_get_action + (ev_window->priv->action_group, PAGE_SELECTOR_ACTION); + + page = ev_view_get_page (EV_VIEW (ev_window->priv->view)); + ev_page_action_set_current_page (EV_PAGE_ACTION (action), page); +} + static void view_page_changed_cb (EvView *view, EvWindow *ev_window) { + update_current_page (ev_window, view); update_action_sensitivity (ev_window); } static void -view_find_status_changed_cb (EvView *view, - EvWindow *ev_window) +view_status_changed_cb (EvView *view, + GParamSpec *pspec, + EvWindow *ev_window) { - char *text; + const char *message; - text = ev_view_get_find_status_message (view); + gtk_statusbar_pop (GTK_STATUSBAR (ev_window->priv->statusbar), + ev_window->priv->view_message_cid); + message = ev_view_get_status (view); + if (message) { + gtk_statusbar_push (GTK_STATUSBAR (ev_window->priv->statusbar), + ev_window->priv->view_message_cid, message); + } +} + +static void +view_find_status_changed_cb (EvView *view, + GParamSpec *pspec, + EvWindow *ev_window) +{ + const char *text; + + text = ev_view_get_find_status (view); egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar), text); - - g_free (text); } static void @@ -980,7 +1300,7 @@ find_bar_search_changed_cb (EggFindBar *find_bar, const char *search_string; g_return_if_fail (EV_IS_WINDOW (ev_window)); - + /* Either the string or case sensitivity could have changed, * we connect this callback to both. We also connect it * to ::visible so when the find bar is hidden, we should @@ -990,7 +1310,7 @@ find_bar_search_changed_cb (EggFindBar *find_bar, case_sensitive = egg_find_bar_get_case_sensitive (find_bar); visible = GTK_WIDGET_VISIBLE (find_bar); search_string = egg_find_bar_get_search_string (find_bar); - + #if 0 g_printerr ("search for '%s'\n", search_string ? search_string : "(nil)"); #endif @@ -1025,7 +1345,7 @@ ev_window_dispose (GObject *object) g_object_unref (priv->action_group); priv->action_group = NULL; } - + G_OBJECT_CLASS (parent_class)->dispose (object); } @@ -1086,7 +1406,10 @@ static GtkActionEntry entries[] = { { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "O", N_("Open a file"), G_CALLBACK (ev_window_cmd_file_open) }, - { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "P", + { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), NULL, + N_("Save the current document with a new filename"), + G_CALLBACK (ev_window_cmd_save_as) }, + { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "P", N_("Print this document"), G_CALLBACK (ev_window_cmd_file_print) }, { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "W", @@ -1097,7 +1420,9 @@ static GtkActionEntry entries[] = { { "EditCopy", GTK_STOCK_COPY, N_("_Copy"), "C", N_("Copy text from the document"), G_CALLBACK (ev_window_cmd_edit_copy) }, - + { "EditSelectAll", NULL, N_("Select _All"), "A", + N_("Select the entire page"), + G_CALLBACK (ev_window_cmd_edit_select_all) }, { "EditFind", GTK_STOCK_FIND, N_("_Find"), "F", N_("Find a word or phrase in the document"), G_CALLBACK (ev_window_cmd_edit_find) }, @@ -1126,24 +1451,24 @@ static GtkActionEntry entries[] = { { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "Right", N_("Go to the page viewed before this one"), G_CALLBACK (ev_window_cmd_go_forward) }, - { "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "Page_Up", + { "GoPageDown", GTK_STOCK_GO_UP, N_("_Page Up"), "Page_Up", N_("Go to the previous page"), - G_CALLBACK (ev_window_cmd_go_previous_page) }, - { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "Page_Down", + G_CALLBACK (ev_window_cmd_go_page_up) }, + { "GoPageUp", GTK_STOCK_GO_DOWN, N_("_Page Down"), "Page_Down", N_("Go to the next page"), - G_CALLBACK (ev_window_cmd_go_next_page) }, + G_CALLBACK (ev_window_cmd_go_page_down) }, { "GoFirstPage", GTK_STOCK_GOTO_FIRST, N_("_First Page"), "Home", N_("Go to the first page"), - G_CALLBACK (ev_window_cmd_go_first_page) }, + G_CALLBACK (ev_window_cmd_go_first_page) }, { "GoLastPage", GTK_STOCK_GOTO_LAST, N_("_Last Page"), "End", N_("Go to the last page"), G_CALLBACK (ev_window_cmd_go_last_page) }, - + /* Help menu */ { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL, N_("Display help for the viewer application"), G_CALLBACK (ev_window_cmd_help_contents) }, - + { "HelpAbout", GTK_STOCK_ABOUT, N_("_About"), NULL, N_("Display credits for the document viewer creators"), G_CALLBACK (ev_window_cmd_help_about) }, @@ -1166,6 +1491,72 @@ static GtkToggleActionEntry toggle_entries[] = { G_CALLBACK (ev_window_cmd_view_fullscreen) }, }; +static void +goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window) +{ + EvView *view = EV_VIEW (ev_window->priv->view); + + if (ev_view_get_page (view) != page_number) { + ev_view_set_page (view, page_number); + } +} + +static void +register_custom_actions (EvWindow *window, GtkActionGroup *group) +{ + GtkAction *action; + + action = g_object_new (EV_TYPE_NAVIGATION_ACTION, + "name", NAVIGATION_BACK_ACTION, + "label", _("Back"), + "stock_id", GTK_STOCK_GO_BACK, + "tooltip", _("Go back"), + "arrow-tooltip", _("Back history"), + "direction", EV_NAVIGATION_DIRECTION_BACK, + "is_important", TRUE, + NULL); + g_signal_connect (action, "activate", + G_CALLBACK (ev_window_cmd_go_back), window); + gtk_action_group_add_action (group, action); + g_object_unref (action); + + action = g_object_new (EV_TYPE_NAVIGATION_ACTION, + "name", NAVIGATION_FORWARD_ACTION, + "label", _("Forward"), + "stock_id", GTK_STOCK_GO_FORWARD, + "tooltip", _("Go forward"), + "arrow-tooltip", _("Forward history"), + "direction", EV_NAVIGATION_DIRECTION_FORWARD, + NULL); + g_signal_connect (action, "activate", + G_CALLBACK (ev_window_cmd_go_forward), window); + gtk_action_group_add_action (group, action); + g_object_unref (action); + + action = g_object_new (EV_TYPE_PAGE_ACTION, + "name", PAGE_SELECTOR_ACTION, + "label", _("Page"), + "tooltip", _("Select Page"), + NULL); + g_signal_connect (action, "goto_page", + G_CALLBACK (goto_page_cb), window); + gtk_action_group_add_action (group, action); + g_object_unref (action); +} + +static void +set_short_labels (GtkActionGroup *action_group) +{ + GtkAction *action; + + action = gtk_action_group_get_action (action_group, "GoPageUp"); + g_object_set (action, "short_label", _("Up"), NULL); + action = gtk_action_group_get_action (action_group, "GoPageDown"); + g_object_set (action, "short_label", _("Down"), NULL); + action = gtk_action_group_get_action (action_group, "ViewPageWidth"); + g_object_set (action, "short_label", _("Fit Width"), NULL); +} + static void ev_window_init (EvWindow *ev_window) { @@ -1184,7 +1575,7 @@ ev_window_init (EvWindow *ev_window) ev_window->priv->main_box = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box); gtk_widget_show (ev_window->priv->main_box); - + action_group = gtk_action_group_new ("MenuActions"); ev_window->priv->action_group = action_group; gtk_action_group_set_translation_domain (action_group, NULL); @@ -1193,6 +1584,8 @@ ev_window_init (EvWindow *ev_window) gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), ev_window); + set_short_labels (action_group); + register_custom_actions (ev_window, action_group); ev_window->priv->ui_manager = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager, @@ -1236,20 +1629,20 @@ ev_window_init (EvWindow *ev_window) ev_window->priv->sidebar); /* Stub sidebar, for now */ - sidebar_widget = ev_sidebar_bookmarks_new (); + sidebar_widget = ev_sidebar_links_new (); gtk_widget_show (sidebar_widget); ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar), - "bookmarks", - _("Bookmarks"), + "index", + _("Index"), sidebar_widget); - sidebar_widget = ev_sidebar_thumbnails_new (); - gtk_widget_show (sidebar_widget); + ev_window->priv->thumbs_sidebar = ev_sidebar_thumbnails_new (); + gtk_widget_show (ev_window->priv->thumbs_sidebar); ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar), "thumbnails", _("Thumbnails"), - sidebar_widget); - + ev_window->priv->thumbs_sidebar); + scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolled_window); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), @@ -1267,10 +1660,14 @@ ev_window_init (EvWindow *ev_window) G_CALLBACK (view_page_changed_cb), ev_window); g_signal_connect (ev_window->priv->view, - "find-status-changed", + "notify::find-status", G_CALLBACK (view_find_status_changed_cb), ev_window); - + g_signal_connect (ev_window->priv->view, + "notify::status", + G_CALLBACK (view_status_changed_cb), + ev_window); + ev_window->priv->statusbar = gtk_statusbar_new (); gtk_widget_show (ev_window->priv->statusbar); gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box), @@ -1278,12 +1675,14 @@ ev_window_init (EvWindow *ev_window) FALSE, TRUE, 0); ev_window->priv->help_message_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (ev_window->priv->statusbar), "help_message"); + ev_window->priv->view_message_cid = gtk_statusbar_get_context_id + (GTK_STATUSBAR (ev_window->priv->statusbar), "view_message"); ev_window->priv->find_bar = egg_find_bar_new (); gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box), ev_window->priv->find_bar, FALSE, TRUE, 0); - + /* Connect to find bar signals */ g_signal_connect (ev_window->priv->find_bar, "previous", @@ -1316,9 +1715,9 @@ ev_window_init (EvWindow *ev_window) g_signal_connect (ev_window, "focus_out_event", G_CALLBACK (ev_window_focus_out_cb), ev_window); - + /* Give focus to the scrolled window */ gtk_widget_grab_focus (scrolled_window); - + update_action_sensitivity (ev_window); -} +}