]> www.fi.muni.cz Git - evince.git/commitdiff
Add a few more toolbar items.
authorOwen Taylor <otaylor@redhat.com>
Wed, 22 Dec 2004 05:13:37 +0000 (05:13 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Wed, 22 Dec 2004 05:13:37 +0000 (05:13 +0000)
Tue Dec 21 23:57:37 2004  Owen Taylor  <otaylor@redhat.com>

        * data/evince-ui.xml: Add a few more toolbar items.

        * shell/ev-window.c: Hook up page navigation toolbar
        items.

        * shell/ev-view.[ch]: add ev_view_set/get_page and
        a page-changed signal.

        * backend/ev-document.{h,cc} pdf/xpdf/pdf-document.cc::
        Add ev_document_get_page().

        * shell/ev-window.c: Sensitize/desensitize navigation
        actions.

ChangeLog
backend/ev-document.c
backend/ev-document.h
data/evince-ui.xml
pdf/xpdf/pdf-document.cc
shell/ev-marshal.list
shell/ev-view.c
shell/ev-view.h
shell/ev-window.c

index fe7e53b5063d39dbe76dea22d958e068f959e44f..b13df8ba1243e8f09e989881b4b8f6b28efbf196 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+Tue Dec 21 23:57:37 2004  Owen Taylor  <otaylor@redhat.com>
+
+       * data/evince-ui.xml: Add a few more toolbar items.
+
+       * shell/ev-window.c: Hook up page navigation toolbar 
+       items.
+
+       * shell/ev-view.[ch]: add ev_view_set/get_page and 
+       a page-changed signal.
+
+       * backend/ev-document.{h,cc} pdf/xpdf/pdf-document.cc::
+       Add ev_document_get_page().
+
+       * shell/ev-window.c: Sensitize/desensitize navigation
+       actions.
+
 2004-12-21  Havoc Pennington  <hp@redhat.com>
 
        * backend/ev-backend-marshal.c,
index 02c24427f288c2523cd49a0e1eeed8ae8d98ae14..4aea1d11c0fbeaf5afc6261c1b20088f484fc8ad 100644 (file)
@@ -92,6 +92,13 @@ ev_document_set_page (EvDocument  *document,
        iface->set_page (document, page);
 }
 
+int
+ev_document_get_page (EvDocument *document)
+{
+       EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
+       return iface->get_page (document);
+}
+
 void
 ev_document_set_target (EvDocument  *document,
                        GdkDrawable *target)
index cc65f5cd45347c116c7f95e6b900fdd574255b7f..8d58f0c501d9d10345169ca1aae16a4047d5562a 100644 (file)
@@ -55,6 +55,7 @@ struct _EvDocumentIface
        int         (* get_n_pages)     (EvDocument *document);
        void        (* set_page)        (EvDocument  *document,
                                         int          page);
+       int         (* get_page)        (EvDocument  *document);
        void        (* set_target)      (EvDocument  *document,
                                         GdkDrawable *target);
        void        (* set_scale)       (EvDocument  *document,
@@ -95,6 +96,7 @@ gboolean ev_document_load            (EvDocument   *document,
 int      ev_document_get_n_pages     (EvDocument   *document);
 void     ev_document_set_page        (EvDocument   *document,
                                      int           page);
+int      ev_document_get_page        (EvDocument   *document);
 void     ev_document_set_target      (EvDocument   *document,
                                      GdkDrawable  *target);
 void     ev_document_set_scale       (EvDocument   *document,
index 41dc86c69953fc1336b818db9670f51a7df5ae92..035e7707f54dd94bdb91c461a254b4145f5f6cee 100644 (file)
 
   <toolbar name="ToolBar">
     <toolitem action="FileOpen"/>
+    <separator/>
+    <toolitem action="GoFirstPage"/>
+    <toolitem action="GoPreviousPage"/>
+    <toolitem action="GoNextPage"/>
+    <toolitem action="GoLastPage"/>
   </toolbar>
 </ui>
index 9a9d022e5f2974a3f1782ec1a4528180611293cf..a25f663030b57926fa6dc02978b9b8c52100d1d1 100644 (file)
@@ -141,6 +141,8 @@ pdf_document_set_page (EvDocument  *document,
 {
        PdfDocument *pdf_document = PDF_DOCUMENT (document);
 
+       page = CLAMP (page, 1, ev_document_get_n_pages (document));
+
        if (page != pdf_document->page) {
                pdf_document->page = page;
                pdf_document->page_valid = FALSE;
@@ -148,6 +150,14 @@ pdf_document_set_page (EvDocument  *document,
 
 }
 
+static int
+pdf_document_get_page (EvDocument  *document)
+{
+       PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+       return pdf_document->page;
+}
+
 static void
 redraw_callback (void *data)
 {
@@ -290,6 +300,7 @@ pdf_document_document_iface_init (EvDocumentIface *iface)
        iface->load = pdf_document_load;
        iface->get_n_pages = pdf_document_get_n_pages;
        iface->set_page = pdf_document_set_page;
+       iface->get_page = pdf_document_get_page;
        iface->set_scale = pdf_document_set_scale;
        iface->set_target = pdf_document_set_target;
        iface->set_page_offset = pdf_document_set_page_offset;
index 38076d6cf12b741922c4e52743bc9e685dadc752..559b357a1a51bb8cd0af4f54d0282178ed20076f 100644 (file)
@@ -1 +1,2 @@
+VOID:NONE
 VOID:OBJECT,OBJECT
index f52b372778c11d56b31ac5991454292b3405a9fe..7aaa59aba9a611ab083baa466a81e181a439a03b 100644 (file)
@@ -46,8 +46,13 @@ struct _EvViewClass {
        void    (*set_scroll_adjustments) (EvView         *view,
                                           GtkAdjustment  *hadjustment,
                                           GtkAdjustment  *vadjustment);
+       
+       /* Should this be notify::page? */
+       void    (*page_changed)           (EvView         *view);
 };
 
+static guint page_changed_signal = 0;
+
 static void ev_view_set_scroll_adjustments (EvView         *view,
                                            GtkAdjustment  *hadjustment,
                                            GtkAdjustment  *vadjustment);
@@ -410,6 +415,13 @@ ev_view_class_init (EvViewClass *class)
                                                                     G_TYPE_NONE, 2,
                                                                     GTK_TYPE_ADJUSTMENT,
                                                                     GTK_TYPE_ADJUSTMENT);
+       page_changed_signal = g_signal_new ("page-changed",
+                                           G_OBJECT_CLASS_TYPE (object_class),
+                                           G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                                           G_STRUCT_OFFSET (EvViewClass, page_changed),
+                                           NULL, NULL,
+                                           ev_marshal_VOID__NONE,
+                                           G_TYPE_NONE, 0);
 }
 
 static void
@@ -435,6 +447,8 @@ ev_view_set_document (EvView     *view,
        g_return_if_fail (EV_IS_VIEW (view));
 
        if (document != view->document) {
+               int old_page = ev_view_get_page (view);
+               
                if (view->document)
                        g_object_unref (view->document);
 
@@ -447,5 +461,32 @@ ev_view_set_document (EvView     *view,
                        ev_document_set_target (view->document, view->bin_window);
                
                gtk_widget_queue_resize (GTK_WIDGET (view));
+               
+               if (old_page != ev_view_get_page (view))
+                       g_signal_emit (view, page_changed_signal, 0);
+       }
+}
+
+void
+ev_view_set_page (EvView *view,
+                 int     page)
+{
+       if (view->document) {
+               int old_page = ev_document_get_page (view->document);
+               if (old_page != page)
+                       ev_document_set_page (view->document, page);
+               if (old_page != ev_document_get_page (view->document)) {
+                       g_signal_emit (view, page_changed_signal, 0);
+                       gtk_widget_queue_draw (GTK_WIDGET (view));
+               }
        }
 }
+
+int
+ev_view_get_page (EvView *view)
+{
+       if (view->document)
+               return ev_document_get_page (view->document);
+       else
+               return 1;
+}
index bb958f3d1373119010fac753530937e5f1d8f0bd..5173461cfd6bb0907995279e494afe9bc25f6d17 100644 (file)
@@ -37,8 +37,11 @@ typedef struct _EvViewClass  EvViewClass;
 GType     ev_view_get_type (void) G_GNUC_CONST;
 GtkWidget* ev_view_new      (void);
 
-void       ev_view_set_document (EvView     *view,
-                                EvDocument *document);
+void ev_view_set_document (EvView     *view,
+                          EvDocument *document);
+void ev_view_set_page     (EvView     *view,
+                          int         page);
+int  ev_view_get_page     (EvView     *view);
 
 G_END_DECLS
 
index 8d0bcbf6639674a2db4ef1748921e9e1c200e458..ec21ae9060254ecdb7df4667e344b8723f0c9b50 100644 (file)
@@ -60,6 +60,7 @@ struct _EvWindowPrivate {
        GtkWidget *find_bar;
        GtkWidget *bonobo_widget;
        GtkWidget *view;
+       GtkActionGroup *action_group;
        GtkUIManager *ui_manager;
        GtkWidget *statusbar;
        guint help_message_cid;
@@ -144,6 +145,35 @@ ev_window_set_property (GObject *object, guint prop_id, const GValue *value,
 }
 #endif
 
+static void
+set_action_sensitive (EvWindow   *ev_window,
+                     const char *name,
+                     gboolean    sensitive)
+{
+       GtkAction *action = gtk_action_group_get_action (ev_window->priv->action_group,
+                                                        name);
+       gtk_action_set_sensitive (action, sensitive);
+}
+
+static void
+update_action_sensitivity (EvWindow *ev_window)
+{
+       int n_pages;
+       int page;
+
+       if (ev_window->priv->document)
+               n_pages = ev_document_get_n_pages (ev_window->priv->document);
+       else
+               n_pages = 1;
+
+       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, "GoLastPage", page < n_pages);
+}
+
 gboolean
 ev_window_is_empty (const EvWindow *ev_window)
 {
@@ -165,6 +195,8 @@ ev_window_open (EvWindow *ev_window, const char *uri)
 
                ev_view_set_document (EV_VIEW (ev_window->priv->view),
                                      document);
+
+               update_action_sensitivity (ev_window);
                
        } else {
                GtkWidget *dialog;
@@ -336,7 +368,8 @@ ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
 {
         g_return_if_fail (EV_IS_WINDOW (ev_window));
 
-        /* FIXME */
+       ev_view_set_page (EV_VIEW (ev_window->priv->view),
+                         ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
 }
 
 static void
@@ -344,7 +377,8 @@ ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
 {
         g_return_if_fail (EV_IS_WINDOW (ev_window));
 
-        /* FIXME */
+       ev_view_set_page (EV_VIEW (ev_window->priv->view),
+                         ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
 }
 
 static void
@@ -352,7 +386,7 @@ ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
 {
         g_return_if_fail (EV_IS_WINDOW (ev_window));
 
-        /* FIXME */
+       ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
 }
 
 static void
@@ -360,7 +394,7 @@ ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
 {
         g_return_if_fail (EV_IS_WINDOW (ev_window));
 
-        /* FIXME */
+       ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
 }
 
 static void
@@ -507,6 +541,13 @@ disconnect_proxy_cb (GtkUIManager *ui_manager, GtkAction *action,
        }
 }
 
+static void
+view_page_changed_cb (EvView   *view,
+                     EvWindow *ev_window)
+{
+       update_action_sensitivity (ev_window);
+}
+
 static void
 find_bar_previous_cb (EggFindBar *find_bar,
                      EvWindow   *ev_window)
@@ -570,6 +611,11 @@ ev_window_dispose (GObject *object)
                priv->ui_manager = NULL;
        }
 
+       if (priv->action_group) {
+               g_object_unref (priv->action_group);
+               priv->action_group = NULL;
+       }
+       
        G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
@@ -728,8 +774,9 @@ 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);
        gtk_action_group_add_actions (action_group, entries,
                                      G_N_ELEMENTS (entries), ev_window);
@@ -805,6 +852,10 @@ ev_window_init (EvWindow *ev_window)
        gtk_widget_show (ev_window->priv->view);
        gtk_container_add (GTK_CONTAINER (scrolled_window),
                           ev_window->priv->view);
+       g_signal_connect (ev_window->priv->view,
+                         "page-changed",
+                         G_CALLBACK (view_page_changed_cb),
+                         ev_window);
 
        ev_window->priv->statusbar = gtk_statusbar_new ();
        gtk_widget_show (ev_window->priv->statusbar);
@@ -844,4 +895,6 @@ ev_window_init (EvWindow *ev_window)
                          "notify::visible",
                          G_CALLBACK (find_bar_search_changed_cb),
                          ev_window);
+       
+       update_action_sensitivity (ev_window);
 }