[gtranslator: 1/2] <c-f> now focuses on search entry if already shown
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator: 1/2] <c-f> now focuses on search entry if already shown
- Date: Mon, 4 Apr 2022 18:10:44 +0000 (UTC)
commit 3ab20db19e744cfc1857984084cf7757390c0e75
Author: Amrit Borah <elessar1802 gmail com>
Date: Mon Apr 4 18:10:43 2022 +0000
<c-f> now focuses on search entry if already shown
src/gtr-application.c | 8 ++++----
src/gtr-search-bar.c | 6 ++++++
src/gtr-tab.c | 14 ++++++++++++++
src/gtr-tab.h | 1 +
src/gtr-window.c | 15 +++++++++++++++
src/gtr-window.h | 2 +-
6 files changed, 41 insertions(+), 5 deletions(-)
---
diff --git a/src/gtr-application.c b/src/gtr-application.c
index 86470895..2d7aeb3b 100644
--- a/src/gtr-application.c
+++ b/src/gtr-application.c
@@ -263,7 +263,7 @@ find_activated (GSimpleAction *action,
GtrTab *active_tab = gtr_window_get_active_tab (priv->active_window);
g_return_if_fail (active_tab != NULL);
- gtr_window_show_search_bar (priv->active_window, TRUE);
+ gtr_window_show_focus_search_bar (priv->active_window, TRUE);
gtr_tab_find_set_replace (active_tab, FALSE);
}
@@ -277,7 +277,7 @@ find_next_activated (GSimpleAction *action,
GtrTab *active_tab = gtr_window_get_active_tab (priv->active_window);
g_return_if_fail (active_tab != NULL);
- gtr_window_show_search_bar (priv->active_window, TRUE);
+ gtr_window_show_focus_search_bar (priv->active_window, TRUE);
gtr_tab_find_next (active_tab);
}
@@ -291,7 +291,7 @@ find_prev_activated (GSimpleAction *action,
GtrTab *active_tab = gtr_window_get_active_tab (priv->active_window);
g_return_if_fail (active_tab != NULL);
- gtr_window_show_search_bar (priv->active_window, TRUE);
+ gtr_window_show_focus_search_bar (priv->active_window, TRUE);
gtr_tab_find_prev (active_tab);
}
@@ -304,7 +304,7 @@ find_and_replace_activated (GSimpleAction *action,
GtrApplicationPrivate *priv = gtr_application_get_instance_private (app);
GtrTab *active_tab = gtr_window_get_active_tab (priv->active_window);
- gtr_window_show_search_bar (priv->active_window, TRUE);
+ gtr_window_show_focus_search_bar (priv->active_window, TRUE);
gtr_tab_find_set_replace (active_tab, TRUE);
}
diff --git a/src/gtr-search-bar.c b/src/gtr-search-bar.c
index a5231b48..6b34ec48 100644
--- a/src/gtr-search-bar.c
+++ b/src/gtr-search-bar.c
@@ -742,3 +742,9 @@ gtr_search_bar_set_found (GtrSearchBar *self,
gtk_style_context_add_class (context, "error");
}
+/* Previously, declared but unimplemented */
+GtkSearchEntry *
+gtr_search_bar_get_search (GtrSearchBar *self)
+{
+ return (GtkSearchEntry *) self->search_entry;
+}
\ No newline at end of file
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index 6b23a202..93b9059b 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -168,6 +168,20 @@ gtr_page_stop_search (GtrTab *tab,
}
+void
+gtr_tab_focus_search_bar (GtrTab *tab)
+{
+ GtrTabPrivate *priv;
+ GtkEntry *entry;
+
+ g_assert (GTR_IS_TAB (tab));
+ priv = gtr_tab_get_instance_private (tab);
+
+ entry = (GtkEntry *) gtr_search_bar_get_search (priv->search_bar);
+
+ gtk_entry_grab_focus_without_selecting (entry);
+}
+
void
gtr_tab_show_hide_search_bar (GtrTab *tab, gboolean show)
{
diff --git a/src/gtr-tab.h b/src/gtr-tab.h
index 57c7e8e4..3f71c49a 100644
--- a/src/gtr-tab.h
+++ b/src/gtr-tab.h
@@ -162,6 +162,7 @@ void gtr_tab_sort_by (GtrTab *tab, GtrMessageTableSortBy sort);
void gtr_tab_find_replace (GtrTab *tab, gboolean set);
+void gtr_tab_focus_search_bar (GtrTab *tab);
void gtr_tab_show_hide_search_bar (GtrTab * tab, gboolean show);
void gtr_tab_find_next (GtrTab * tab);
void gtr_tab_find_prev (GtrTab * tab);
diff --git a/src/gtr-window.c b/src/gtr-window.c
index e3aea6f5..954955d2 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -929,6 +929,21 @@ gtr_window_show_search_bar (GtrWindow *window,
priv->search_bar_shown = show;
}
+// Shortcut for find now calls this
+void
+gtr_window_show_focus_search_bar (GtrWindow *window,
+ gboolean show)
+{
+ GtrWindowPrivate *priv = gtr_window_get_instance_private (window);
+ GtrTab *tab = gtr_window_get_active_tab (window);
+
+ // don't need to show if already shown but need to focus on entry
+ if (tab != NULL && priv->search_bar_shown == show)
+ gtr_tab_focus_search_bar (tab);
+ else
+ gtr_window_show_search_bar (window, show);
+}
+
void
gtr_window_toggle_search_bar (GtrWindow *window)
{
diff --git a/src/gtr-window.h b/src/gtr-window.h
index 36efb4de..d40517f8 100644
--- a/src/gtr-window.h
+++ b/src/gtr-window.h
@@ -80,7 +80,7 @@ void gtr_window_tm_keybind (GtrWindow *window, GSimpleAction *action);
void gtr_window_hide_sort_menu (GtrWindow *window);
-void gtr_window_show_search_bar (GtrWindow *window, gboolean show);
+void gtr_window_show_focus_search_bar (GtrWindow *window, gboolean show);
void gtr_window_toggle_search_bar (GtrWindow *window);
/** stack app states **/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]