chiark / gitweb /
Auto-collapse rows that were only expanded to display search results.
[disorder] / disobedience / choose-search.c
index c804276d812683dc79f0b85da3cb6c56b3697288..82a06757184aaa99db051b432ab16ce5a48c24e4 100644 (file)
  *
  * TODO:
  * - cleverer focus to implement typeahead find
- * - don't steal ^A
  */
 #include "disobedience.h"
 #include "choose.h"
 
+int choose_auto_expanding;
+
 static GtkWidget *choose_search_entry;
 static GtkWidget *choose_next;
 static GtkWidget *choose_prev;
@@ -125,7 +126,7 @@ static int choose_make_one_visible(const char *track) {
     }
     if(is_prefix(dir, track)) {
       /* We found a prefix of the target track. */
-      //fprintf(stderr, "   is a prefix\n");
+      //fprintf(stderr, "   %s is a prefix\n", dir);
       const gboolean expanded
         = gtk_tree_view_row_expanded(GTK_TREE_VIEW(choose_view), path);
       if(expanded) {
@@ -147,14 +148,16 @@ static int choose_make_one_visible(const char *track) {
       } else {
         //fprintf(stderr, "   requesting expansion of %s\n", dir);
         /* Track is below a non-expanded directory.  So let's expand it.
-         * choose_make_visible() will arrange a revisit in due course. */
+         * choose_make_visible() will arrange a revisit in due course.
+         *
+         * We mark the row as auto-expanded.
+         */
+        ++choose_auto_expanding;
         gtk_tree_view_expand_row(GTK_TREE_VIEW(choose_view),
                                  path,
                                  FALSE/*open_all*/);
         gtk_tree_path_free(path);
-        /* TODO: the old version would remember which rows had been expanded
-         * just to show search results and collapse them again.  We should
-         * probably do that. */
+        --choose_auto_expanding;
         return 0;
       }
     } else
@@ -190,6 +193,8 @@ static int choose_compare_references(const void *av, const void *bv) {
  *
  * If @p row_align is negative no row alignemt is performed.  Otherwise
  * it must be between 0 (the top) and 1 (the bottom).
+ *
+ * TODO: if the row is already visible do nothing.
  */
 static int choose_make_path_visible(GtkTreePath *path,
                                     gfloat row_align) {
@@ -244,7 +249,7 @@ static void choose_make_visible(const char attribute((unused)) *event,
     /* If there's work left to be done make sure we get a callback when
      * something changes */
     if(!choose_inserted_handle)
-      choose_inserted_handle = event_register("choose-inserted-tracks",
+      choose_inserted_handle = event_register("choose-more-tracks",
                                               choose_make_visible, 0);
   } else {
     /* Suppress callbacks if there's nothing more to do */
@@ -277,6 +282,9 @@ static void choose_search_completed(void attribute((unused)) *v,
     return;
   }
   //fprintf(stderr, "*** %d search results\n", nvec);
+  /* We're actually going to use these search results.  Autocollapse anything
+   * left over from the old search. */
+  choose_auto_collapse();
   choose_search_hash = hash_new(1);
   if(nvec) {
     for(int n = 0; n < nvec; ++n)