[gnome-logs] window: Use set_key_capture_widget in entry bar



commit c71055611a45bd83a69f386ebd6ffafed370f6dd
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Mon Oct 11 00:29:43 2021 +0200

    window: Use set_key_capture_widget in entry bar

 data/gl-window.ui      |  2 --
 src/gl-eventviewlist.c | 39 ++++++++++++++++-----------------------
 src/gl-eventviewlist.h |  3 ---
 src/gl-window.c        | 23 -----------------------
 4 files changed, 16 insertions(+), 51 deletions(-)
---
diff --git a/data/gl-window.ui b/data/gl-window.ui
index dd3e3fa..297eb88 100644
--- a/data/gl-window.ui
+++ b/data/gl-window.ui
@@ -3,8 +3,6 @@
     <template class="GlWindow" parent="AdwApplicationWindow">
         <property name="default-width">1200</property>
         <property name="default-height">600</property>
-        <!-- TODO -->
-        <!-- <signal name="key-press-event" handler="on_gl_window_key_press_event"/> -->
         <child>
             <object class="GtkBox" id="event_box">
                 <property name="orientation">vertical</property>
diff --git a/src/gl-eventviewlist.c b/src/gl-eventviewlist.c
index 0369756..7cd30da 100644
--- a/src/gl-eventviewlist.c
+++ b/src/gl-eventviewlist.c
@@ -414,29 +414,6 @@ gl_event_view_list_get_boot_ids (GlEventViewList *view)
     return gl_journal_model_get_boot_ids (priv->journal_model);
 }
 
-gboolean
-gl_event_view_list_handle_search_event (GlEventViewList *view,
-                                        GAction *action,
-                                        GdkEvent *event)
-{
-    GlEventViewListPrivate *priv;
-
-    priv = gl_event_view_list_get_instance_private (view);
-
-    if (g_action_get_enabled (action))
-    {
-        if (gtk_search_bar_handle_event (GTK_SEARCH_BAR (priv->event_search),
-                                         event) == GDK_EVENT_STOP)
-        {
-            g_action_change_state (action, g_variant_new_boolean (TRUE));
-
-            return GDK_EVENT_STOP;
-        }
-    }
-
-    return GDK_EVENT_PROPAGATE;
-}
-
 void
 gl_event_view_list_set_search_mode (GlEventViewList *view,
                                     gboolean state)
@@ -1017,6 +994,21 @@ gl_event_view_list_finalize (GObject *object)
     G_OBJECT_CLASS (gl_event_view_list_parent_class)->finalize (object);
 }
 
+static void
+gl_event_view_list_realize (GtkWidget *widget)
+{
+    GlEventViewList *view = GL_EVENT_VIEW_LIST (widget);
+    GlEventViewListPrivate *priv = gl_event_view_list_get_instance_private (view);
+    GtkRoot *root;
+
+    GTK_WIDGET_CLASS (gl_event_view_list_parent_class)->realize (widget);
+
+    root = gtk_widget_get_root (widget);
+
+    gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (priv->event_search),
+                                           GTK_WIDGET (root));
+}
+
 static void
 gl_event_view_list_class_init (GlEventViewListClass *klass)
 {
@@ -1024,6 +1016,7 @@ gl_event_view_list_class_init (GlEventViewListClass *klass)
     GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
     gobject_class->finalize = gl_event_view_list_finalize;
+    widget_class->realize = gl_event_view_list_realize;
 
     gtk_widget_class_set_template_from_resource (widget_class,
                                                  "/org/gnome/Logs/gl-eventviewlist.ui");
diff --git a/src/gl-eventviewlist.h b/src/gl-eventviewlist.h
index e0ad0c8..53bfdab 100644
--- a/src/gl-eventviewlist.h
+++ b/src/gl-eventviewlist.h
@@ -32,9 +32,6 @@ G_DECLARE_FINAL_TYPE (GlEventViewList, gl_event_view_list, GL, EVENT_VIEW_LIST,
 
 GtkWidget * gl_event_view_list_new (void);
 GlRowEntry *gl_event_view_list_get_detail_entry (GlEventViewList *view);
-gboolean gl_event_view_list_handle_search_event (GlEventViewList *view,
-                                                 GAction *action,
-                                                 GdkEvent *event);
 void gl_event_view_list_set_search_mode (GlEventViewList *view, gboolean state);
 void gl_event_view_list_set_sort_order (GlEventViewList *view, GlSortOrder  sort_order);
 void gl_event_view_list_view_boot (GlEventViewList *view, const gchar *match);
diff --git a/src/gl-window.c b/src/gl-window.c
index 8bbbbd4..3227bc8 100644
--- a/src/gl-window.c
+++ b/src/gl-window.c
@@ -256,27 +256,6 @@ on_category_list_changed (GlCategoryList *list,
     g_free (current_boot);
 }
 
-static gboolean
-on_gl_window_key_press_event (GlWindow *window,
-                              GdkEvent *event,
-                              gpointer user_data)
-{
-    GlWindowPrivate *priv;
-    GlEventViewList *event_list;
-    GAction *action;
-
-    priv = gl_window_get_instance_private (window);
-    action = g_action_map_lookup_action (G_ACTION_MAP (window), "search");
-    event_list = GL_EVENT_VIEW_LIST (priv->event_list);
-
-    if (gl_event_view_list_handle_search_event (event_list, action, event) == GDK_EVENT_STOP)
-    {
-        return GDK_EVENT_STOP;
-    }
-
-    return GDK_EVENT_PROPAGATE;
-}
-
 static void
 on_help_button_clicked (GlWindow *window,
                         gint response_id,
@@ -355,8 +334,6 @@ gl_window_class_init (GlWindowClass *klass)
     gtk_widget_class_bind_template_child_private (widget_class, GlWindow,
                                                   info_bar);
 
-    gtk_widget_class_bind_template_callback (widget_class,
-                                             on_gl_window_key_press_event);
     gtk_widget_class_bind_template_callback (widget_class,
                                              on_help_button_clicked);
     gtk_widget_class_bind_template_callback (widget_class,


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