+}
+
+static void choose_row_expanded(GtkTreeView attribute((unused)) *treeview,
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ gpointer attribute((unused)) user_data) {
+ /*fprintf(stderr, "row-expanded path=[%s]\n\n",
+ gtk_tree_path_to_string(path));*/
+ /* We update a node's contents whenever it is expanded, even if it was
+ * already populated; the effect is that contracting and expanding a node
+ * suffices to update it to the latest state on the server. */
+ choose_refill_row(path, iter);
+ if(!choose_suppress_set_autocollapse) {
+ if(choose_auto_expanding) {
+ /* This was an automatic expansion; mark it the row for auto-collapse. */
+ gtk_tree_store_set(choose_store, iter,
+ AUTOCOLLAPSE_COLUMN, TRUE,
+ -1);
+ /*fprintf(stderr, "enable auto-collapse for %s\n",
+ gtk_tree_path_to_string(path));*/
+ } else {
+ /* This was a manual expansion. Inhibit automatic collapse on this row
+ * and all its ancestors. */
+ gboolean itv;
+ do {
+ gtk_tree_store_set(choose_store, iter,
+ AUTOCOLLAPSE_COLUMN, FALSE,
+ -1);
+ /*fprintf(stderr, "suppress auto-collapse for %s\n",
+ gtk_tree_model_get_string_from_iter(GTK_TREE_MODEL(choose_store),
+ iter));*/
+ GtkTreeIter child = *iter;
+ itv = gtk_tree_model_iter_parent(GTK_TREE_MODEL(choose_store),
+ iter,
+ &child);
+ } while(itv);
+ /* The effect of this is that if you expand a row that's actually a
+ * sibling of the real target of the auto-expansion, it stays expanded
+ * when you clear a search. That's find and good, but it _still_ stays
+ * expanded if you expand it and then collapse it.
+ *
+ * An alternative policy would be to only auto-collapse rows that don't
+ * have any expanded children (apart from ones also subject to
+ * auto-collapse). I'm not sure what the most usable policy is.
+ */
+ }
+ }
+}
+
+static void choose_auto_collapse_callback(GtkTreeView *tree_view,
+ GtkTreePath *path,
+ gpointer attribute((unused)) user_data) {
+ GtkTreeIter it[1];
+
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(choose_store), it, path);
+ if(choose_can_autocollapse(it)) {
+ /*fprintf(stderr, "collapse %s\n",
+ gtk_tree_path_to_string(path));*/
+ gtk_tree_store_set(choose_store, it,
+ AUTOCOLLAPSE_COLUMN, FALSE,
+ -1);
+ gtk_tree_view_collapse_row(tree_view, path);
+ }
+}
+
+/** @brief Perform automatic collapse after a search is cleared */
+void choose_auto_collapse(void) {
+ gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(choose_view),
+ choose_auto_collapse_callback,
+ 0);
+}
+
+/** @brief Called from choose_refill() with each expanded row */
+static void choose_refill_callback(GtkTreeView attribute((unused)) *tree_view,
+ GtkTreePath *path,
+ gpointer attribute((unused)) user_data) {
+ GtkTreeIter it[1];
+
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(choose_store), it, path);
+ choose_refill_row(path, it);
+}
+
+/** @brief Synchronize all visible data with the server
+ *
+ * Called at startup, when a rescan completes, and via periodic_slow().
+ */
+static void choose_refill(const char attribute((unused)) *event,
+ void attribute((unused)) *eventdata,
+ void attribute((unused)) *callbackdata) {
+ //fprintf(stderr, "choose_refill\n");
+ /* Update the root */
+ disorder_eclient_files(client, choose_files_completed, "", NULL, NULL);
+ disorder_eclient_dirs(client, choose_dirs_completed, "", NULL, NULL);
+ choose_list_in_flight += 2;
+ /* Update all expanded rows */
+ gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(choose_view),
+ choose_refill_callback,
+ 0);