[gnome-text-editor] searchbar: hide after performing search movement
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] searchbar: hide after performing search movement
- Date: Wed, 30 Jun 2021 20:05:02 +0000 (UTC)
commit ea558ae0b981d941c557a432423bd308487efaaa
Author: Christian Hergert <chergert redhat com>
Date: Wed Jun 30 13:04:57 2021 -0700
searchbar: hide after performing search movement
src/editor-page-actions.c | 2 +-
src/editor-page.c | 4 ++--
src/editor-search-bar-private.h | 6 ++++--
src/editor-search-bar.c | 37 +++++++++++++++++++++++--------------
4 files changed, 30 insertions(+), 19 deletions(-)
---
diff --git a/src/editor-page-actions.c b/src/editor-page-actions.c
index 930ec0f..ca88d63 100644
--- a/src/editor-page-actions.c
+++ b/src/editor-page-actions.c
@@ -90,7 +90,7 @@ editor_page_actions_replace_one (GtkWidget *widget,
{
_editor_search_bar_replace (self->search_bar);
_editor_page_scroll_to_insert (self);
- _editor_search_bar_move_next (self->search_bar);
+ _editor_search_bar_move_next (self->search_bar, FALSE);
}
}
diff --git a/src/editor-page.c b/src/editor-page.c
index 3b43357..066c63b 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -1090,7 +1090,7 @@ _editor_page_move_next_search (EditorPage *self)
{
g_return_if_fail (EDITOR_IS_PAGE (self));
- _editor_search_bar_move_next (self->search_bar);
+ _editor_search_bar_move_next (self->search_bar, FALSE);
}
void
@@ -1098,7 +1098,7 @@ _editor_page_move_previous_search (EditorPage *self)
{
g_return_if_fail (EDITOR_IS_PAGE (self));
- _editor_search_bar_move_previous (self->search_bar);
+ _editor_search_bar_move_previous (self->search_bar, FALSE);
}
static void
diff --git a/src/editor-search-bar-private.h b/src/editor-search-bar-private.h
index c467e07..047a5b7 100644
--- a/src/editor-search-bar-private.h
+++ b/src/editor-search-bar-private.h
@@ -39,8 +39,10 @@ void _editor_search_bar_attach (EditorSearchBar *self,
void _editor_search_bar_detach (EditorSearchBar *self);
void _editor_search_bar_set_mode (EditorSearchBar *self,
EditorSearchBarMode mode);
-void _editor_search_bar_move_next (EditorSearchBar *self);
-void _editor_search_bar_move_previous (EditorSearchBar *self);
+void _editor_search_bar_move_next (EditorSearchBar *self,
+ gboolean hide_after_move);
+void _editor_search_bar_move_previous (EditorSearchBar *self,
+ gboolean hide_after_move);
gboolean _editor_search_bar_get_can_move (EditorSearchBar *self);
gboolean _editor_search_bar_get_can_replace (EditorSearchBar *self);
gboolean _editor_search_bar_get_can_replace_all (EditorSearchBar *self);
diff --git a/src/editor-search-bar.c b/src/editor-search-bar.c
index 55b74dd..a3af994 100644
--- a/src/editor-search-bar.c
+++ b/src/editor-search-bar.c
@@ -50,6 +50,7 @@ struct _EditorSearchBar
guint can_move : 1;
guint can_replace : 1;
guint can_replace_all : 1;
+ guint hide_after_move : 1;
};
G_DEFINE_TYPE (EditorSearchBar, editor_search_bar, GTK_TYPE_WIDGET)
@@ -117,8 +118,7 @@ editor_search_bar_search_activate_cb (EditorSearchBar *self,
g_assert (EDITOR_IS_SEARCH_BAR (self));
g_assert (GTK_IS_ENTRY (entry));
- _editor_search_bar_move_next (self);
- gtk_widget_activate_action (GTK_WIDGET (self), "search.hide", NULL);
+ _editor_search_bar_move_next (self, TRUE);
}
static void
@@ -148,10 +148,14 @@ editor_search_bar_move_next_forward_cb (GObject *object,
buffer = gtk_source_search_context_get_buffer (context);
gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &begin, &end);
editor_search_bar_scroll_to_insert (self);
+
+ if (self->hide_after_move)
+ gtk_widget_activate_action (GTK_WIDGET (self), "search.hide", NULL);
}
void
-_editor_search_bar_move_next (EditorSearchBar *self)
+_editor_search_bar_move_next (EditorSearchBar *self,
+ gboolean hide_after_move)
{
GtkSourceBuffer *buffer;
GtkTextIter begin;
@@ -162,6 +166,8 @@ _editor_search_bar_move_next (EditorSearchBar *self)
if (self->context == NULL)
return;
+ self->hide_after_move = !!hide_after_move;
+
buffer = gtk_source_search_context_get_buffer (self->context);
gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &begin, &end);
gtk_text_iter_order (&begin, &end);
@@ -174,7 +180,8 @@ _editor_search_bar_move_next (EditorSearchBar *self)
}
void
-_editor_search_bar_move_previous (EditorSearchBar *self)
+_editor_search_bar_move_previous (EditorSearchBar *self,
+ gboolean hide_after_move)
{
GtkSourceBuffer *buffer;
GtkTextIter begin;
@@ -185,6 +192,8 @@ _editor_search_bar_move_previous (EditorSearchBar *self)
if (self->context == NULL)
return;
+ self->hide_after_move = !!hide_after_move;
+
buffer = gtk_source_search_context_get_buffer (self->context);
gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &begin, &end);
gtk_text_iter_order (&begin, &end);
@@ -391,7 +400,7 @@ editor_search_bar_class_init (EditorSearchBarClass *klass)
G_CALLBACK (_editor_search_bar_move_next),
NULL, NULL,
NULL,
- G_TYPE_NONE, 0);
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
signals [MOVE_PREVIOUS_SEARCH] =
g_signal_new_class_handler ("move-previous-search",
@@ -400,7 +409,7 @@ editor_search_bar_class_init (EditorSearchBarClass *klass)
G_CALLBACK (_editor_search_bar_move_previous),
NULL, NULL,
NULL,
- G_TYPE_NONE, 0);
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
signals [HIDE_SEARCH] =
g_signal_new_class_handler ("hide-search",
@@ -412,14 +421,14 @@ editor_search_bar_class_init (EditorSearchBarClass *klass)
G_TYPE_NONE, 0);
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "search.hide", NULL);
- gtk_widget_class_add_binding_action (widget_class, GDK_KEY_g, GDK_CONTROL_MASK|GDK_SHIFT_MASK,
"search.move-previous-search", 0);
- gtk_widget_class_add_binding_action (widget_class, GDK_KEY_g, GDK_CONTROL_MASK, "search.move-next-search",
0);
- gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Down, 0, "search.move-next-search", 0);
- gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Up, 0, "search.move-previous-search", 0);
- gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, 0, "search.move-next-search", 0);
- gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Enter, 0, "search.move-next-search", 0);
- gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, GDK_SHIFT_MASK,
"search.move-previous-search", 0);
- gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Enter, GDK_SHIFT_MASK,
"search.move-previous-search", 0);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_g, GDK_CONTROL_MASK|GDK_SHIFT_MASK,
"search.move-previous-search", NULL);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_g, GDK_CONTROL_MASK, "search.move-next-search",
NULL);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Down, 0, "search.move-next-search", NULL);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Up, 0, "search.move-previous-search", NULL);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, 0, "search.move-next-search", NULL);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Enter, 0, "search.move-next-search", NULL);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, GDK_SHIFT_MASK,
"search.move-previous-search", NULL);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Enter, GDK_SHIFT_MASK,
"search.move-previous-search", NULL);
properties [PROP_MODE] =
g_param_spec_enum ("mode",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]