[perl-Glib-Object-Introspection] perli11ndoc: when filtering, show children of matching elements



commit 7fcbfab3a2dd29e9d3dd125099612107de9142c6
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Sat Sep 12 12:56:43 2015 +0200

    perli11ndoc: when filtering, show children of matching elements

 bin/perli11ndoc |   44 ++++++++++++++++++++++++++++++--------------
 1 files changed, 30 insertions(+), 14 deletions(-)
---
diff --git a/bin/perli11ndoc b/bin/perli11ndoc
index 7e3ff7f..aba2871 100755
--- a/bin/perli11ndoc
+++ b/bin/perli11ndoc
@@ -1216,21 +1216,37 @@ sub filter_gir_view {
     } else {
       $re = qr/\Q$criterion\E/i;
     }
-    $model->foreach (sub {
-      my (undef, $path, $iter) = @_;
-      my ($text, $is_cat) = $model->get ($iter, GIR_VIEW_COL_TEXT,
-                                         GIR_VIEW_COL_IS_CATEGORY);
-      my $is_match = $text =~ $re;
-      if ($is_cat || !$is_match) {
-        $model->set ($iter, GIR_VIEW_COL_IS_VISIBLE, FALSE);
-      } else {
-        # Make the element and all its parents visible.
-        do {
-          $model->set ($iter, GIR_VIEW_COL_IS_VISIBLE, TRUE);
-        } while (defined ($iter = $model->iter_parent ($iter)));
-        $view->expand_to_path ($filter_model->convert_child_path_to_path ($path));
+
+    my $check_tree;
+    $check_tree = sub {
+      my ($iter) = @_;
+      my @children = map { $model->iter_nth_child ($iter, $_) }
+                         0..$model->iter_n_children ($iter);
+      foreach my $child (@children) {
+        my ($text, $is_cat) = $model->get ($child,
+                                           GIR_VIEW_COL_TEXT,
+                                           GIR_VIEW_COL_IS_CATEGORY);
+        if ($is_cat || $text !~ $re) { # no match
+          $model->set ($child, GIR_VIEW_COL_IS_VISIBLE, FALSE);
+          $check_tree->($child); # descend
+        } else { # match
+          # Make the element and all its parents visible.
+          my $cur = $child;
+          do {
+            $model->set ($cur, GIR_VIEW_COL_IS_VISIBLE, TRUE);
+          } while (defined ($cur = $model->iter_parent ($cur)));
+
+          # Expand the matching element and all its parents.
+          $view->expand_to_path (
+            $filter_model->convert_child_path_to_path (
+              $model->get_path ($child)));
+
+          # No need to descend as we want all children of matching elements to
+          # be visible.  (All elements are visible by default.)
+        }
       }
-    });
+    };
+    $check_tree->(undef); # start with the virtual root node
   }
 }
 


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