From a048e46e0811c3812f43feaf77697488a78f988d Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 08 Oct 2017 02:56:22 -0400 Subject: MqTabChrome: Make find bar functional --- (limited to 'src') diff --git a/src/tab-chrome.c b/src/tab-chrome.c index 3133196..72b42ba 100644 --- a/src/tab-chrome.c +++ b/src/tab-chrome.c @@ -557,21 +557,68 @@ navigation_toolbar_new(MqTabChrome *chrome, const gchar *uri) } static void +find_search(MqTabChrome *chrome) +{ + guint32 find_options; + + find_options = WEBKIT_FIND_OPTIONS_WRAP_AROUND; + if (!chrome->find_match_case) { + find_options |= WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE; + } + webkit_find_controller_search(chrome->find_controller, + gtk_entry_get_text(GTK_ENTRY(chrome->find_search_entry)), + find_options, G_MAXUINT); + chrome->find_searching = TRUE; +} + +static void +find_search_finished(MqTabChrome *chrome) +{ + chrome->find_searching = FALSE; + webkit_find_controller_search_finish(chrome->find_controller); +} + +static void +find_search_changed_cb(GtkSearchEntry G_GNUC_UNUSED *entry, MqTabChrome *chrome) +{ + find_search(chrome); +} + +static void +find_search_activate_cb(GtkEntry G_GNUC_UNUSED *entry, MqTabChrome *chrome) +{ + find_search(chrome); +} + +static void find_prev_clicked_cb(GtkButton G_GNUC_UNUSED *button, MqTabChrome *chrome) { - /* FIXME: Unimplemented */ + /* Calling this method before webkit_find_controller_search() or + * webkit_find_controller_count_matches() is a programming error. */ + if (chrome->find_searching) { + webkit_find_controller_search_previous(chrome->find_controller); + } else { + find_search(chrome); + } } static void find_next_clicked_cb(GtkButton G_GNUC_UNUSED *button, MqTabChrome *chrome) { - /* FIXME: Unimplemented */ + /* Calling this method before webkit_find_controller_search() or + * webkit_find_controller_count_matches() is a programming error. */ + if (chrome->find_searching) { + webkit_find_controller_search_next(chrome->find_controller); + } else { + find_search(chrome); + } } static void -find_match_case_toggled_cb(GtkButton G_GNUC_UNUSED *button, MqTabChrome *chrome) +find_match_case_toggled_cb(GtkToggleButton *toggle_button, MqTabChrome *chrome) { - /* FIXME: Unimplemented */ + chrome->find_match_case = gtk_toggle_button_get_active(toggle_button); + find_search(chrome); } static void @@ -579,6 +626,7 @@ find_close_clicked_cb(GtkButton G_GNUC_UNUSED *button, MqTabChrome *chrome) { gtk_revealer_set_reveal_child(GTK_REVEALER(chrome->find_revealer), FALSE); + find_search_finished(chrome); } static GtkWidget * @@ -592,6 +640,10 @@ find_toolbar_new(MqTabChrome *chrome) /* Search entry */ chrome->find_search_entry = gtk_search_entry_new(); + g_signal_connect(chrome->find_search_entry, "search-changed", + G_CALLBACK(find_search_changed_cb), chrome); + g_signal_connect(chrome->find_search_entry, "activate", + G_CALLBACK(find_search_activate_cb), chrome); /* Previous button */ prev_button = gtk_button_new_from_icon_name("go-up", @@ -641,6 +693,9 @@ find_toolbar_new(MqTabChrome *chrome) GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN); gtk_container_add(GTK_CONTAINER(chrome->find_revealer), box); + chrome->find_match_case = FALSE; + chrome->find_searching = FALSE; + return chrome->find_revealer; } diff --git a/src/tab-chrome.h b/src/tab-chrome.h index 257bd8b..5cb1705 100644 --- a/src/tab-chrome.h +++ b/src/tab-chrome.h @@ -44,6 +44,8 @@ struct MqTabChrome { gchar *hovered_link_uri; GtkWidget *find_revealer; GtkWidget *find_search_entry; + gboolean find_match_case; + gboolean find_searching; WebKitWebView *web_view; WebKitFindController *find_controller; gboolean load_failed; -- cgit v0.9.1