From: Carlos Garcia Campos Date: Fri, 15 Dec 2006 10:18:38 +0000 (+0000) Subject: Check if text inserted in page entry is a valid page number when it X-Git-Tag: EVINCE_0_7_0~8 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=602f7fc6c5e5ff91e64de65758a6464431dbbcc9;p=evince.git Check if text inserted in page entry is a valid page number when it 2006-12-15 Carlos Garcia Campos * 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. --- diff --git a/ChangeLog b/ChangeLog index ec4746bd..0fbc1647 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-12-15 Carlos Garcia Campos + + * 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, * shell/ev-window.c: diff --git a/shell/ev-page-action.c b/shell/ev-page-action.c index 52c74f54..7c28edc9 100644 --- a/shell/ev-page-action.c +++ b/shell/ev-page-action.c @@ -33,6 +33,7 @@ #include #include #include +#include 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 * diff --git a/shell/ev-page-action.h b/shell/ev-page-action.h index d89a3d90..2908d345 100644 --- a/shell/ev-page-action.h +++ b/shell/ev-page-action.h @@ -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); diff --git a/shell/ev-window.c b/shell/ev-window.c index a4a6b6ec..19ad581b 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -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);