From ec2aa10ab1ec9246d6c35b90f5d1df372f39c732 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Thu, 23 Dec 2004 03:09:00 +0000 Subject: display an error if the document doesn't support find (better ideas?) 2004-12-22 Havoc Pennington * shell/ev-window.c (ev_window_cmd_edit_find): display an error if the document doesn't support find (better ideas?) (find_bar_search_changed_cb): handle missing document or document that doesn't support find * pdf/xpdf/pdf-document.cc: port to implement the new EvDocumentFindIface * backend/ev-document-find.c: create a new interface for searching * backend/ev-document.h, backend/ev-document.c: delete the find stuff --- diff --git a/ChangeLog b/ChangeLog index 98180c4..c92ff05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2004-12-22 Havoc Pennington + + * shell/ev-window.c (ev_window_cmd_edit_find): display an error if + the document doesn't support find (better ideas?) + (find_bar_search_changed_cb): handle missing document or document + that doesn't support find + + * pdf/xpdf/pdf-document.cc: port to implement the new + EvDocumentFindIface + + * backend/ev-document-find.c: create a new interface for searching + + * backend/ev-document.h, backend/ev-document.c: delete the find stuff + 2004-12-23 Martin Kretzschmar * pdf/xpdf/Makefile.am (libpdfdocument_la_LIBADD): add diff --git a/backend/Makefile.am b/backend/Makefile.am index 5ccd5a1..d1f5cbf 100644 --- a/backend/Makefile.am +++ b/backend/Makefile.am @@ -17,6 +17,8 @@ libevbackend_la_SOURCES= \ ev-document-thumbnails.h \ ev-document-bookmarks.c \ ev-document-bookmarks.h \ + ev-document-find.c \ + ev-document-find.h \ ev-ps-exporter.c \ ev-ps-exporter.h \ $(NULL) diff --git a/backend/ev-document.c b/backend/ev-document.c index 2f50dcc..59697bd 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -21,7 +21,7 @@ #include "config.h" #include "ev-document.h" -#include "ev-backend-marshal.c" +#include "ev-backend-marshalers.h" static void ev_document_base_init (gpointer g_class); @@ -50,22 +50,7 @@ ev_document_get_type (void) static void ev_document_base_init (gpointer g_class) { - static gboolean initialized = FALSE; - - if (!initialized) { - g_signal_new ("found", - EV_TYPE_DOCUMENT, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EvDocumentIface, found), - NULL, NULL, - _ev_backend_marshal_VOID__POINTER_INT_DOUBLE, - G_TYPE_NONE, 3, - G_TYPE_POINTER, - G_TYPE_INT, - G_TYPE_DOUBLE); - - initialized = TRUE; - } + } gboolean @@ -143,31 +128,4 @@ ev_document_render (EvDocument *document, EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); iface->render (document, clip_x, clip_y, clip_width, clip_height); } - -void -ev_document_begin_find (EvDocument *document, - const char *search_string, - gboolean case_sensitive) -{ - EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - iface->begin_find (document, search_string, case_sensitive); -} - -void -ev_document_end_find (EvDocument *document) -{ - EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - iface->end_find (document); -} - -void -ev_document_found (EvDocument *document, - const EvFindResult *results, - int n_results, - double percent_complete) -{ - g_signal_emit_by_name (document, - "found", - results, n_results, percent_complete); -} diff --git a/backend/ev-document.h b/backend/ev-document.h index 4cf4601..083bd1a 100644 --- a/backend/ev-document.h +++ b/backend/ev-document.h @@ -28,12 +28,6 @@ G_BEGIN_DECLS -typedef struct -{ - int page_num; - GdkRectangle highlight_area; -} EvFindResult; - #define EV_TYPE_DOCUMENT (ev_document_get_type ()) #define EV_DOCUMENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT, EvDocument)) #define EV_DOCUMENT_IFACE(k) (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT, EvDocumentIface)) @@ -71,23 +65,6 @@ struct _EvDocumentIface int clip_y, int clip_width, int clip_height); - - void (* begin_find) (EvDocument *document, - const char *search_string, - gboolean case_sensitive); - void (* end_find) (EvDocument *document); - - /* Signals */ - - /* "found" emitted at least 1 time (possibly with n_results == 0) - * for any call to begin_find; also emitted with NULL,0 when - * you end_find. Calling begin_find twice without calling end_find - * is considered OK. - */ - void (* found) (EvDocument *document, - const EvFindResult *results, - int n_results, - double percent_complete); }; GType ev_document_get_type (void); @@ -114,16 +91,6 @@ void ev_document_render (EvDocument *document, int clip_y, int clip_width, int clip_height); -void ev_document_begin_find (EvDocument *document, - const char *search_string, - gboolean case_sensitive); -void ev_document_end_find (EvDocument *document); - -void ev_document_found (EvDocument *document, - const EvFindResult *results, - int n_results, - double percent_complete); - G_END_DECLS diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc index 8323ebe..efee462 100644 --- a/pdf/xpdf/pdf-document.cc +++ b/pdf/xpdf/pdf-document.cc @@ -20,6 +20,7 @@ #include "gpdf-g-switch.h" #include "pdf-document.h" #include "ev-ps-exporter.h" +#include "ev-document-find.h" #include "gpdf-g-switch.h" #include "GlobalParams.h" @@ -55,8 +56,9 @@ struct _PdfDocument gboolean page_valid; }; -static void pdf_document_document_iface_init (EvDocumentIface *iface); -static void pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface); +static void pdf_document_document_iface_init (EvDocumentIface *iface); +static void pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface); +static void pdf_document_find_iface_init (EvDocumentFindIface *iface); G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT, { @@ -64,6 +66,8 @@ G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT, pdf_document_document_iface_init); G_IMPLEMENT_INTERFACE (EV_TYPE_PS_EXPORTER, pdf_document_ps_exporter_iface_init); + G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND, + pdf_document_find_iface_init); }); static gboolean @@ -281,9 +285,9 @@ pdf_document_render (EvDocument *document, } static void -pdf_document_begin_find (EvDocument *document, - const char *search_string, - gboolean case_sensitive) +pdf_document_find_begin (EvDocumentFind *document, + const char *search_string, + gboolean case_sensitive) { /* FIXME make this incremental (idle handler) and multi-page */ /* Right now it's fully synchronous plus only does the current page */ @@ -340,26 +344,22 @@ pdf_document_begin_find (EvDocument *document, } } - ev_document_found (document, - (EvFindResult*) results->data, - results->len, - 1.0); + ev_document_find_found (document, + (EvFindResult*) results->data, + results->len, + 1.0); g_array_free (results, TRUE); } static void -pdf_document_end_find (EvDocument *document) +pdf_document_find_cancel (EvDocumentFind *document) { PdfDocument *pdf_document = PDF_DOCUMENT (document); /* FIXME this will do something once begin_find queues * an incremental find */ - - // this should probably be shared among EvDocument - // implementations somehow? - ev_document_found (document, NULL, 0, 1.0); } static void @@ -431,8 +431,6 @@ pdf_document_document_iface_init (EvDocumentIface *iface) iface->set_page_offset = pdf_document_set_page_offset; iface->get_page_size = pdf_document_get_page_size; iface->render = pdf_document_render; - iface->begin_find = pdf_document_begin_find; - iface->end_find = pdf_document_end_find; } static void @@ -443,6 +441,14 @@ pdf_document_ps_exporter_iface_init (EvPSExporterIface *iface) iface->end = pdf_document_ps_export_end; } + +static void +pdf_document_find_iface_init (EvDocumentFindIface *iface) +{ + iface->begin = pdf_document_find_begin; + iface->cancel = pdf_document_find_cancel; +} + static void pdf_document_init (PdfDocument *pdf_document) { diff --git a/pixbuf/pixbuf-document.c b/pixbuf/pixbuf-document.c index 7eeb8fd..01df278 100644 --- a/pixbuf/pixbuf-document.c +++ b/pixbuf/pixbuf-document.c @@ -176,19 +176,6 @@ pixbuf_document_render (EvDocument *document, } static void -pixbuf_document_begin_find (EvDocument *document, - const char *search_string, - gboolean case_sensitive) -{ - -} - -static void -pixbuf_document_end_find (EvDocument *document) -{ -} - -static void pixbuf_document_finalize (GObject *object) { PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object); @@ -220,8 +207,6 @@ pixbuf_document_document_iface_init (EvDocumentIface *iface) iface->set_page_offset = pixbuf_document_set_page_offset; iface->get_page_size = pixbuf_document_get_page_size; iface->render = pixbuf_document_render; - iface->begin_find = pixbuf_document_begin_find; - iface->end_find = pixbuf_document_end_find; } static GdkPixbuf * diff --git a/ps/gtkgs.c b/ps/gtkgs.c index 4c895b9..ebb29f2 100644 --- a/ps/gtkgs.c +++ b/ps/gtkgs.c @@ -2156,18 +2156,6 @@ ps_document_render (EvDocument *document, } static void -ps_document_begin_find (EvDocument *document, - const char *search_string, - gboolean case_sensitive) -{ -} - -static void -ps_document_end_find (EvDocument *document) -{ -} - -static void ps_document_document_iface_init (EvDocumentIface *iface) { iface->load = ps_document_load; @@ -2179,6 +2167,4 @@ ps_document_document_iface_init (EvDocumentIface *iface) iface->set_page_offset = ps_document_set_page_offset; iface->get_page_size = ps_document_get_page_size; iface->render = ps_document_render; - iface->begin_find = ps_document_begin_find; - iface->end_find = ps_document_end_find; } diff --git a/shell/ev-view.c b/shell/ev-view.c index 4553525..8f8f068 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -22,6 +22,7 @@ #include "ev-marshal.h" #include "ev-view.h" +#include "ev-document-find.h" #define EV_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_VIEW, EvViewClass)) #define EV_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EV_TYPE_VIEW)) diff --git a/shell/ev-window.c b/shell/ev-window.c index e0445c6..405f86b 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -34,6 +34,7 @@ #include "ev-sidebar-thumbnails.h" #include "ev-view.h" #include "ev-print-job.h" +#include "ev-document-find.h" #include "eggfindbar.h" #include "pdf-document.h" @@ -405,16 +406,42 @@ ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window) } static void +find_not_supported_dialog (EvWindow *ev_window) +{ + GtkWidget *dialog; + + /* 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, + GTK_BUTTONS_CLOSE, + _("The \"Find\" feature will not work with this document")); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + _("Searching for text is only supported for PDF documents.")); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); +} + +static void ev_window_cmd_edit_find (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - gtk_widget_show (ev_window->priv->find_bar); + if (ev_window->priv->document == NULL) { + g_printerr ("We should have set the Find menu item insensitive since there's no document\n"); + } else if (!EV_IS_DOCUMENT_FIND (ev_window->priv->document)) { + find_not_supported_dialog (ev_window); + } else { + gtk_widget_show (ev_window->priv->find_bar); - if (ev_window->priv->exit_fullscreen_popup) - update_fullscreen_popup (ev_window); + 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)); + egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar)); + } } static void @@ -442,7 +469,7 @@ update_fullscreen_popup (EvWindow *window) /* FIXME multihead */ gdk_screen_get_monitor_geometry (gdk_screen_get_default (), - gdk_screen_get_monitor_at_window + gdk_screen_get_monitor_at_window (gdk_screen_get_default (), GTK_WIDGET (window)->window), &screen_rect); @@ -922,10 +949,13 @@ find_bar_search_changed_cb (EggFindBar *find_bar, /* We don't require begin/end find calls to be matched up, it's really * start_find and cancel_any_find_that_may_not_be_finished */ - if (visible && search_string) { - ev_document_begin_find (ev_window->priv->document, search_string, case_sensitive); - } else { - ev_document_end_find (ev_window->priv->document); + if (ev_window->priv->document && + EV_IS_DOCUMENT_FIND (ev_window->priv->document)) { + if (visible && search_string) { + ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive); + } else { + ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document)); + } } } -- cgit v0.9.1