From 650cc839c740e53965758df75e629e90336bdd59 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 13 Nov 2017 09:01:55 -0500 Subject: MqFindToolbar: Show message when wrapping --- diff --git a/src/toolbars/find-toolbar.c b/src/toolbars/find-toolbar.c index a793b7c..42c2a9a 100644 --- a/src/toolbars/find-toolbar.c +++ b/src/toolbars/find-toolbar.c @@ -50,17 +50,20 @@ struct _MqFindToolbarClass { G_DEFINE_TYPE(MqFindToolbar, mq_find_toolbar, GTK_TYPE_REVEALER) static void -search(MqFindToolbar *find_toolbar, gboolean forward) +search(MqFindToolbar *find_toolbar, gboolean forward, gboolean wrap_around) { guint32 find_options; - find_options = WEBKIT_FIND_OPTIONS_WRAP_AROUND; + find_options = WEBKIT_FIND_OPTIONS_NONE; if (!find_toolbar->match_case) { find_options |= WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE; } if (!forward) { find_options |= WEBKIT_FIND_OPTIONS_BACKWARDS; } + if (wrap_around) { + find_options |= WEBKIT_FIND_OPTIONS_WRAP_AROUND; + } webkit_find_controller_search(find_toolbar->find_controller, gtk_entry_get_text(GTK_ENTRY(find_toolbar->search_entry)), find_options, G_MAXUINT); @@ -86,7 +89,7 @@ static void search_changed_cb(GtkSearchEntry G_GNUC_UNUSED *entry, MqFindToolbar *find_toolbar) { - search(find_toolbar, TRUE); + search(find_toolbar, TRUE, FALSE); } static gboolean @@ -101,7 +104,7 @@ search_key_press_event_cb(GtkSearchEntry G_GNUC_UNUSED *entry, case GDK_KEY_KP_Enter: case GDK_KEY_ISO_Enter: search(find_toolbar, - !(event->state & GDK_SHIFT_MASK)); + !(event->state & GDK_SHIFT_MASK), FALSE); return TRUE; default: return FALSE; @@ -111,13 +114,13 @@ search_key_press_event_cb(GtkSearchEntry G_GNUC_UNUSED *entry, static void prev_clicked_cb(GtkButton G_GNUC_UNUSED *button, MqFindToolbar *find_toolbar) { - search(find_toolbar, FALSE); + search(find_toolbar, FALSE, FALSE); } static void next_clicked_cb(GtkButton G_GNUC_UNUSED *button, MqFindToolbar *find_toolbar) { - search(find_toolbar, TRUE); + search(find_toolbar, TRUE, FALSE); } static void @@ -125,7 +128,7 @@ match_case_toggled_cb(GtkToggleButton *toggle_button, MqFindToolbar *find_toolbar) { find_toolbar->match_case = gtk_toggle_button_get_active(toggle_button); - search(find_toolbar, TRUE); + search(find_toolbar, TRUE, FALSE); } static void @@ -138,13 +141,39 @@ static void found_text_cb(WebKitFindController G_GNUC_UNUSED *find_controller, guint match_count, MqFindToolbar *find_toolbar) { - gchar *text; + gchar *text; + guint32 find_options; gtk_spinner_stop(find_toolbar->spinner); - if (match_count == 1) { - text = g_strdup("1 match"); + find_options = webkit_find_controller_get_options( + find_toolbar->find_controller); + + if (find_options & WEBKIT_FIND_OPTIONS_WRAP_AROUND) { + if (find_options & WEBKIT_FIND_OPTIONS_BACKWARDS) { + if (match_count == 1) { + text = g_strdup("1 match, " + "wrapped from top to bottom"); + } else { + text = g_strdup_printf("%u matches, " + "wrapped from top to bottom", + match_count); + } + } else { + if (match_count == 1) { + text = g_strdup("1 match, " + "wrapped from bottom to top"); + } else { + text = g_strdup_printf("%u matches, " + "wrapped from bottom to top", + match_count); + } + } } else { - text = g_strdup_printf("%u matches", match_count); + if (match_count == 1) { + text = g_strdup("1 match"); + } else { + text = g_strdup_printf("%u matches", match_count); + } } gtk_label_set_text(GTK_LABEL(find_toolbar->matches_label), text); g_free(text); @@ -154,9 +183,19 @@ static void failed_to_find_text_cb(WebKitFindController G_GNUC_UNUSED *find_controller, MqFindToolbar *find_toolbar) { - gtk_spinner_stop(find_toolbar->spinner); - gtk_label_set_text(GTK_LABEL(find_toolbar->matches_label), - "No matches"); + guint32 find_options; + + find_options = webkit_find_controller_get_options( + find_toolbar->find_controller); + + if (find_options & WEBKIT_FIND_OPTIONS_WRAP_AROUND) { + gtk_spinner_stop(find_toolbar->spinner); + gtk_label_set_text(GTK_LABEL(find_toolbar->matches_label), + "No matches"); + } else { + search(find_toolbar, + !(find_options & WEBKIT_FIND_OPTIONS_BACKWARDS), TRUE); + } } static void -- cgit v0.9.1