[geary/wip/geary-inspector: 10/10] Implement filtering log messages



commit 8b912d6367740b9b1d0e8314f6ce52b9f7a4402d
Author: Michael Gratton <mike vee net>
Date:   Sat Apr 6 20:20:58 2019 +1100

    Implement filtering log messages

 src/client/components/components-inspector.vala | 73 ++++++++++++++++++++-----
 ui/components-inspector.ui                      | 10 ++++
 2 files changed, 70 insertions(+), 13 deletions(-)
---
diff --git a/src/client/components/components-inspector.vala b/src/client/components/components-inspector.vala
index dc4bf0d0..8e8d9168 100644
--- a/src/client/components/components-inspector.vala
+++ b/src/client/components/components-inspector.vala
@@ -33,6 +33,9 @@ public class Components.Inspector : Gtk.Window {
     [GtkChild]
     private Hdy.SearchBar search_bar;
 
+    [GtkChild]
+    private Gtk.SearchEntry search_entry;
+
     [GtkChild]
     private Gtk.TreeView logs_view;
 
@@ -49,23 +52,17 @@ public class Components.Inspector : Gtk.Window {
             typeof(string)
     });
 
+    private Gtk.TreeModelFilter logs_filter;
+
+    private string[] logs_filter_terms = new string[0];
+
     private string details;
 
 
     public Inspector(GearyApplication app) {
         this.title = this.header_bar.title = _("Inspector");
 
-        // Log a marker for when the inspector was opened
-        debug("---- 8< ---- %s ---- 8< ----", this.header_bar.title);
-
-        Gtk.ListStore logs_store = this.logs_store;
-        Geary.Logging.LogRecord? logs = Geary.Logging.get_logs();
-        while (logs != null) {
-            Gtk.TreeIter iter;
-            logs_store.append(out iter);
-            logs_store.set_value(iter, COL_MESSAGE, logs.format());
-            logs = logs.get_next();
-        }
+        this.search_bar.connect_entry(this.search_entry);
 
         GLib.Settings system = app.config.gnome_interface;
         system.bind(
@@ -74,8 +71,6 @@ public class Components.Inspector : Gtk.Window {
             SettingsBindFlags.DEFAULT
         );
 
-        this.logs_view.set_model(logs_store);
-
         StringBuilder details = new StringBuilder();
         foreach (GearyApplication.RuntimeDetail? detail
                  in app.get_runtime_information()) {
@@ -85,6 +80,48 @@ public class Components.Inspector : Gtk.Window {
             details.append_printf("%s: %s\n", detail.name, detail.value);
         }
         this.details = details.str;
+
+        // Log a marker for when the inspector was opened
+        debug("---- 8< ---- %s ---- 8< ----", this.header_bar.title);
+
+        Gtk.ListStore logs_store = this.logs_store;
+        Geary.Logging.LogRecord? logs = Geary.Logging.get_logs();
+        while (logs != null) {
+            Gtk.TreeIter iter;
+            logs_store.append(out iter);
+            logs_store.set_value(iter, COL_MESSAGE, logs.format());
+            logs = logs.get_next();
+        }
+
+        this.logs_filter = new Gtk.TreeModelFilter(logs_store, null);
+        this.logs_filter.set_visible_func((model, iter) => {
+                bool ret = true;
+                if (this.logs_filter_terms.length > 0) {
+                    ret = false;
+                    Value value;
+                    model.get_value(iter, COL_MESSAGE, out value);
+                    string? message = (string) value;
+                    if (message != null) {
+                        foreach (string term in this.logs_filter_terms) {
+                            if (term in message) {
+                                ret = true;
+                                break;
+                            }
+                        }
+                    }
+                }
+                return ret;
+            });
+
+        this.logs_view.set_model(this.logs_filter);
+    }
+
+    public override bool key_press_event(Gdk.EventKey event) {
+        bool ret = this.search_bar.handle_event(event);
+        if (ret == Gdk.EVENT_PROPAGATE) {
+            ret = base.key_press_event(event);
+        }
+        return ret;
     }
 
     private async void save(string path,
@@ -129,6 +166,11 @@ public class Components.Inspector : Gtk.Window {
         this.search_button.set_visible(logs_visible);
     }
 
+    private void update_logs_filter() {
+        this.logs_filter_terms = this.search_entry.text.split(" ");
+        this.logs_filter.refilter();
+    }
+
     [GtkCallback]
     private void on_visible_child_changed() {
         update_ui();
@@ -202,6 +244,11 @@ public class Components.Inspector : Gtk.Window {
         update_ui();
     }
 
+    [GtkCallback]
+    private void on_logs_search_changed() {
+        update_logs_filter();
+    }
+
     [GtkCallback]
     private void on_destroy() {
         destroy();
diff --git a/ui/components-inspector.ui b/ui/components-inspector.ui
index 95824f0e..d62575b1 100644
--- a/ui/components-inspector.ui
+++ b/ui/components-inspector.ui
@@ -102,6 +102,16 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="hexpand">True</property>
+                <child>
+                  <object class="GtkSearchEntry" id="search_entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="primary_icon_name">edit-find-symbolic</property>
+                    <property name="primary_icon_activatable">False</property>
+                    <property name="primary_icon_sensitive">False</property>
+                    <signal name="search-changed" handler="on_logs_search_changed" swapped="no"/>
+                  </object>
+                </child>
               </object>
               <packing>
                 <property name="left_attach">0</property>


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