+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:
#include <gtk/gtklabel.h>
#include <gtk/gtkhbox.h>
#include <string.h>
+#include <stdlib.h>
struct _EvPageActionPrivate
{
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));
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 *
}
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);