[epiphany/gnome-3-32] history-dialog: Improve search UI



commit 91d0aaa4b2c38f3f5259275df04dfb9f61b90244
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Tue Feb 26 18:09:01 2019 +0000

    history-dialog: Improve search UI
    
    Add a search toggle button and allow "type-to-search".
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/632
    
    
    (cherry picked from commit 0bad9b81af183be5bc9c29493e13a40bdbd98a66)

 src/ephy-history-dialog.c           | 26 ++++++++++++++++++++++++++
 src/resources/gtk/history-dialog.ui | 23 +++++++++++++++++++++--
 2 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/src/ephy-history-dialog.c b/src/ephy-history-dialog.c
index 69bde6272..dbcae3d6c 100644
--- a/src/ephy-history-dialog.c
+++ b/src/ephy-history-dialog.c
@@ -34,6 +34,7 @@
 #include "ephy-time-helpers.h"
 #include "ephy-window.h"
 
+#include <ctype.h>
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 #include <string.h>
@@ -51,6 +52,8 @@ struct _EphyHistoryDialog {
   GtkWidget *listbox;
   GtkWidget *forget_all_button;
   GtkWidget *popup_menu;
+  GtkWidget *search_bar;
+  GtkWidget *search_button;
 
   GActionGroup *action_group;
 
@@ -516,6 +519,26 @@ on_search_entry_changed (GtkSearchEntry    *entry,
   filter_now (self);
 }
 
+static gboolean
+on_key_press_event (EphyHistoryDialog *self,
+                    GdkEvent          *event,
+                    gpointer           user_data)
+{
+  GdkEventKey *key = (GdkEventKey *)event;
+  gint ret;
+
+  ret = gtk_search_bar_handle_event (GTK_SEARCH_BAR (self->search_bar), event);
+
+  if (ret != GDK_EVENT_STOP) {
+    if (key->keyval == GDK_KEY_Escape)
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->search_button), FALSE);
+    else if (isprint (key->keyval))
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->search_button), TRUE);
+  }
+
+  return ret;
+}
+
 static void
 update_selection_actions (GActionGroup *action_group,
                           gboolean      has_selection)
@@ -745,11 +768,14 @@ ephy_history_dialog_class_init (EphyHistoryDialogClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, listbox);
   gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, forget_all_button);
   gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, popup_menu);
+  gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, search_bar);
+  gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, search_button);
 
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated);
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_selected);
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_button_press_event);
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_key_press_event);
+  gtk_widget_class_bind_template_callback (widget_class, on_key_press_event);
   gtk_widget_class_bind_template_callback (widget_class, on_search_entry_changed);
   gtk_widget_class_bind_template_callback (widget_class, on_edge_reached);
 }
diff --git a/src/resources/gtk/history-dialog.ui b/src/resources/gtk/history-dialog.ui
index 3c48b001c..bad7bed0d 100644
--- a/src/resources/gtk/history-dialog.ui
+++ b/src/resources/gtk/history-dialog.ui
@@ -3,6 +3,11 @@
 <interface>
   <requires lib="gtk+" version="3.20"/>
   <requires lib="libhandy" version="0.0"/>
+  <object class="GtkImage" id="image1">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="icon_name">edit-find-symbolic</property>
+  </object>
   <template class="EphyHistoryDialog" parent="GtkWindow">
     <property name="can_focus">False</property>
     <property name="modal">True</property>
@@ -11,6 +16,7 @@
     <property name="default_height">600</property>
     <property name="destroy_with_parent">True</property>
     <property name="type_hint">dialog</property>
+    <signal name="key-press-event" handler="on_key_press_event" swapped="no"/>
     <child type="titlebar">
       <object class="GtkHeaderBar">
         <property name="visible">True</property>
@@ -31,6 +37,19 @@
             </style>
           </object>
         </child>
+        <child>
+          <object class="GtkToggleButton" id="search_button">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="image">image1</property>
+            <property name="active" bind-source="search_bar" bind-property="search-mode-enabled" 
bind-flags="sync-create|bidirectional"/>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
       </object>
     </child>
     <child>
@@ -39,10 +58,10 @@
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <child>
-          <object class="GtkSearchBar">
+          <object class="GtkSearchBar" id="search_bar">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="search_mode_enabled">True</property>
+            <property name="search_mode_enabled">False</property>
             <child>
               <object class="GtkSearchEntry">
                 <property name="width_request">280</property>


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