From 66b94a7112f6379b0e30ad7a8917ab146e374a20 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 08 Oct 2017 03:38:23 -0400 Subject: MqTabChrome: Add match count label to find bar --- (limited to 'src') diff --git a/src/tab-chrome.c b/src/tab-chrome.c index e9f5cc7..39efff7 100644 --- a/src/tab-chrome.c +++ b/src/tab-chrome.c @@ -586,6 +586,7 @@ find_close(MqTabChrome *chrome) { gtk_revealer_set_reveal_child(GTK_REVEALER(chrome->find_revealer), FALSE); + gtk_label_set_text(GTK_LABEL(chrome->find_matches_label), NULL); find_search_finished(chrome); } @@ -690,6 +691,9 @@ find_toolbar_new(MqTabChrome *chrome) g_signal_connect(match_case_button, "toggled", G_CALLBACK(find_match_case_toggled_cb), chrome); + /* Matches label */ + chrome->find_matches_label = gtk_label_new(NULL); + /* Close button */ close_button = gtk_button_new_from_icon_name("window-close", GTK_ICON_SIZE_BUTTON); @@ -706,6 +710,8 @@ find_toolbar_new(MqTabChrome *chrome) gtk_box_pack_start(GTK_BOX(box), prev_button, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(box), next_button, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(box), match_case_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(box), chrome->find_matches_label, + FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(box), close_button, FALSE, FALSE, 0); /* Revealer */ @@ -925,6 +931,29 @@ back_forward_list_changed_cb( } static void +find_found_text_cb(WebKitFindController G_GNUC_UNUSED *find_controller, + guint match_count, MqTabChrome *chrome) +{ + gchar *text; + + if (match_count == 1) { + text = g_strdup("1 match"); + } else { + text = g_strdup_printf("%u matches", match_count); + } + gtk_label_set_text(GTK_LABEL(chrome->find_matches_label), text); + g_free(text); + +} + +static void +find_failed_to_find_text_cb(WebKitFindController G_GNUC_UNUSED *find_controller, + MqTabChrome *chrome) +{ + gtk_label_set_text(GTK_LABEL(chrome->find_matches_label), "No matches"); +} + +static void connect_web_view(MqTabChrome *chrome) { chrome->hovered_link_uri = NULL; @@ -944,6 +973,11 @@ connect_web_view(MqTabChrome *chrome) g_signal_connect( webkit_web_view_get_back_forward_list(chrome->web_view), "changed", G_CALLBACK(back_forward_list_changed_cb), chrome); + + g_signal_connect(chrome->find_controller, "found-text", + G_CALLBACK(find_found_text_cb), chrome); + g_signal_connect(chrome->find_controller, "failed-to-find-text", + G_CALLBACK(find_failed_to_find_text_cb), chrome); } void diff --git a/src/tab-chrome.h b/src/tab-chrome.h index 5cb1705..f3bf883 100644 --- a/src/tab-chrome.h +++ b/src/tab-chrome.h @@ -44,6 +44,7 @@ struct MqTabChrome { gchar *hovered_link_uri; GtkWidget *find_revealer; GtkWidget *find_search_entry; + GtkWidget *find_matches_label; gboolean find_match_case; gboolean find_searching; WebKitWebView *web_view; -- cgit v0.9.1