[epiphany] ephy-window: Add ephy_window_location_search()



commit 397bb580da7f9662bbc4c02d779edae36b68a395
Author: Yetizone <andreii lisita gmail com>
Date:   Fri Feb 21 21:09:37 2020 +0200

    ephy-window: Add ephy_window_location_search()
    
    Function focuses URL entry and sets the text to the default search engine bang

 src/ephy-window.c | 30 ++++++++++++++++++++++++++++++
 src/ephy-window.h |  1 +
 2 files changed, 31 insertions(+)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 6a1c0a434..c7643f2d6 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -110,6 +110,7 @@ const struct {
 
   { "win.send-to", { "Send", NULL } },
   { "win.location", { "<Primary>L", "<alt>D", "F6", "Go", "OpenURL", NULL } },
+  { "win.location-search", {"<Primary>K", NULL} },
   { "win.home", { "<alt>Home", NULL } },
   { "win.content", { "Escape", NULL } },
 
@@ -845,6 +846,7 @@ static const GActionEntry window_entries [] = {
 
   { "send-to", window_cmd_send_to },
   { "location", window_cmd_go_location },
+  { "location-search", window_cmd_location_search },
   { "home", window_cmd_go_home },
   { "content", window_cmd_go_content },
   { "tabs-view", window_cmd_go_tabs_view },
@@ -3990,6 +3992,34 @@ ephy_window_activate_location (EphyWindow *window)
     ephy_location_entry_focus (EPHY_LOCATION_ENTRY (title_widget));
 }
 
+/**
+ * ephy_window_location_search:
+ * @window: an #EphyWindow
+ *
+ * Focuses the location entry on @window's header bar
+ * and sets the text to the default search engine's bang.
+ **/
+void
+ephy_window_location_search (EphyWindow *window)
+{
+  EphyTitleWidget *title_widget = ephy_header_bar_get_title_widget (EPHY_HEADER_BAR (window->header_bar));
+  EphyLocationEntry *location_entry = EPHY_LOCATION_ENTRY (title_widget);
+  GtkEntry *location_gtk_entry = GTK_ENTRY (ephy_location_entry_get_entry (location_entry));
+  GtkApplication *gtk_application = gtk_window_get_application (GTK_WINDOW (window));
+  EphyEmbedShell *embed_shell = EPHY_EMBED_SHELL (gtk_application);
+  EphySearchEngineManager *search_engine_manager = ephy_embed_shell_get_search_engine_manager (embed_shell);
+  char *search_engine_name = ephy_search_engine_manager_get_default_engine (search_engine_manager);
+  const char *search_engine_bang = ephy_search_engine_manager_get_bang (search_engine_manager, 
search_engine_name);
+  char *entry_text = g_strconcat (search_engine_bang, " ", NULL);
+
+  gtk_window_set_focus (GTK_WINDOW (window), GTK_WIDGET (location_gtk_entry));
+  gtk_entry_set_text (location_gtk_entry, entry_text);
+  gtk_editable_set_position (GTK_EDITABLE (location_gtk_entry), strlen (entry_text));
+
+  g_free (entry_text);
+  g_free (search_engine_name);
+}
+
 /**
  * ephy_window_set_zoom:
  * @window: an #EphyWindow
diff --git a/src/ephy-window.h b/src/ephy-window.h
index 3e92c7f94..81d68df9a 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -56,6 +56,7 @@ void              ephy_window_set_zoom            (EphyWindow *window,
                                                    double zoom);
 
 void              ephy_window_activate_location   (EphyWindow *window);
+void              ephy_window_location_search     (EphyWindow *window);
 const char       *ephy_window_get_location        (EphyWindow *window);
 
 GtkWidget        *ephy_window_get_header_bar      (EphyWindow *window);


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