]> www.fi.muni.cz Git - evince.git/commitdiff
display an error if the document doesn't support find (better ideas?)
authorHavoc Pennington <hp@redhat.com>
Thu, 23 Dec 2004 03:09:00 +0000 (03:09 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Thu, 23 Dec 2004 03:09:00 +0000 (03:09 +0000)
2004-12-22  Havoc Pennington  <hp@redhat.com>

* 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

ChangeLog
backend/Makefile.am
backend/ev-document.c
backend/ev-document.h
pdf/xpdf/pdf-document.cc
pixbuf/pixbuf-document.c
ps/gtkgs.c
shell/ev-view.c
shell/ev-window.c

index 98180c43d7745a0aa7f4d6228a70d7fb43d68c39..c92ff05b8af04a545194f18bc92d449001173fde 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2004-12-22  Havoc Pennington  <hp@redhat.com>
+
+       * 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  <martink@gnome.org>
 
        * pdf/xpdf/Makefile.am (libpdfdocument_la_LIBADD): add
index 5ccd5a100450514f24d69dbe1634b37fbe5df15a..d1f5cbf06843e9e3926c6fee2416a0957d73ee2f 100644 (file)
@@ -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)
index 2f50dcc832d05bdbdc14254f00d47f8c12b2ea93..59697bd6a2bc82985306a4d778336a167a4fd9d3 100644 (file)
@@ -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);
-}
                                    
index 4cf4601fc0cac639a83eec7cd2288e881ae7a126..083bd1ae5829cd4fe949e1356cc44d02b1e3c4cf 100644 (file)
 
 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
 
index 8323ebe380677bfc646cf4f6abe92d2b8cce787f..efee46252083820896f1df2af0f8cc61f174b9a9 100644 (file)
@@ -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)
 {
index 7eeb8fdaf986e699b568151e8775e536976818f6..01df2783b705b0e08911434c651af889b5624a18 100644 (file)
@@ -175,19 +175,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)
 {
@@ -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 *
index 4c895b95c01d2b9b9b65c29f6be90a0539bc80c3..ebb29f2341be7c39e6b42d8279d455ab0fc1db44 100644 (file)
@@ -2155,18 +2155,6 @@ ps_document_render (EvDocument  *document,
        g_object_unref (gc);
 }
 
-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)
 {
@@ -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;
 }
index 45535253d2ad349dfc62655d008ca594b6333f3c..8f8f068fb3c94522101dc48177b3601e04b99dae 100644 (file)
@@ -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))
index e0445c67fe1ed0a06736de06d1597a7a2d8ebd26..405f86bca45d4aff9aa3bac7b4ceccd35cbc2f65 100644 (file)
@@ -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"
@@ -404,17 +405,43 @@ ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
        gtk_widget_destroy (GTK_WIDGET (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));
+               }
        }
 }