[nautilus/2094-search-button-doesn-t-focus-the-search-entry] query-editor: Stop using GtkSearchEntry




commit abe257d1a3e6358bdbd1e848a0fcb73b9dc5e47d
Author: António Fernandes <antoniof gnome org>
Date:   Thu Apr 21 09:25:28 2022 +0100

    query-editor: Stop using GtkSearchEntry
    
    It doesn't have a ::grab_focus_without_selecting() method, which is
    breaking keyboard focus expectations. Also, GtkSearchEntry is just
    a placeholder until we have a tagged search entry.
    
    Therefore, use GtkEntry and make it look and behave like a search
    entry would, except for the delayed "search-changed" signal. That's
    to be implemented later along with the tags anyway.
    
    Closes https://gitlab.gnome.org/GNOME/nautilus/-/issues/2094

 src/nautilus-query-editor.c | 53 +++++++++++++++++++++++++++++++++------------
 1 file changed, 39 insertions(+), 14 deletions(-)
---
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index 98d69f3b0..abb555a12 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -294,6 +294,10 @@ nautilus_query_editor_class_init (NautilusQueryEditorClass *class)
                                  gtk_signal_action_new ("focus-view"));
     gtk_widget_class_add_shortcut (widget_class, shortcut);
 
+    shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (GDK_KEY_Escape, 0),
+                                 gtk_signal_action_new ("cancel"));
+    gtk_widget_class_add_shortcut (widget_class, shortcut);
+
     /**
      * NautilusQueryEditor::location:
      *
@@ -373,6 +377,14 @@ static void
 entry_changed_cb (GtkWidget           *entry,
                   NautilusQueryEditor *editor)
 {
+    g_autofree gchar *text = NULL;
+
+    text = g_strdup (gtk_editable_get_text (GTK_EDITABLE (editor->entry)));
+
+    gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
+                                  GTK_ENTRY_ICON_SECONDARY,
+                                  (text != NULL && *text != '\0'));
+
     if (editor->change_frozen)
     {
         return;
@@ -384,9 +396,6 @@ entry_changed_cb (GtkWidget           *entry,
     }
     else
     {
-        g_autofree gchar *text = NULL;
-
-        text = g_strdup (gtk_editable_get_text (GTK_EDITABLE (editor->entry)));
         text = g_strstrip (text);
 
         nautilus_query_set_text (editor->query, text);
@@ -395,13 +404,6 @@ entry_changed_cb (GtkWidget           *entry,
     nautilus_query_editor_changed (editor);
 }
 
-static void
-nautilus_query_editor_on_stop_search (GtkWidget           *entry,
-                                      NautilusQueryEditor *editor)
-{
-    g_signal_emit (editor, signals[CANCEL], 0);
-}
-
 /* Type */
 
 static void
@@ -564,11 +566,23 @@ entry_tag_close_button_clicked (NautilusQueryEditor *editor,
 }
 #endif
 
+static void
+on_clear_icon_release (GtkEntry             *entry,
+                       GtkEntryIconPosition  icon_pos,
+                       gpointer              user_data)
+{
+    if (icon_pos == GTK_ENTRY_ICON_SECONDARY)
+    {
+        gtk_editable_set_text (GTK_EDITABLE (entry), "");
+    }
+}
+
 static void
 setup_widgets (NautilusQueryEditor *editor)
 {
     GtkWidget *hbox;
     GtkWidget *vbox;
+    GtkEntry *entry;
 
     /* vertical box that holds the search entry and the label below */
     vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
@@ -583,9 +597,22 @@ setup_widgets (NautilusQueryEditor *editor)
 #if 0 && TAGGED_ENTRY_NEEDS_GTK4_REIMPLEMENTATION
     editor->entry = GTK_WIDGET (gd_tagged_entry_new ());
 #else
-    editor->entry = gtk_search_entry_new ();
+    editor->entry = gtk_entry_new ();
+    entry = GTK_ENTRY (editor->entry);
 #endif
     gtk_widget_set_hexpand (editor->entry, TRUE);
+    gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_PRIMARY,
+                                       "system-search-symbolic");
+
+    gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY,
+                                       (gtk_widget_get_direction (editor->entry) == GTK_TEXT_DIR_RTL ?
+                                        "edit-clear-rtl-symbolic" :
+                                        "edit-clear-symbolic"));
+    gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY,
+                                     _("Clear search query"));
+    gtk_entry_set_icon_activatable (entry, GTK_ENTRY_ICON_SECONDARY, TRUE);
+    gtk_entry_set_icon_sensitive (entry, GTK_ENTRY_ICON_SECONDARY, FALSE);
+    g_signal_connect (entry, "icon-release", G_CALLBACK (on_clear_icon_release), NULL);
 
     gtk_box_append (GTK_BOX (hbox), editor->entry);
 
@@ -622,10 +649,8 @@ setup_widgets (NautilusQueryEditor *editor)
 
     g_signal_connect (editor->entry, "activate",
                       G_CALLBACK (entry_activate_cb), editor);
-    g_signal_connect (editor->entry, "search-changed",
+    g_signal_connect (editor->entry, "changed",
                       G_CALLBACK (entry_changed_cb), editor);
-    g_signal_connect (editor->entry, "stop-search",
-                      G_CALLBACK (nautilus_query_editor_on_stop_search), editor);
     g_signal_connect (editor->popover, "date-range",
                       G_CALLBACK (search_popover_date_range_changed_cb), editor);
     g_signal_connect (editor->popover, "mime-type",


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