mirror of
https://gitlab.gnome.org/GNOME/evince
synced 2024-06-28 13:44:46 +00:00
Activate search-outline mode from text entry
Right now the search-outline mode can only be activated through the context menu action. Some people miss the more practical way of entering some text and have it search the Outline, that's what this MR implements, with the exception when the entered text is just a number or a roman numeral, in that case we go directly to that page (as expected). Fixes #1991
This commit is contained in:
parent
9556bcb939
commit
54ac4dd903
|
@ -171,6 +171,46 @@ page_scroll_cb (EvPageActionWidget *action_widget, GdkEventScroll *event)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
is_roman (const char s)
|
||||
{
|
||||
return s == 'l' || s == 'L' ||
|
||||
s == 'x' || s == 'X' ||
|
||||
s == 'v' || s == 'V' ||
|
||||
s == 'i' || s == 'I';
|
||||
}
|
||||
|
||||
/* Returns TRUE if the passed string is a number [0-9] or
|
||||
* a roman numeral i.e. only have these characters [lxvi] .
|
||||
* Returns FALSE otherwise. */
|
||||
static gboolean
|
||||
is_roman_numeral_or_number (const char *text)
|
||||
{
|
||||
gboolean look_for_roman;
|
||||
gboolean look_for_digits;
|
||||
char *s;
|
||||
|
||||
s = (char *) text;
|
||||
g_strstrip (s);
|
||||
|
||||
look_for_digits = g_ascii_isdigit (*s);
|
||||
look_for_roman = look_for_digits ? FALSE : is_roman (*s);
|
||||
|
||||
if (!look_for_digits && !look_for_roman)
|
||||
return FALSE;
|
||||
|
||||
s++;
|
||||
while (*s != 0) {
|
||||
if (look_for_digits && !g_ascii_isdigit (*s))
|
||||
return FALSE;
|
||||
if (look_for_roman && !is_roman (*s))
|
||||
return FALSE;
|
||||
s++;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
activate_cb (EvPageActionWidget *action_widget)
|
||||
{
|
||||
|
@ -182,6 +222,7 @@ activate_cb (EvPageActionWidget *action_widget)
|
|||
gchar *link_text;
|
||||
gchar *new_text;
|
||||
gint current_page;
|
||||
gboolean has_sidebar_links;
|
||||
|
||||
model = action_widget->doc_model;
|
||||
current_page = ev_document_model_get_page (model);
|
||||
|
@ -197,6 +238,17 @@ activate_cb (EvPageActionWidget *action_widget)
|
|||
g_free (new_text);
|
||||
}
|
||||
|
||||
has_sidebar_links = EV_IS_DOCUMENT_LINKS (action_widget->document) &&
|
||||
ev_document_links_has_document_links (EV_DOCUMENT_LINKS (action_widget->document));
|
||||
|
||||
if (has_sidebar_links && !is_roman_numeral_or_number (text)) {
|
||||
/* Change to search-outline mode */
|
||||
ev_page_action_widget_set_temporary_entry_width (action_widget, 15);
|
||||
ev_page_action_widget_enable_completion_search (action_widget, TRUE);
|
||||
g_signal_emit_by_name (GTK_EDITABLE (action_widget->entry), "changed", NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
link_dest = ev_link_dest_new_page_label (text);
|
||||
link_action = ev_link_action_new_dest (link_dest);
|
||||
link_text = g_strdup_printf (_("Page %s"), text);
|
||||
|
|
Loading…
Reference in New Issue
Block a user