[devhelp] Window: simplify implementation of win.find GAction
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] Window: simplify implementation of win.find GAction
- Date: Fri, 2 Feb 2018 21:02:08 +0000 (UTC)
commit 65178fb51bb339bfb70892e83322d684f1d7d292
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Feb 2 21:38:29 2018 +0100
Window: simplify implementation of win.find GAction
gtk_search_bar_set_search_mode() is now sufficient to trigger the
search.
Improve the function names, to make a bug more apparent: when switching
tab the search is not launched in the new tab.
src/dh-window.c | 59 +++++++++++++++++++++++++++----------------------------
1 files changed, 29 insertions(+), 30 deletions(-)
---
diff --git a/src/dh-window.c b/src/dh-window.c
index d4ce21f..1393d06 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -83,7 +83,6 @@ static void window_open_new_tab (DhWindow *window,
static void window_tab_set_title (DhWindow *window,
WebKitWebView *web_view,
const gchar *title);
-static void do_search (DhWindow *window);
#define TAB_WEB_VIEW_KEY "web_view"
#define TAB_INFO_BAR_KEY "info_bar"
@@ -334,12 +333,6 @@ find_cb (GSimpleAction *action,
gtk_search_bar_set_search_mode (priv->search_bar, TRUE);
gtk_widget_grab_focus (GTK_WIDGET (priv->search_entry));
-
- /* The behaviour for WebKit1 is to re-enable highlighting without
- * starting a new search. WebKit2 API does not allow that
- * without invoking a new search.
- */
- do_search (window);
}
static int
@@ -596,17 +589,32 @@ sidebar_link_selected_cb (DhSidebar *sidebar,
}
static void
-search_mode_enabled_notify_cb (GtkSearchBar *search_bar,
- GParamSpec *pspec,
- DhWindow *window)
+launch_search_in_active_web_view (DhWindow *window)
+{
+ DhWindowPrivate *priv = dh_window_get_instance_private (window);
+ WebKitWebView *view;
+ WebKitFindController *find_controller;
+ const gchar *search_text;
+
+ view = window_get_active_web_view (window);
+ find_controller = webkit_web_view_get_find_controller (view);
+
+ search_text = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
+
+ webkit_find_controller_search (find_controller,
+ search_text,
+ WEBKIT_FIND_OPTIONS_WRAP_AROUND |
+ WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE,
+ G_MAXUINT);
+}
+
+static void
+finish_search_in_all_web_views (DhWindow *window)
{
DhWindowPrivate *priv = dh_window_get_instance_private (window);
gint n_pages;
gint page_num;
- if (gtk_search_bar_get_search_mode (search_bar))
- return;
-
n_pages = gtk_notebook_get_n_pages (priv->notebook);
for (page_num = 0; page_num < n_pages; page_num++) {
@@ -623,30 +631,21 @@ search_mode_enabled_notify_cb (GtkSearchBar *search_bar,
}
static void
-do_search (DhWindow *window)
+search_mode_enabled_notify_cb (GtkSearchBar *search_bar,
+ GParamSpec *pspec,
+ DhWindow *window)
{
- DhWindowPrivate *priv = dh_window_get_instance_private (window);
- WebKitWebView *view;
- WebKitFindController *find_controller;
- const gchar *search_text;
-
- view = window_get_active_web_view (window);
- find_controller = webkit_web_view_get_find_controller (view);
-
- search_text = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
-
- webkit_find_controller_search (find_controller,
- search_text,
- WEBKIT_FIND_OPTIONS_WRAP_AROUND |
- WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE,
- G_MAXUINT);
+ if (gtk_search_bar_get_search_mode (search_bar))
+ launch_search_in_active_web_view (window);
+ else
+ finish_search_in_all_web_views (window);
}
static void
search_changed_cb (GtkEntry *entry,
DhWindow *window)
{
- do_search (window);
+ launch_search_in_active_web_view (window);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]