]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Queue a resize when zoom changes
[evince.git] / shell / ev-window.c
index 19394f5034195718527af2410e0000d022e52798..007ca8893ac86d434178bde2ad9beb9d35b3695e 100644 (file)
@@ -29,6 +29,8 @@
 #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-thumbnails.h"
@@ -72,6 +74,8 @@ struct _EvWindowPrivate {
        GtkWidget *statusbar;
        guint help_message_cid;
        GtkWidget *exit_fullscreen_popup;
+       char *uri;
+       GtkAction *page_action;
 
        EvDocument *document;
 
@@ -181,8 +185,8 @@ update_action_sensitivity (EvWindow *ev_window)
        page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
 
        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, "GoPageDown", page > 1);
+       set_action_sensitive (ev_window, "GoPageUp", page < n_pages);
        set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
 }
 
@@ -249,11 +253,45 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
        return retval;
 }
 
+static void
+update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window)
+{
+       char *title = NULL;
+
+       if (document == NULL) {
+               title = g_strdup (_("Document Viewer"));
+       } else {
+               title = ev_document_get_title (document);
+
+               if (title == NULL) {
+                       title = g_path_get_basename (ev_window->priv->uri);
+               }
+       }
+
+       gtk_window_set_title (GTK_WINDOW (ev_window), title);
+
+       g_free (title);
+}
+
+static void
+update_total_pages (EvWindow *ev_window)
+{
+       EvPageAction *page_action;
+       int pages;
+
+       pages = ev_document_get_n_pages (ev_window->priv->document);
+       page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
+       ev_page_action_set_total_pages (page_action, pages);
+}
+
 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);
 
        mime_type = gnome_vfs_get_mime_type (uri);
 
@@ -269,6 +307,11 @@ ev_window_open (EvWindow *ev_window, const char *uri)
        if (document) {
                GError *error = 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);
@@ -279,8 +322,8 @@ ev_window_open (EvWindow *ev_window, const char *uri)
                        ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar),
                                                 document);
 
+                       update_total_pages (ev_window);
                        update_action_sensitivity (ev_window);
-               
                } else {
                        g_assert (error != NULL);
                        g_object_unref (document);
@@ -712,7 +755,7 @@ ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
 }
 
 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));
 
@@ -721,7 +764,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));
 
@@ -893,10 +936,22 @@ disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
        }
 }
 
+static void
+update_current_page (EvWindow *ev_window)
+{
+       EvPageAction *page_action;
+       int page;
+
+       page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
+       page_action = EV_PAGE_ACTION (ev_window->priv->page_action);
+       ev_page_action_set_current_page (page_action, page);
+}
+
 static void
 view_page_changed_cb (EvView   *view,
                      EvWindow *ev_window)
 {
+       update_current_page (ev_window);
        update_action_sensitivity (ev_window);
 }
 
@@ -1097,12 +1152,12 @@ static GtkActionEntry entries[] = {
         { "GoForward", GTK_STOCK_GO_FORWARD, N_("Fo_rward"), "<mod1>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"), "<control>Page_Up",
+        { "GoPageDown", GTK_STOCK_GO_UP, N_("_Page Up"), "<control>Page_Up",
           N_("Go to the previous page"),
-          G_CALLBACK (ev_window_cmd_go_previous_page) },
-        { "GoNextPage", GTK_STOCK_GO_FORWARD, N_("_Next Page"), "<control>Page_Down",
+          G_CALLBACK (ev_window_cmd_go_page_up) },
+        { "GoPageUp", GTK_STOCK_GO_DOWN, N_("_Page Down"), "<control>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"), "<control>Home",
           N_("Go to the first page"),
           G_CALLBACK (ev_window_cmd_go_first_page) },        
@@ -1137,6 +1192,53 @@ static GtkToggleActionEntry toggle_entries[] = {
           G_CALLBACK (ev_window_cmd_view_fullscreen) },
 };
 
+static void
+goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window)
+{
+
+       ev_view_set_page (EV_VIEW (ev_window->priv->view), page_number);
+}
+
+static void
+register_custom_actions (EvWindow *window, GtkActionGroup *group)
+{
+       GtkAction *action;
+
+       action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
+                              "name", "NavigationBack",
+                              "label", _("Back"),
+                              "stock_id", GTK_STOCK_GO_BACK,
+                              "tooltip", _("Go back"),
+                              "arrow-tooltip", _("Back history"),
+                              "direction", EV_NAVIGATION_DIRECTION_BACK,
+                              "is_important", TRUE,
+                              NULL);
+       gtk_action_group_add_action (group, action);
+       g_object_unref (action);
+
+       action = g_object_new (EV_TYPE_NAVIGATION_ACTION,
+                              "name", "NavigationForward",
+                              "label", _("Forward"),
+                              "stock_id", GTK_STOCK_GO_FORWARD,
+                              "tooltip", _("Go forward"),
+                              "arrow-tooltip", _("Forward history"),
+                              "direction", EV_NAVIGATION_DIRECTION_FORWARD,
+                              NULL);
+       gtk_action_group_add_action (group, action);
+       g_object_unref (action);
+
+       action = g_object_new (EV_TYPE_PAGE_ACTION,
+                              "name", "PageSelector",
+                              "label", _("Page"),
+                              "tooltip", _("Select Page"),
+                              NULL);
+       g_signal_connect (action, "goto_page",
+                         G_CALLBACK (goto_page_cb), window);
+       window->priv->page_action = action;
+       gtk_action_group_add_action (group, action);
+       g_object_unref (action);
+}
+
 static void
 ev_window_init (EvWindow *ev_window)
 {
@@ -1150,7 +1252,7 @@ ev_window_init (EvWindow *ev_window)
 
        ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
 
-       gtk_window_set_title (GTK_WINDOW (ev_window), _("Document Viewer"));
+       update_window_title (NULL, NULL, ev_window);
 
        ev_window->priv->main_box = gtk_vbox_new (FALSE, 0);
        gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box);
@@ -1165,6 +1267,8 @@ ev_window_init (EvWindow *ev_window)
                                             G_N_ELEMENTS (toggle_entries),
                                             ev_window);
 
+       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,
                                            action_group, 0);