From: Owen Taylor Date: Wed, 22 Dec 2004 05:13:37 +0000 (+0000) Subject: Add a few more toolbar items. X-Git-Tag: EVINCE_0_1_0~101 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=d97441740d457e1463083d561afdb719ca99e66b;p=evince.git Add a few more toolbar items. Tue Dec 21 23:57:37 2004 Owen Taylor * 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. --- diff --git a/ChangeLog b/ChangeLog index fe7e53b5..b13df8ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +Tue Dec 21 23:57:37 2004 Owen Taylor + + * 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 * backend/ev-backend-marshal.c, diff --git a/backend/ev-document.c b/backend/ev-document.c index 02c24427..4aea1d11 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -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) diff --git a/backend/ev-document.h b/backend/ev-document.h index cc65f5cd..8d58f0c5 100644 --- a/backend/ev-document.h +++ b/backend/ev-document.h @@ -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, diff --git a/data/evince-ui.xml b/data/evince-ui.xml index 41dc86c6..035e7707 100644 --- a/data/evince-ui.xml +++ b/data/evince-ui.xml @@ -46,5 +46,10 @@ + + + + + diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc index 9a9d022e..a25f6630 100644 --- a/pdf/xpdf/pdf-document.cc +++ b/pdf/xpdf/pdf-document.cc @@ -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; diff --git a/shell/ev-marshal.list b/shell/ev-marshal.list index 38076d6c..559b357a 100644 --- a/shell/ev-marshal.list +++ b/shell/ev-marshal.list @@ -1 +1,2 @@ +VOID:NONE VOID:OBJECT,OBJECT diff --git a/shell/ev-view.c b/shell/ev-view.c index f52b3727..7aaa59ab 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -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; +} diff --git a/shell/ev-view.h b/shell/ev-view.h index bb958f3d..5173461c 100644 --- a/shell/ev-view.h +++ b/shell/ev-view.h @@ -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 diff --git a/shell/ev-window.c b/shell/ev-window.c index 8d0bcbf6..ec21ae90 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -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); }