From b96645084a304e564c116d2a9c32fce3faeb6ced Mon Sep 17 00:00:00 2001 From: Tom Samstag Date: Sun, 13 Mar 2016 23:45:09 -0700 Subject: [PATCH] add a filter to the tree of rule filters I can never remember which category filters are in when making a new rule. This change adds a filter entry above the treeview. As you type, filters that do not contain the search text (case insensitively) are made not visible. Categories are always visible, but will no longer expand if all of their child nodes are hidden. --- gramps/gui/editors/filtereditor.py | 24 +++++++++++++++- gramps/gui/glade/rule.glade | 44 ++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/gramps/gui/editors/filtereditor.py b/gramps/gui/editors/filtereditor.py index 6c5170cc0..aca96fed5 100644 --- a/gramps/gui/editors/filtereditor.py +++ b/gramps/gui/editors/filtereditor.py @@ -455,6 +455,7 @@ class EditRule(ManagedWindow): self.get_widget('rule_editor_title'),label) self.window.hide() self.valuebox = self.get_widget('valuebox') + self.rname_filter = self.get_widget('ruletreefilter') self.rname = self.get_widget('ruletree') self.rule_name = self.get_widget('rulename') self.description = self.get_widget('description') @@ -619,11 +620,13 @@ class EditRule(ManagedWindow): self.page_num = self.page_num + 1 self.page_num = 0 self.store = Gtk.TreeStore(GObject.TYPE_STRING, GObject.TYPE_PYOBJECT) + self.ruletree_filter = self.store.filter_new() + self.ruletree_filter.set_visible_func(self.rtree_visible_func) self.selection = self.rname.get_selection() col = Gtk.TreeViewColumn(_('Rule Name'), Gtk.CellRendererText(), text=0) self.rname.append_column(col) - self.rname.set_model(self.store) + self.rname.set_model(self.ruletree_filter) prev = None last_top = None @@ -677,6 +680,7 @@ class EditRule(ManagedWindow): self.get_widget('rule_editor_ok').connect('clicked', self.rule_ok) self.get_widget('rule_editor_cancel').connect('clicked', self.close_window) self.get_widget('rule_editor_help').connect('clicked', self.on_help_clicked) + self.rname_filter.connect('changed', self.on_rname_filter_changed) self._set_size() self.show() @@ -735,6 +739,12 @@ class EditRule(ManagedWindow): class_obj = store.get_value(node, 1) self.display_values(class_obj) + def on_rname_filter_changed(self, obj): + """ + Update the ruletree based on the filter. + """ + self.ruletree_filter.refilter() + def display_values(self, class_obj): if class_obj in self.class2page: page = self.class2page[class_obj] @@ -765,6 +775,18 @@ class EditRule(ManagedWindow): except KeyError: pass + def rtree_visible_func(self, model, iter, data): + """ + Callback function to determine if a row of the tree is visible + """ + filter_text = self.rname_filter.get_text() + tree_text = model[iter][0] + children = model[iter].iterchildren() + result = (not tree_text or + children.iter or + filter_text.lower() in tree_text.lower()) + return result + #------------------------------------------------------------------------- # # EditFilter diff --git a/gramps/gui/glade/rule.glade b/gramps/gui/glade/rule.glade index 14c028262..258fa8817 100644 --- a/gramps/gui/glade/rule.glade +++ b/gramps/gui/glade/rule.glade @@ -835,13 +835,45 @@ in 200 - - 250 + True - True - False - - + False + + + True + False + vertical + + + True + True + edit-find-symbolic + False + False + + + False + True + 0 + + + + + 250 + True + True + False + + + + + + True + True + 1 + + +