]> www.fi.muni.cz Git - evince.git/commitdiff
Check if text inserted in page entry is a valid page number when it
authorCarlos Garcia Campos <carlosgc@gnome.org>
Fri, 15 Dec 2006 10:18:38 +0000 (10:18 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Fri, 15 Dec 2006 10:18:38 +0000 (10:18 +0000)
2006-12-15  Carlos Garcia Campos  <carlosgc@gnome.org>
* shell/ev-page-action.[ch]: (activate_cb):
* shell/ev-window.c: (activate_label_cb):
Check if text inserted in page entry is a valid page number when it
doesn't match to any document page label. Fixes bug #383165.

ChangeLog
shell/ev-page-action.c
shell/ev-page-action.h
shell/ev-window.c

index ec4746bd30c31058cd43a139f61f95281b75e525..0fbc1647192a85958d3c376e8d10c2a945b3c48e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-12-15  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-page-action.[ch]: (activate_cb):
+       * shell/ev-window.c: (activate_label_cb):
+
+       Check if text inserted in page entry is a valid page number when it
+       doesn't match to any document page label. Fixes bug #383165.
+
 2006-12-14  Julien Rebetez,  <julienr@cvs.gnome.org>
        * shell/ev-window.c:
 
index 52c74f549e60e6c74eaed987d1cc0fbb16f7652c..7c28edc9a8c7ec9a4679b00208b46a41e5f83ed2 100644 (file)
@@ -33,6 +33,7 @@
 #include <gtk/gtklabel.h>
 #include <gtk/gtkhbox.h>
 #include <string.h>
+#include <stdlib.h>
 
 struct _EvPageActionPrivate
 {
@@ -113,6 +114,8 @@ activate_cb (GtkWidget *entry, GtkAction *action)
        EvPageAction *page = EV_PAGE_ACTION (action);
        EvPageCache *page_cache;
        const char *text;
+       gchar *page_label;
+       gint page_number;
        gboolean changed;
 
        text = gtk_entry_get_text (GTK_ENTRY (entry));
@@ -120,16 +123,30 @@ activate_cb (GtkWidget *entry, GtkAction *action)
 
        g_signal_emit (action, signals[ACTIVATE_LABEL], 0, text, &changed);
 
-       if (!changed) {
-               /* rest the entry to the current page if we were unable to
-                * change it */
-               gchar *page_label =
-                       ev_page_cache_get_page_label (page_cache,
-                                                     ev_page_cache_get_current_page (page_cache));
+       if (changed)
+               return;
+       
+       /* Check whether it's a valid page number */
+       page_number = atoi (text) - 1;
+       if (page_number >= 0 &&
+           page_number < ev_page_cache_get_n_pages (page_cache)) {
+               page_label = ev_page_cache_get_page_label (page_cache, page_number);
                gtk_entry_set_text (GTK_ENTRY (entry), page_label);
                gtk_editable_set_position (GTK_EDITABLE (entry), -1);
+
+               g_signal_emit (action, signals[ACTIVATE_LABEL], 0, page_label, &changed);
                g_free (page_label);
+               
+               return;
        }
+       
+       /* rest the entry to the current page if we were unable to
+        * change it */
+       page_label = ev_page_cache_get_page_label (page_cache,
+                                                  ev_page_cache_get_current_page (page_cache));
+       gtk_entry_set_text (GTK_ENTRY (entry), page_label);
+       gtk_editable_set_position (GTK_EDITABLE (entry), -1);
+       g_free (page_label);
 }
 
 static GtkWidget *
index d89a3d90f03950154229a6a10d607f727e05635d..2908d3456dd9d97c8f47a777f83e6007531c494a 100644 (file)
@@ -53,7 +53,7 @@ struct _EvPageActionClass
        void     (* activate_link) (EvPageAction *page_action,
                                    EvLink       *link);
        gboolean (*activate_label) (EvPageAction *page_action,
-                                   char         *label);
+                                   const gchar  *label);
 };
 
 GType ev_page_action_get_type     (void);
index a4a6b6ec9f97d1967ecba600b8eb4b91fa12ef88..19ad581b3b64ba30b50c73a4845f09407dc366fa 100644 (file)
@@ -3891,7 +3891,7 @@ activate_link_cb (EvPageAction *page_action, EvLink *link, EvWindow *window)
 }
 
 static gboolean
-activate_label_cb (EvPageAction *page_action, char *label, EvWindow *window)
+activate_label_cb (EvPageAction *page_action, const gchar *label, EvWindow *window)
 {
        g_return_val_if_fail (EV_IS_WINDOW (window), FALSE);