chiark / gitweb /
Delay search initiation for a bit after the last keypress, to avoid
[disorder] / disobedience / choose.c
index ce3f754d6b36032a8da326b6603f9e16cd5f868e..a275fac1c49c25dbc1879c2b8402f9ff3bccb0dd 100644 (file)
@@ -35,7 +35,6 @@
  * TODO:
  * - sweep up contracted nodes
  * - update when content may have changed (e.g. after a rescan)
- * - searching!
  * - proper sorting
  */
 
@@ -51,6 +50,12 @@ GtkWidget *choose_view;
 /** @brief The selection tree's selection */
 GtkTreeSelection *choose_selection;
 
+/** @brief Count of file listing operations in flight */
+static int choose_list_in_flight;
+
+/** @brief Count of files inserted in current batch of listing operations */
+static int choose_inserted;
+
 static char *choose_get_string(GtkTreeIter *iter, int column) {
   gchar *gs;
   gtk_tree_model_get(GTK_TREE_MODEL(choose_store), iter,
@@ -125,8 +130,8 @@ static gboolean choose_set_state_callback(GtkTreeModel attribute((unused)) *mode
                        -1);
     if(choose_is_search_result(track))
       gtk_tree_store_set(choose_store, it,
-                         BG_COLUMN, "yellow",
-                         FG_COLUMN, "black",
+                         BG_COLUMN, SEARCH_RESULT_BG,
+                         FG_COLUMN, SEARCH_RESULT_FG,
                          -1);
     else
       gtk_tree_store_set(choose_store, it,
@@ -219,7 +224,7 @@ static void choose_populate(GtkTreeRowReference *parent_ref,
   }
   /* Add nodes we don't have */
   int inserted = 0;
-  //fprintf(stderr, " inserting new %s nodes\n", choose_type_map[type]);
+  //fprintf(stderr, " inserting new %s nodes\n", isfile ? "track" : "dir");
   const char *typename = isfile ? "track" : "dir";
   for(int n = 0; n < nvec; ++n) {
     if(!found[n]) {
@@ -264,6 +269,18 @@ static void choose_populate(GtkTreeRowReference *parent_ref,
     gtk_tree_row_reference_free(parent_ref);
     gtk_tree_path_free(parent_path);
   }
+  /* We only notify others that we've inserted tracks when there are no more
+   * insertions pending, so that they don't have to keep track of how many
+   * requests they've made.  */
+  choose_inserted += inserted;
+  if(--choose_list_in_flight == 0) {
+    /* Notify interested parties that we inserted some tracks, AFTER making
+     * sure that the row is properly expanded */
+    if(choose_inserted) {
+      event_raise("choose-inserted-tracks", parent_it);
+      choose_inserted = 0;
+    }
+  }
 }
 
 static void choose_dirs_completed(void *v,
@@ -334,6 +351,7 @@ static void choose_row_expanded(GtkTreeView attribute((unused)) *treeview,
                         gtk_tree_row_reference_new(GTK_TREE_MODEL(choose_store),
                                                    path));
   /* The row references are destroyed in the _completed handlers. */
+  choose_list_in_flight += 2;
 }
 
 /** @brief Create the choose tab */