diff options
author | Yetizone <andreii.lisita@gmail.com> | 2020-02-21 21:09:37 +0200 |
---|---|---|
committer | Michael Catanzaro <mcatanzaro@gnome.org> | 2020-03-07 20:33:24 +0000 |
commit | 397bb580da7f9662bbc4c02d779edae36b68a395 (patch) | |
tree | 6580b00d7e16948aaab01893f496279c58d4dcce | |
parent | 86694e0b04433f478d53cb4b89989c14d37fddcd (diff) | |
download | epiphany-397bb580da7f9662bbc4c02d779edae36b68a395.tar.gz |
ephy-window: Add ephy_window_location_search()
Function focuses URL entry and sets the text to the default search engine bang
-rw-r--r-- | src/ephy-window.c | 30 | ||||
-rw-r--r-- | src/ephy-window.h | 1 |
2 files changed, 31 insertions, 0 deletions
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 }, @@ -3991,6 +3993,34 @@ ephy_window_activate_location (EphyWindow *window) } /** + * 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 * @zoom: the desired zoom level 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); |