Implement filtering log messages

This commit is contained in:
Michael Gratton 2019-04-06 20:20:58 +11:00 committed by Michael James Gratton
parent b5f27dce79
commit e5893e1d66
2 changed files with 72 additions and 15 deletions

View file

@ -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,12 +52,35 @@ 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");
this.search_bar.connect_entry(this.search_entry);
GLib.Settings system = app.config.gnome_interface;
system.bind(
"monospace-font-name",
this.log_renderer, "font",
SettingsBindFlags.DEFAULT
);
StringBuilder details = new StringBuilder();
foreach (GearyApplication.RuntimeDetail? detail
in app.get_runtime_information()) {
this.detail_list.add(
new DetailRow("%s:".printf(detail.name), detail.value)
);
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);
@ -67,24 +93,35 @@ public class Components.Inspector : Gtk.Window {
logs = logs.get_next();
}
GLib.Settings system = app.config.gnome_interface;
system.bind(
"monospace-font-name",
this.log_renderer, "font",
SettingsBindFlags.DEFAULT
);
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(logs_store);
this.logs_view.set_model(this.logs_filter);
}
StringBuilder details = new StringBuilder();
foreach (GearyApplication.RuntimeDetail? detail
in app.get_runtime_information()) {
this.detail_list.add(
new DetailRow("%s:".printf(detail.name), detail.value)
);
details.append_printf("%s: %s\n", detail.name, detail.value);
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);
}
this.details = details.str;
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();

View file

@ -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>