[devhelp] SearchBar: Grab search bar search entry on ctrl-f



commit 3f2738a990ba58c0a1a075c4df808ed88094ebda
Author: Ayman Bagabas <ayman bagabas gmail com>
Date:   Wed Dec 18 18:42:38 2019 -0500

    SearchBar: Grab search bar search entry on ctrl-f
    
    Implement dh_search_bar_grab_focus_to_search_entry to grab the focus and
    selects the text in search_entry.
    Call this every time we get a ctrl-f event.
    Add function to docs.
    
    Fixes https://gitlab.gnome.org/GNOME/devhelp/issues/6

 devhelp/dh-search-bar.c             | 15 +++++++++++++++
 devhelp/dh-search-bar.h             |  8 +++++---
 docs/reference/devhelp-sections.txt |  1 +
 src/dh-window.c                     |  1 +
 4 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/devhelp/dh-search-bar.c b/devhelp/dh-search-bar.c
index 872dff8a..639dff22 100644
--- a/devhelp/dh-search-bar.c
+++ b/devhelp/dh-search-bar.c
@@ -364,3 +364,18 @@ dh_search_bar_get_notebook (DhSearchBar *search_bar)
 
         return search_bar->priv->notebook;
 }
+
+/**
+ * dh_search_bar_grab_focus_to_search_entry:
+ * @search_bar: a #DhSearchBar.
+ *
+ * Grabs the focus of #DhSearchBar search entry and selects its text
+ */
+void
+dh_search_bar_grab_focus_to_search_entry (DhSearchBar *search_bar)
+{
+        g_return_if_fail (DH_IS_SEARCH_BAR (search_bar));
+
+        gtk_widget_grab_focus (GTK_WIDGET (search_bar->priv->search_entry));
+        gtk_editable_select_region (GTK_EDITABLE (search_bar->priv->search_entry), 0, -1);
+}
diff --git a/devhelp/dh-search-bar.h b/devhelp/dh-search-bar.h
index 72f2cd7c..bb4b107f 100644
--- a/devhelp/dh-search-bar.h
+++ b/devhelp/dh-search-bar.h
@@ -50,11 +50,13 @@ struct _DhSearchBarClass {
         gpointer padding[12];
 };
 
-GType           dh_search_bar_get_type          (void);
+GType           dh_search_bar_get_type                   (void);
 
-DhSearchBar *   dh_search_bar_new               (DhNotebook *notebook);
+DhSearchBar *   dh_search_bar_new                        (DhNotebook *notebook);
 
-DhNotebook *    dh_search_bar_get_notebook      (DhSearchBar *search_bar);
+DhNotebook *    dh_search_bar_get_notebook               (DhSearchBar *search_bar);
+
+void            dh_search_bar_grab_focus_to_search_entry (DhSearchBar *search_bar);
 
 G_END_DECLS
 
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index dc5e8475..6e63adf8 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -271,6 +271,7 @@ dh_profile_builder_get_type
 DhSearchBar
 dh_search_bar_new
 dh_search_bar_get_notebook
+dh_search_bar_grab_focus_to_search_entry
 <SUBSECTION Standard>
 DH_IS_SEARCH_BAR
 DH_IS_SEARCH_BAR_CLASS
diff --git a/src/dh-window.c b/src/dh-window.c
index 64c91f18..d1b22b32 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -290,6 +290,7 @@ find_cb (GSimpleAction *action,
         DhWindowPrivate *priv = dh_window_get_instance_private (window);
 
         gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->search_bar), TRUE);
+        dh_search_bar_grab_focus_to_search_entry (priv->search_bar);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]