2 * This file is part of DisOrder
3 * Copyright (C) 2006, 2007 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 /** @file disobedience/choose.c
21 * @brief Hierarchical track selection and search
23 * We don't use the built-in tree widgets because they require that you know
24 * the children of a node on demand, and we have to wait for the server to tell
28 #include "disobedience.h"
30 /* Choose track ------------------------------------------------------------ */
48 /** @brief Accumulated information about the tree widget */
50 /** @brief Maximum width required */
52 /** @brief Maximum height required */
56 /* instantiate the node vector type */
58 VECTOR_TYPE(nodevector, struct choosenode *, xrealloc);
60 /** @brief Signature of function called when a choosenode is filled */
61 typedef void (when_filled_callback)(struct choosenode *cn,
64 /** @brief One node in the virtual filesystem */
66 struct choosenode *parent; /**< @brief parent node */
67 const char *path; /**< @brief full path or 0 */
68 const char *sort; /**< @brief sort key */
69 const char *display; /**< @brief display name */
70 int pending; /**< @brief pending resolve queries */
72 #define CN_EXPANDABLE 0x0001 /**< @brief node is expandable */
73 #define CN_EXPANDED 0x0002 /**< @brief node is expanded
75 * Expandable items are directories;
76 * non-expandable ones are files. */
77 #define CN_DISPLAYED 0x0004 /**< @brief widget is displayed in layout */
78 #define CN_SELECTED 0x0008 /**< @brief node is selected */
79 #define CN_GETTING_FILES 0x0010 /**< @brief files inbound */
80 #define CN_RESOLVING_FILES 0x0020 /**< @brief resolved files inbound */
81 #define CN_GETTING_DIRS 0x0040 /**< @brief directories inbound */
82 #define CN_GETTING_ANY 0x0070 /**< @brief getting something */
83 #define CN_CONTINGENT 0x0080 /**< @brief expansion contingent on search */
84 struct nodevector children; /**< @brief vector of children */
85 void (*fill)(struct choosenode *); /**< @brief request child fill or 0 for leaf */
86 GtkWidget *container; /**< @brief the container for this row */
87 GtkWidget *hbox; /**< @brief the hbox for this row */
88 GtkWidget *arrow; /**< @brief arrow widget or 0 */
89 GtkWidget *label; /**< @brief text label for this node */
90 GtkWidget *marker; /**< @brief queued marker */
92 when_filled_callback *whenfilled; /**< @brief called when filled or 0 */
93 void *wfu; /**< @brief passed to @c whenfilled */
94 int ymin; /**< @brief least Y value */
95 int ymax; /**< @brief greatest Y value */
98 /** @brief One item in the popup menu */
99 struct choose_menuitem {
101 const char *name; /**< @brief name */
104 void (*activate)(GtkMenuItem *menuitem, gpointer user_data);
105 /**< @brief Called to activate the menu item.
107 * @p user_data is the choosenode the mouse pointer is over. */
109 gboolean (*sensitive)(struct choosenode *cn);
110 /* @brief Called to determine whether the menu item should be sensitive.
115 gulong handlerid; /**< @brief signal handler ID */
116 GtkWidget *w; /**< @brief menu item widget */
121 static GtkWidget *chooselayout;
122 static GtkAdjustment *vadjust;
123 static GtkWidget *searchentry; /**< @brief search terms */
124 static GtkWidget *nextsearch; /**< @brief next search result */
125 static GtkWidget *prevsearch; /**< @brief previous search result */
126 static struct choosenode *root;
127 static GtkWidget *track_menu; /**< @brief track popup menu */
128 static GtkWidget *dir_menu; /**< @brief directory popup menu */
129 static struct choosenode *last_click; /**< @brief last clicked node for selection */
130 static int files_visible; /**< @brief total files visible */
131 static int files_selected; /**< @brief total files selected */
132 static int gets_in_flight; /**< @brief total gets in flight */
133 static int search_in_flight; /**< @brief a search is underway */
134 static int search_obsolete; /**< @brief the current search is void */
135 static char **searchresults; /**< @brief search results */
136 static int nsearchresults; /**< @brief number of results */
137 static int nsearchvisible; /**< @brief number of search results visible */
138 static struct hash *searchhash; /**< @brief hash of search results */
139 static struct progress_window *spw; /**< @brief progress window */
140 static struct choosenode **searchnodes; /**< @brief choosenodes of search results */
141 static int suppress_redisplay; /**< @brief suppress redisplay */
143 /* Forward Declarations */
145 static void clear_children(struct choosenode *cn);
146 static struct choosenode *newnode(struct choosenode *parent,
151 void (*fill)(struct choosenode *));
152 static void fill_root_node(struct choosenode *cn);
153 static void fill_directory_node(struct choosenode *cn);
154 static void got_files(void *v, int nvec, char **vec);
155 static void got_resolved_file(void *v, const char *track);
156 static void got_dirs(void *v, int nvec, char **vec);
158 static void expand_node(struct choosenode *cn, int contingent);
159 static void contract_node(struct choosenode *cn);
160 static void updated_node(struct choosenode *cn, int redisplay,
163 static void display_selection(struct choosenode *cn);
164 static void clear_selection(struct choosenode *cn);
166 static void redisplay_tree(const char *why);
167 static struct displaydata display_tree(struct choosenode *cn, int x, int y);
168 static void undisplay_tree(struct choosenode *cn);
169 static void initiate_search(void);
170 static void delete_widgets(struct choosenode *cn);
171 static void expand_from(struct choosenode *cn);
172 static struct choosenode *first_search_result(struct choosenode *cn);
174 static void clicked_choosenode(GtkWidget attribute((unused)) *widget,
175 GdkEventButton *event,
178 static void activate_track_play(GtkMenuItem *menuitem, gpointer user_data);
179 static void activate_track_properties(GtkMenuItem *menuitem, gpointer user_data);
181 static gboolean sensitive_track_play(struct choosenode *cn);
182 static gboolean sensitive_track_properties(struct choosenode *cn);
184 static void activate_dir_play(GtkMenuItem *menuitem, gpointer user_data);
185 static void activate_dir_properties(GtkMenuItem *menuitem, gpointer user_data);
186 static void activate_dir_select(GtkMenuItem *menuitem, gpointer user_data);
188 static gboolean sensitive_dir_play(struct choosenode *cn);
189 static gboolean sensitive_dir_properties(struct choosenode *cn);
190 static gboolean sensitive_dir_select(struct choosenode *cn);
192 /** @brief Track menu items */
193 static struct choose_menuitem track_menuitems[] = {
194 { "Play track", activate_track_play, sensitive_track_play, 0, 0 },
195 { "Track properties", activate_track_properties, sensitive_track_properties, 0, 0 },
199 /** @brief Directory menu items */
200 static struct choose_menuitem dir_menuitems[] = {
201 { "Play all tracks", activate_dir_play, sensitive_dir_play, 0, 0 },
202 { "Track properties", activate_dir_properties, sensitive_dir_properties, 0, 0 },
203 { "Select all tracks", activate_dir_select, sensitive_dir_select, 0, 0 },
207 /* Maintaining the data structure ------------------------------------------ */
209 static char *cnflags(const struct choosenode *cn) {
210 unsigned f = cn->flags, n;
213 static const char *bits[] = {
223 #define NBITS (sizeof bits / sizeof *bits)
227 dynstr_append(d, '0');
229 for(n = 0; n < NBITS; ++n) {
230 const unsigned bit = 1 << n;
233 dynstr_append(d, '|');
234 dynstr_append_string(d, bits[n]);
241 dynstr_append(d, '|');
242 sprintf(buf, "%#x", f);
243 dynstr_append_string(d, buf);
250 /** @brief Create a new node */
251 static struct choosenode *newnode(struct choosenode *parent,
256 void (*fill)(struct choosenode *)) {
257 struct choosenode *const n = xmalloc(sizeof *n);
259 D(("newnode %s %s", path, display));
260 if(flags & CN_EXPANDABLE)
266 n->display = display;
269 nodevector_init(&n->children);
272 nodevector_append(&parent->children, n);
276 /** @brief Called when a node has been filled
278 * Response for calling @c whenfilled.
280 static void filled(struct choosenode *cn) {
281 when_filled_callback *const whenfilled = cn->whenfilled;
285 whenfilled(cn, cn->wfu);
287 if(nsearchvisible < nsearchresults) {
288 /* There is still search expansion work to do */
289 D(("filled %s %d/%d", cn->path, nsearchvisible, nsearchresults));
292 if(gets_in_flight == 0 && nsearchvisible < nsearchresults)
296 /** @brief Fill the root */
297 static void fill_root_node(struct choosenode *cn) {
298 struct callbackdata *cbd;
300 D(("fill_root_node"));
302 /* More de-duping possible here */
303 if(cn->flags & CN_GETTING_ANY)
305 gtk_label_set_text(GTK_LABEL(report_label), "getting files");
306 cbd = xmalloc(sizeof *cbd);
307 cbd->u.choosenode = cn;
308 disorder_eclient_dirs(client, got_dirs, "", 0, cbd);
309 cbd = xmalloc(sizeof *cbd);
310 cbd->u.choosenode = cn;
311 disorder_eclient_files(client, got_files, "", 0, cbd);
312 cn->flags |= CN_GETTING_FILES|CN_GETTING_DIRS;
316 /** @brief Delete all the widgets owned by @p cn */
317 static void delete_cn_widgets(struct choosenode *cn) {
320 gtk_widget_destroy(cn->arrow);
325 gtk_widget_destroy(cn->label);
330 gtk_widget_destroy(cn->marker);
335 gtk_widget_destroy(cn->hbox);
340 gtk_widget_destroy(cn->container);
345 /** @brief Recursively clear all the children of @p cn
347 * All the widgets at or below @p cn are deleted. All choosenodes below
348 * it are emptied. i.e. we prune the tree at @p cn.
350 static void clear_children(struct choosenode *cn) {
353 D(("clear_children %s", cn->path));
354 /* Recursively clear subtrees */
355 for(n = 0; n < cn->children.nvec; ++n) {
356 clear_children(cn->children.vec[n]);
357 delete_cn_widgets(cn->children.vec[n]);
359 cn->children.nvec = 0;
362 /** @brief Called with a list of files just below some node */
363 static void got_files(void *v, int nvec, char **vec) {
364 struct callbackdata *cbd = v;
365 struct choosenode *cn = cbd->u.choosenode;
368 D(("got_files %d files for %s %s", nvec, cn->path, cnflags(cn)));
369 /* Complicated by the need to resolve aliases. We can save a bit of effort
370 * by re-using cbd though. */
371 cn->flags &= ~CN_GETTING_FILES;
373 if((cn->pending = nvec)) {
374 cn->flags |= CN_RESOLVING_FILES;
375 for(n = 0; n < nvec; ++n) {
376 disorder_eclient_resolve(client, got_resolved_file, vec[n], cbd);
380 /* If there are no files and the directories are all read by now, we're
382 if(!(cn->flags & CN_GETTING_ANY))
385 redisplay_tree("got_files");
388 /** @brief Called with an alias resolved filename */
389 static void got_resolved_file(void *v, const char *track) {
390 struct callbackdata *cbd = v;
391 struct choosenode *cn = cbd->u.choosenode, *file_cn;
393 D(("resolved %s %s %d left", cn->path, cnflags(cn), cn->pending - 1));
395 file_cn = newnode(cn, track,
396 trackname_transform("track", track, "display"),
397 trackname_transform("track", track, "sort"),
398 0/*flags*/, 0/*fill*/);
400 /* Only bother updating when we've got the lot */
401 if(--cn->pending == 0) {
402 cn->flags &= ~CN_RESOLVING_FILES;
403 updated_node(cn, gets_in_flight == 0, "got_resolved_file");
404 if(!(cn->flags & CN_GETTING_ANY))
409 /** @brief Called with a list of directories just below some node */
410 static void got_dirs(void *v, int nvec, char **vec) {
411 struct callbackdata *cbd = v;
412 struct choosenode *cn = cbd->u.choosenode;
415 D(("got_dirs %d dirs for %s %s", nvec, cn->path, cnflags(cn)));
416 /* TODO this depends on local configuration for trackname_transform().
417 * This will work, since the defaults are now built-in, but it'll be
418 * (potentially) different to the server's configured settings.
420 * Really we want a variant of files/dirs that produces both the
421 * raw filename and the transformed name for a chosen context.
424 for(n = 0; n < nvec; ++n)
426 trackname_transform("dir", vec[n], "display"),
427 trackname_transform("dir", vec[n], "sort"),
428 CN_EXPANDABLE, fill_directory_node);
429 updated_node(cn, gets_in_flight == 0, "got_dirs");
430 cn->flags &= ~CN_GETTING_DIRS;
431 if(!(cn->flags & CN_GETTING_ANY))
435 /** @brief Fill a child node */
436 static void fill_directory_node(struct choosenode *cn) {
437 struct callbackdata *cbd;
439 D(("fill_directory_node %s", cn->path));
441 if(cn->flags & CN_GETTING_ANY)
443 assert(report_label != 0);
444 gtk_label_set_text(GTK_LABEL(report_label), "getting files");
446 cbd = xmalloc(sizeof *cbd);
447 cbd->u.choosenode = cn;
448 disorder_eclient_dirs(client, got_dirs, cn->path, 0, cbd);
449 cbd = xmalloc(sizeof *cbd);
450 cbd->u.choosenode = cn;
451 disorder_eclient_files(client, got_files, cn->path, 0, cbd);
452 cn->flags |= CN_GETTING_FILES|CN_GETTING_DIRS;
456 /** @brief Expand a node */
457 static void expand_node(struct choosenode *cn, int contingent) {
458 D(("expand_node %s %d %s", cn->path, contingent, cnflags(cn)));
459 assert(cn->flags & CN_EXPANDABLE);
460 /* If node is already expanded do nothing. */
461 if(cn->flags & CN_EXPANDED) return;
462 /* We mark the node as expanded and request that it fill itself. When it has
463 * completed it will called updated_node() and we can redraw at that
465 cn->flags |= CN_EXPANDED;
467 cn->flags |= CN_CONTINGENT;
469 cn->flags &= ~CN_CONTINGENT;
470 /* If this node is not contingently expanded, mark all its parents back to
471 * the root as not contingent either, so they won't be contracted when the
472 * search results change */
474 struct choosenode *cnp;
476 for(cnp = cn->parent; cnp; cnp = cnp->parent)
477 cnp->flags &= ~CN_CONTINGENT;
479 /* TODO: visual feedback */
483 /** @brief Make sure all the search results below @p cn are expanded
484 * @param cn Node to start at
486 static void expand_from(struct choosenode *cn) {
489 if(nsearchvisible == nsearchresults)
492 /* Are any of the search tracks at/below this point? */
493 if(!(cn == root || hash_find(searchhash, cn->path)))
495 D(("expand_from %d/%d visible %s",
496 nsearchvisible, nsearchresults, cn->path));
497 if(cn->flags & CN_EXPANDABLE) {
498 if(cn->flags & CN_EXPANDED)
499 /* This node is marked as expanded already. children.nvec might be 0,
500 * indicating that expansion is still underway. We should get another
501 * callback when it is expanded. */
502 for(n = 0; n < cn->children.nvec && gets_in_flight < 10; ++n)
503 expand_from(cn->children.vec[n]);
505 /* This node is not expanded yet */
509 /* This is an actual search result */
511 progress_window_progress(spw, nsearchvisible, nsearchresults);
512 if(nsearchvisible == nsearchresults) {
513 if(suppress_redisplay) {
514 suppress_redisplay = 0;
515 redisplay_tree("all search results visible");
517 /* We've got the lot. We make sure the first result is visible. */
518 cn = first_search_result(root);
519 gtk_adjustment_clamp_page(vadjust, cn->ymin, cn->ymax);
524 /** @brief Contract all contingently expanded nodes below @p cn */
525 static void contract_contingent(struct choosenode *cn) {
528 if(cn->flags & CN_CONTINGENT)
531 for(n = 0; n < cn->children.nvec; ++n)
532 contract_contingent(cn->children.vec[n]);
535 /** @brief Contract a node */
536 static void contract_node(struct choosenode *cn) {
537 D(("contract_node %s", cn->path));
538 assert(cn->flags & CN_EXPANDABLE);
539 /* If node is already contracted do nothing. */
540 if(!(cn->flags & CN_EXPANDED)) return;
541 cn->flags &= ~(CN_EXPANDED|CN_CONTINGENT);
542 /* Clear selection below this node */
544 /* Zot children. We never used to do this but the result would be that over
545 * time you'd end up with the entire tree pulled into memory. If the server
546 * is over a slow network it will make interactivity slightly worse; if
547 * anyone complains we can make it an option. */
549 /* We can contract a node immediately. */
550 redisplay_tree("contract_node");
553 /** @brief qsort() callback for ordering choosenodes */
554 static int compare_choosenode(const void *av, const void *bv) {
555 const struct choosenode *const *aa = av, *const *bb = bv;
556 const struct choosenode *a = *aa, *b = *bb;
558 return compare_tracks(a->sort, b->sort,
559 a->display, b->display,
563 /** @brief Called when an expandable node is updated. */
564 static void updated_node(struct choosenode *cn, int redisplay,
566 D(("updated_node %s", cn->path));
567 assert(cn->flags & CN_EXPANDABLE);
568 /* It might be that the node has been de-expanded since we requested the
569 * update. In that case we ignore this notification. */
570 if(!(cn->flags & CN_EXPANDED)) return;
572 qsort(cn->children.vec, cn->children.nvec, sizeof (struct choosenode *),
577 snprintf(whywhy, sizeof whywhy, "updated_node %s", why);
578 redisplay_tree(whywhy);
582 /* Searching --------------------------------------------------------------- */
584 /** @brief Return true if @p track is a search result
586 * In particular the return value is one more than the index of the track
589 static int is_search_result(const char *track) {
592 if(searchhash && (r = hash_find(searchhash, track)))
593 return 1 + *(int *)r;
598 /** @brief Return the first search result at or below @p cn */
599 static struct choosenode *first_search_result(struct choosenode *cn) {
601 struct choosenode *r;
603 if(cn->flags & CN_EXPANDABLE) {
604 for(n = 0; n < cn->children.nvec; ++n)
605 if((r = first_search_result(cn->children.vec[n])))
607 } else if(is_search_result(cn->path))
612 /** @brief Called with a list of search results
614 * This is called from eclient with a (possibly empty) list of search results,
615 * and also from initiate_seatch with an always empty list to indicate that
616 * we're not searching for anything in particular. */
617 static void search_completed(void attribute((unused)) *v,
618 int nvec, char **vec) {
622 search_in_flight = 0;
623 /* Contract any choosenodes that were only expanded to show search
625 suppress_redisplay = 1;
626 contract_contingent(root);
627 suppress_redisplay = 0;
628 if(search_obsolete) {
629 /* This search has been obsoleted by user input since it started.
630 * Therefore we throw away the result and search again. */
634 /* Stash the search results */
636 nsearchresults = nvec;
638 /* Create a new search hash for fast identification of results */
639 searchhash = hash_new(sizeof(int));
640 for(n = 0; n < nvec; ++n) {
641 int *const ip = xmalloc(sizeof (int *));
642 static const int minus_1 = -1;
644 /* The filename itself lives in the hash */
645 hash_add(searchhash, vec[n], ip, HASH_INSERT_OR_REPLACE);
646 /* So do its ancestor directories */
647 for(s = vec[n] + 1; *s; ++s) {
650 hash_add(searchhash, vec[n], &minus_1, HASH_INSERT_OR_REPLACE);
655 /* We don't yet know that the results are visible */
658 progress_window_progress(spw, 0, 0);
661 if(nsearchresults > 50)
662 spw = progress_window_new("Fetching search results");
663 /* Initiate expansion */
665 /* The search results buttons are usable */
666 gtk_widget_set_sensitive(nextsearch, 1);
667 gtk_widget_set_sensitive(prevsearch, 1);
668 suppress_redisplay = 1; /* avoid lots of redisplays */
670 searchhash = 0; /* for the gc */
671 redisplay_tree("no search results"); /* remove search markers */
672 /* The search results buttons are not usable */
673 gtk_widget_set_sensitive(nextsearch, 0);
674 gtk_widget_set_sensitive(prevsearch, 0);
679 /** @brief Initiate a search
681 * If a search is underway we set @ref search_obsolete and restart the search
682 * in search_completed() above.
684 static void initiate_search(void) {
687 /* Find out what the user is after */
688 terms = xstrdup(gtk_entry_get_text(GTK_ENTRY(searchentry)));
689 /* Strip leading and trailing space */
690 while(*terms == ' ') ++terms;
691 e = terms + strlen(terms);
692 while(e > terms && e[-1] == ' ') --e;
694 /* If a search is already underway then mark it as obsolete. We'll revisit
695 * when it returns. */
696 if(search_in_flight) {
701 /* There's still something left. Initiate the search. */
702 if(disorder_eclient_search(client, search_completed, terms, 0)) {
703 /* The search terms are bad! We treat this as if there were no search
704 * terms at all. Some kind of feedback would be handy. */
705 fprintf(stderr, "bad terms [%s]\n", terms); /* TODO */
706 search_completed(0, 0, 0);
708 search_in_flight = 1;
711 /* No search terms - we want to see all tracks */
712 search_completed(0, 0, 0);
716 /** @brief Called when the cancel search button is clicked */
717 static void clearsearch_clicked(GtkButton attribute((unused)) *button,
718 gpointer attribute((unused)) userdata) {
719 gtk_entry_set_text(GTK_ENTRY(searchentry), "");
722 /** @brief Called when the 'next search result' button is clicked */
723 static void next_clicked(GtkButton attribute((unused)) *button,
724 gpointer attribute((unused)) userdata) {
725 /* We want to find the highest (lowest ymax) track that is below the current
728 const gdouble bottom = gtk_adjustment_get_value(vadjust) + vadjust->page_size;
729 const struct choosenode *candidate = 0;
731 for(n = 0; n < nsearchresults; ++n) {
732 const struct choosenode *const cn = searchnodes[n];
737 || cn->ymax < candidate->ymax))
741 gtk_adjustment_clamp_page(vadjust, candidate->ymin, candidate->ymax);
744 /** @brief Called when the 'previous search result' button is clicked */
745 static void prev_clicked(GtkButton attribute((unused)) *button,
746 gpointer attribute((unused)) userdata) {
747 /* We want to find the lowest (greated ymax) track that is above the current
750 const gdouble top = gtk_adjustment_get_value(vadjust);
751 const struct choosenode *candidate = 0;
753 for(n = 0; n < nsearchresults; ++n) {
754 const struct choosenode *const cn = searchnodes[n];
759 || cn->ymax > candidate->ymax))
763 gtk_adjustment_clamp_page(vadjust, candidate->ymin, candidate->ymax);
766 /* Display functions ------------------------------------------------------- */
768 /** @brief Delete all the widgets in the tree */
769 static void delete_widgets(struct choosenode *cn) {
772 delete_cn_widgets(cn);
773 for(n = 0; n < cn->children.nvec; ++n)
774 delete_widgets(cn->children.vec[n]);
775 cn->flags &= ~(CN_DISPLAYED|CN_SELECTED);
779 /** @brief Update the display */
780 static void redisplay_tree(const char *why) {
781 struct displaydata d;
782 guint oldwidth, oldheight;
784 D(("redisplay_tree %s", why));
785 if(suppress_redisplay) {
786 /*fprintf(stderr, "redisplay_tree %s suppressed\n", why);*/
789 /*fprintf(stderr, "redisplay_tree %s *** NOT SUPPRESSED ***\n", why);*/
790 /* We'll count these up empirically each time */
793 /* Correct the layout and find out how much space it uses */
794 MTAG_PUSH("display_tree");
795 searchnodes = nsearchresults ? xcalloc(nsearchresults,
796 sizeof (struct choosenode *)) : 0;
797 d = display_tree(root, 0, 0);
799 /* We must set the total size or scrolling will not work (it wouldn't be hard
800 * for GtkLayout to figure it out for itself but presumably you're supposed
801 * to be able to have widgets off the edge of the layuot.)
803 * There is a problem: if we shrink the size then the part of the screen that
804 * is outside the new size but inside the old one is not updated. I think
805 * this is arguably bug in GTK+ but it's easy to force a redraw if this
806 * region is nonempty.
808 gtk_layout_get_size(GTK_LAYOUT(chooselayout), &oldwidth, &oldheight);
809 if(oldwidth > d.width || oldheight > d.height)
810 gtk_widget_queue_draw(chooselayout);
811 gtk_layout_set_size(GTK_LAYOUT(chooselayout), d.width, d.height);
812 /* Notify the main menu of any recent changes */
816 /** @brief Recursive step for redisplay_tree()
817 * @param cn Node to display
818 * @param x X coordinate for @p cn
819 * @param y Y coordinate for @p cn
821 * Makes sure all displayed widgets from CN down exist and are in their proper
822 * place and return the maximum space used.
824 static struct displaydata display_tree(struct choosenode *cn, int x, int y) {
827 struct displaydata d, cd;
829 const int search_result = is_search_result(cn->path);
831 D(("display_tree %s %d,%d", cn->path, x, y));
833 /* An expandable item contains an arrow and a text label. When you press the
834 * button it flips its expand state.
836 * A non-expandable item has just a text label and no arrow.
839 MTAG_PUSH("make_widgets_1");
840 /* Widgets need to be created */
842 cn->hbox = gtk_hbox_new(FALSE, 1);
843 if(cn->flags & CN_EXPANDABLE) {
845 cn->arrow = gtk_arrow_new(cn->flags & CN_EXPANDED ? GTK_ARROW_DOWN
851 if((pb = find_image("notes.png"))) {
853 cn->marker = gtk_image_new_from_pixbuf(pb);
857 MTAG_PUSH("make_widgets_2");
859 cn->label = gtk_label_new(cn->display);
861 gtk_container_add(GTK_CONTAINER(cn->hbox), cn->arrow);
862 gtk_container_add(GTK_CONTAINER(cn->hbox), cn->label);
864 gtk_container_add(GTK_CONTAINER(cn->hbox), cn->marker);
866 MTAG_PUSH("make_widgets_3");
868 cn->container = gtk_event_box_new();
869 gtk_container_add(GTK_CONTAINER(cn->container), cn->hbox);
870 g_signal_connect(cn->container, "button-release-event",
871 G_CALLBACK(clicked_choosenode), cn);
872 g_signal_connect(cn->container, "button-press-event",
873 G_CALLBACK(clicked_choosenode), cn);
874 g_object_ref(cn->container);
875 /* Show everything by default */
876 gtk_widget_show_all(cn->container);
879 assert(cn->container);
882 gtk_widget_modify_bg(cn->container, GTK_STATE_NORMAL, &search_bg);
884 gtk_widget_modify_bg(cn->container, GTK_STATE_NORMAL, &layout_bg);
885 gtk_widget_modify_bg(cn->container, GTK_STATE_SELECTED, &selected_bg);
886 gtk_widget_modify_bg(cn->container, GTK_STATE_PRELIGHT, &selected_bg);
887 gtk_widget_modify_fg(cn->label, GTK_STATE_NORMAL, &item_fg);
888 gtk_widget_modify_fg(cn->label, GTK_STATE_SELECTED, &selected_fg);
889 gtk_widget_modify_fg(cn->label, GTK_STATE_PRELIGHT, &selected_fg);
890 /* Make sure the icon is right */
891 if(cn->flags & CN_EXPANDABLE)
892 gtk_arrow_set(GTK_ARROW(cn->arrow),
893 cn->flags & CN_EXPANDED ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT,
896 /* Make sure the queued marker is right */
897 /* TODO: doesn't always work */
898 (queued(cn->path) ? gtk_widget_show : gtk_widget_hide)(cn->marker);
899 /* Put the widget in the right place */
900 if(cn->flags & CN_DISPLAYED)
901 gtk_layout_move(GTK_LAYOUT(chooselayout), cn->container, x, y);
903 gtk_layout_put(GTK_LAYOUT(chooselayout), cn->container, x, y);
904 cn->flags |= CN_DISPLAYED;
905 /* Now chooselayout has a ref to the container */
906 g_object_unref(cn->container);
908 /* Set the widget's selection status */
909 if(!(cn->flags & CN_EXPANDABLE))
910 display_selection(cn);
911 /* Find the size used so we can get vertical positioning right. */
912 gtk_widget_size_request(cn->container, &req);
913 d.width = x + req.width;
914 d.height = y + req.height;
917 if(cn->flags & CN_EXPANDED) {
918 /* We'll offset children by the size of the arrow whatever it might be. */
920 gtk_widget_size_request(cn->arrow, &req);
922 for(n = 0; n < cn->children.nvec; ++n) {
923 cd = display_tree(cn->children.vec[n], x + aw, d.height);
924 if(cd.width > d.width)
926 d.height = cd.height;
929 for(n = 0; n < cn->children.nvec; ++n)
930 undisplay_tree(cn->children.vec[n]);
932 if(!(cn->flags & CN_EXPANDABLE)) {
934 if(cn->flags & CN_SELECTED)
937 /* update the search results array */
939 searchnodes[search_result - 1] = cn;
940 /* report back how much space we used */
941 D(("display_tree %s %d,%d total size %dx%d", cn->path, x, y,
946 /** @brief Remove widgets for newly hidden nodes */
947 static void undisplay_tree(struct choosenode *cn) {
950 D(("undisplay_tree %s", cn->path));
951 /* Remove this widget from the display */
952 if(cn->flags & CN_DISPLAYED) {
953 gtk_container_remove(GTK_CONTAINER(chooselayout), cn->container);
954 cn->flags ^= CN_DISPLAYED;
956 /* Remove children too */
957 for(n = 0; n < cn->children.nvec; ++n)
958 undisplay_tree(cn->children.vec[n]);
961 /* Selection --------------------------------------------------------------- */
963 /** @brief Mark the widget @p cn according to its selection state */
964 static void display_selection(struct choosenode *cn) {
965 /* Need foreground and background colors */
966 gtk_widget_set_state(cn->label, (cn->flags & CN_SELECTED
967 ? GTK_STATE_SELECTED : GTK_STATE_NORMAL));
968 gtk_widget_set_state(cn->container, (cn->flags & CN_SELECTED
969 ? GTK_STATE_SELECTED : GTK_STATE_NORMAL));
972 /** @brief Set the selection state of a widget
974 * Directories can never be selected, we just ignore attempts to do so. */
975 static void set_selection(struct choosenode *cn, int selected) {
976 unsigned f = selected ? CN_SELECTED : 0;
978 D(("set_selection %d %s", selected, cn->path));
979 if(!(cn->flags & CN_EXPANDABLE) && (cn->flags & CN_SELECTED) != f) {
980 cn->flags ^= CN_SELECTED;
981 /* Maintain selection count */
986 display_selection(cn);
987 /* Update main menu sensitivity */
992 /** @brief Recursively clear all selection bits from CN down */
993 static void clear_selection(struct choosenode *cn) {
996 set_selection(cn, 0);
997 for(n = 0; n < cn->children.nvec; ++n)
998 clear_selection(cn->children.vec[n]);
1001 /* User actions ------------------------------------------------------------ */
1003 /** @brief Clicked on something
1005 * This implements playing, all the modifiers for selection, etc.
1007 static void clicked_choosenode(GtkWidget attribute((unused)) *widget,
1008 GdkEventButton *event,
1009 gpointer user_data) {
1010 struct choosenode *cn = user_data;
1011 int ind, last_ind, n;
1013 D(("clicked_choosenode %s", cn->path));
1014 if(event->type == GDK_BUTTON_RELEASE
1015 && event->button == 1) {
1017 if(cn->flags & CN_EXPANDABLE) {
1018 /* This is a directory. Flip its expansion status. */
1019 if(cn->flags & CN_EXPANDED)
1022 expand_node(cn, 0/*!contingent*/);
1025 /* This is a file. Adjust selection status */
1026 /* TODO the basic logic here is essentially the same as that in queue.c.
1027 * Can we share code at all? */
1028 switch(event->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK)) {
1030 clear_selection(root);
1031 set_selection(cn, 1);
1034 case GDK_CONTROL_MASK:
1035 set_selection(cn, !(cn->flags & CN_SELECTED));
1038 case GDK_SHIFT_MASK:
1039 case GDK_SHIFT_MASK|GDK_CONTROL_MASK:
1040 if(last_click && last_click->parent == cn->parent) {
1041 /* Figure out where the current and last clicks are in the list */
1042 ind = last_ind = -1;
1043 for(n = 0; n < cn->parent->children.nvec; ++n) {
1044 if(cn->parent->children.vec[n] == cn)
1046 if(cn->parent->children.vec[n] == last_click)
1049 /* Test shouldn't ever fail, but still */
1050 if(ind >= 0 && last_ind >= 0) {
1051 if(!(event->state & GDK_CONTROL_MASK)) {
1052 for(n = 0; n < cn->parent->children.nvec; ++n)
1053 set_selection(cn->parent->children.vec[n], 0);
1056 for(n = last_ind; n <= ind; ++n)
1057 set_selection(cn->parent->children.vec[n], 1);
1059 for(n = ind; n <= last_ind; ++n)
1060 set_selection(cn->parent->children.vec[n], 1);
1061 if(event->state & GDK_CONTROL_MASK)
1065 /* TODO trying to select a range that doesn't share a single parent
1066 * currently does not work, but it ought to. */
1070 } else if(event->type == GDK_BUTTON_RELEASE
1071 && event->button == 2) {
1072 /* Middle click - play the pointed track */
1073 if(!(cn->flags & CN_EXPANDABLE)) {
1074 clear_selection(root);
1075 set_selection(cn, 1);
1076 gtk_label_set_text(GTK_LABEL(report_label), "adding track to queue");
1077 disorder_eclient_play(client, cn->path, 0, 0);
1080 } else if(event->type == GDK_BUTTON_PRESS
1081 && event->button == 3) {
1082 struct choose_menuitem *const menuitems =
1083 (cn->flags & CN_EXPANDABLE ? dir_menuitems : track_menuitems);
1084 GtkWidget *const menu =
1085 (cn->flags & CN_EXPANDABLE ? dir_menu : track_menu);
1086 /* Right click. Pop up a menu. */
1087 /* If the current file isn't selected, switch the selection to just that.
1088 * (If we're looking at a directory then leave the selection alone.) */
1089 if(!(cn->flags & CN_EXPANDABLE) && !(cn->flags & CN_SELECTED)) {
1090 clear_selection(root);
1091 set_selection(cn, 1);
1094 /* Set the item sensitivity and callbacks */
1095 for(n = 0; menuitems[n].name; ++n) {
1096 if(menuitems[n].handlerid)
1097 g_signal_handler_disconnect(menuitems[n].w,
1098 menuitems[n].handlerid);
1099 gtk_widget_set_sensitive(menuitems[n].w,
1100 menuitems[n].sensitive(cn));
1101 menuitems[n].handlerid = g_signal_connect
1102 (menuitems[n].w, "activate", G_CALLBACK(menuitems[n].activate), cn);
1104 set_tool_colors(menu);
1105 /* Pop up the menu */
1106 gtk_widget_show_all(menu);
1107 gtk_menu_popup(GTK_MENU(menu), 0, 0, 0, 0,
1108 event->button, event->time);
1112 /** @brief Called BY GTK+ to tell us the search entry box has changed */
1113 static void searchentry_changed(GtkEditable attribute((unused)) *editable,
1114 gpointer attribute((unused)) user_data) {
1118 /* Track menu items -------------------------------------------------------- */
1120 /** @brief Recursive step for gather_selected() */
1121 static void recurse_selected(struct choosenode *cn, struct vector *v) {
1124 if(cn->flags & CN_EXPANDABLE) {
1125 if(cn->flags & CN_EXPANDED)
1126 for(n = 0; n < cn->children.nvec; ++n)
1127 recurse_selected(cn->children.vec[n], v);
1129 if((cn->flags & CN_SELECTED) && cn->path)
1130 vector_append(v, (char *)cn->path);
1134 /*** @brief Get a list of all the selected tracks */
1135 static const char **gather_selected(int *ntracks) {
1139 recurse_selected(root, &v);
1140 vector_terminate(&v);
1141 if(ntracks) *ntracks = v.nvec;
1142 return (const char **)v.vec;
1145 /** @brief Called when the track menu's play option is activated */
1146 static void activate_track_play(GtkMenuItem attribute((unused)) *menuitem,
1147 gpointer attribute((unused)) user_data) {
1148 const char **tracks = gather_selected(0);
1151 gtk_label_set_text(GTK_LABEL(report_label), "adding track to queue");
1152 for(n = 0; tracks[n]; ++n)
1153 disorder_eclient_play(client, tracks[n], 0, 0);
1156 /** @brief Called when the menu's properties option is activated */
1157 static void activate_track_properties(GtkMenuItem attribute((unused)) *menuitem,
1158 gpointer attribute((unused)) user_data) {
1160 const char **tracks = gather_selected(&ntracks);
1162 properties(ntracks, tracks);
1165 /** @brief Determine whether the menu's play option should be sensitive */
1166 static gboolean sensitive_track_play(struct choosenode attribute((unused)) *cn) {
1167 return (!!files_selected
1168 && (disorder_eclient_state(client) & DISORDER_CONNECTED));
1171 /** @brief Determine whether the menu's properties option should be sensitive */
1172 static gboolean sensitive_track_properties(struct choosenode attribute((unused)) *cn) {
1173 return !!files_selected && (disorder_eclient_state(client) & DISORDER_CONNECTED);
1176 /* Directory menu items ---------------------------------------------------- */
1178 /** @brief Return the file children of @p cn
1180 * The list is terminated by a null pointer.
1182 static const char **dir_files(struct choosenode *cn, int *nfiles) {
1183 const char **files = xcalloc(cn->children.nvec + 1, sizeof (char *));
1186 for(n = m = 0; n < cn->children.nvec; ++n)
1187 if(!(cn->children.vec[n]->flags & CN_EXPANDABLE))
1188 files[m++] = cn->children.vec[n]->path;
1190 if(nfiles) *nfiles = m;
1194 static void play_dir(struct choosenode *cn,
1195 void attribute((unused)) *wfu) {
1197 const char **tracks = dir_files(cn, &ntracks);
1199 gtk_label_set_text(GTK_LABEL(report_label), "adding track to queue");
1200 for(n = 0; n < ntracks; ++n)
1201 disorder_eclient_play(client, tracks[n], 0, 0);
1204 static void properties_dir(struct choosenode *cn,
1205 void attribute((unused)) *wfu) {
1207 const char **tracks = dir_files(cn, &ntracks);
1209 properties(ntracks, tracks);
1212 static void select_dir(struct choosenode *cn,
1213 void attribute((unused)) *wfu) {
1216 clear_selection(root);
1217 for(n = 0; n < cn->children.nvec; ++n)
1218 set_selection(cn->children.vec[n], 1);
1221 /** @brief Ensure @p cn is expanded and then call @p callback */
1222 static void call_with_dir(struct choosenode *cn,
1223 when_filled_callback *whenfilled,
1225 if(!(cn->flags & CN_EXPANDABLE))
1226 return; /* something went wrong */
1227 if(cn->flags & CN_EXPANDED)
1228 /* @p cn is already open */
1229 whenfilled(cn, wfu);
1231 /* @p cn is not open, arrange for the callback to go off when it is
1233 cn->whenfilled = whenfilled;
1235 expand_node(cn, 0/*not contingnet upon search*/);
1239 /** @brief Called when the directory menu's play option is activated */
1240 static void activate_dir_play(GtkMenuItem attribute((unused)) *menuitem,
1241 gpointer user_data) {
1242 struct choosenode *const cn = (struct choosenode *)user_data;
1244 call_with_dir(cn, play_dir, 0);
1247 /** @brief Called when the directory menu's properties option is activated */
1248 static void activate_dir_properties(GtkMenuItem attribute((unused)) *menuitem,
1249 gpointer user_data) {
1250 struct choosenode *const cn = (struct choosenode *)user_data;
1252 call_with_dir(cn, properties_dir, 0);
1255 /** @brief Called when the directory menu's select option is activated */
1256 static void activate_dir_select(GtkMenuItem attribute((unused)) *menuitem,
1257 gpointer user_data) {
1258 struct choosenode *const cn = (struct choosenode *)user_data;
1260 call_with_dir(cn, select_dir, 0);
1263 /** @brief Determine whether the directory menu's play option should be sensitive */
1264 static gboolean sensitive_dir_play(struct choosenode attribute((unused)) *cn) {
1265 return !!(disorder_eclient_state(client) & DISORDER_CONNECTED);
1268 /** @brief Determine whether the directory menu's properties option should be sensitive */
1269 static gboolean sensitive_dir_properties(struct choosenode attribute((unused)) *cn) {
1270 return !!(disorder_eclient_state(client) & DISORDER_CONNECTED);
1273 /** @brief Determine whether the directory menu's select option should be sensitive */
1274 static gboolean sensitive_dir_select(struct choosenode attribute((unused)) *cn) {
1280 /* Main menu plumbing ------------------------------------------------------ */
1282 /** @brief Determine whether the edit menu's properties option should be sensitive */
1283 static int choose_properties_sensitive(GtkWidget attribute((unused)) *w) {
1284 return !!files_selected && (disorder_eclient_state(client) & DISORDER_CONNECTED);
1287 /** @brief Determine whether the edit menu's select all option should be sensitive
1289 * TODO not implemented, see also choose_selectall_activate()
1291 static int choose_selectall_sensitive(GtkWidget attribute((unused)) *w) {
1295 /** @brief Called when the edit menu's properties option is activated */
1296 static void choose_properties_activate(GtkWidget attribute((unused)) *w) {
1297 activate_track_properties(0, 0);
1300 /** @brief Called when the edit menu's select all option is activated
1302 * TODO not implemented, see choose_selectall_sensitive() */
1303 static void choose_selectall_activate(GtkWidget attribute((unused)) *w) {
1306 /** @brief Main menu callbacks for Choose screen */
1307 static const struct tabtype tabtype_choose = {
1308 choose_properties_sensitive,
1309 choose_selectall_sensitive,
1310 choose_properties_activate,
1311 choose_selectall_activate,
1314 /* Public entry points ----------------------------------------------------- */
1316 /** @brief Called to entirely reset the choose screen */
1317 static void choose_reset(void) {
1319 undisplay_tree(root);
1320 root = newnode(0/*parent*/, "<root>", "All files", "",
1321 CN_EXPANDABLE, fill_root_node);
1322 expand_node(root, 0); /* will call redisplay_tree */
1325 /** @brief Create a track choice widget */
1326 GtkWidget *choose_widget(void) {
1328 GtkWidget *scrolled;
1329 GtkWidget *vbox, *hbox, *clearsearch;
1332 * +--vbox-------------------------------------------------------+
1333 * | +-hbox----------------------------------------------------+ |
1334 * | | searchentry | clearsearch | |
1335 * | +---------------------------------------------------------+ |
1336 * | +-scrolled------------------------------------------------+ |
1337 * | | +-chooselayout------------------------------------++--+ | |
1338 * | | | Tree structure is manually layed out in here ||^^| | |
1343 * | | +-------------------------------------------------++--+ | |
1344 * | | +-------------------------------------------------+ | |
1346 * | | +-------------------------------------------------+ | |
1347 * | +---------------------------------------------------------+ |
1348 * +-------------------------------------------------------------+
1351 /* Text entry box for search terms */
1353 searchentry = gtk_entry_new();
1354 g_signal_connect(searchentry, "changed", G_CALLBACK(searchentry_changed), 0);
1355 gtk_tooltips_set_tip(tips, searchentry, "Enter search terms here; search is automatic", "");
1357 /* Cancel button to clear the search */
1359 clearsearch = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
1360 gtk_widget_modify_bg(clearsearch, GTK_STATE_NORMAL, &tool_bg);
1361 gtk_widget_modify_bg(clearsearch, GTK_STATE_ACTIVE, &tool_active);
1362 gtk_widget_modify_bg(clearsearch, GTK_STATE_PRELIGHT, &tool_active);
1363 gtk_widget_modify_bg(clearsearch, GTK_STATE_SELECTED, &tool_active);
1364 g_signal_connect(G_OBJECT(clearsearch), "clicked",
1365 G_CALLBACK(clearsearch_clicked), 0);
1366 gtk_tooltips_set_tip(tips, clearsearch, "Clear search terms", "");
1368 /* Up and down buttons to find previous/next results; initially they are not
1369 * usable as there are no search results. */
1370 prevsearch = iconbutton("up.png", "Previous search result");
1371 g_signal_connect(G_OBJECT(prevsearch), "clicked",
1372 G_CALLBACK(prev_clicked), 0);
1373 gtk_widget_set_sensitive(prevsearch, 0);
1374 gtk_widget_modify_bg(prevsearch, GTK_STATE_NORMAL, &tool_bg);
1375 gtk_widget_modify_bg(prevsearch, GTK_STATE_ACTIVE, &tool_active);
1376 gtk_widget_modify_bg(prevsearch, GTK_STATE_PRELIGHT, &tool_active);
1377 gtk_widget_modify_bg(prevsearch, GTK_STATE_SELECTED, &tool_active);
1378 gtk_widget_modify_bg(prevsearch, GTK_STATE_INSENSITIVE, &tool_active);
1379 nextsearch = iconbutton("down.png", "Next search result");
1380 g_signal_connect(G_OBJECT(nextsearch), "clicked",
1381 G_CALLBACK(next_clicked), 0);
1382 gtk_widget_set_sensitive(nextsearch, 0);
1383 gtk_widget_modify_bg(nextsearch, GTK_STATE_NORMAL, &tool_bg);
1384 gtk_widget_modify_bg(nextsearch, GTK_STATE_ACTIVE, &tool_active);
1385 gtk_widget_modify_bg(nextsearch, GTK_STATE_PRELIGHT, &tool_active);
1386 gtk_widget_modify_bg(nextsearch, GTK_STATE_SELECTED, &tool_active);
1387 gtk_widget_modify_bg(nextsearch, GTK_STATE_INSENSITIVE, &tool_active);
1389 /* hbox packs the search tools button together on a line */
1391 hbox = gtk_hbox_new(FALSE/*homogeneous*/, 1/*spacing*/);
1392 gtk_box_pack_start(GTK_BOX(hbox), searchentry,
1393 TRUE/*expand*/, TRUE/*fill*/, 0/*padding*/);
1394 gtk_box_pack_start(GTK_BOX(hbox), prevsearch,
1395 FALSE/*expand*/, FALSE/*fill*/, 0/*padding*/);
1396 gtk_box_pack_start(GTK_BOX(hbox), nextsearch,
1397 FALSE/*expand*/, FALSE/*fill*/, 0/*padding*/);
1398 gtk_box_pack_start(GTK_BOX(hbox), clearsearch,
1399 FALSE/*expand*/, FALSE/*fill*/, 0/*padding*/);
1401 /* chooselayout contains the currently visible subset of the track
1404 chooselayout = gtk_layout_new(0, 0);
1405 gtk_widget_modify_bg(chooselayout, GTK_STATE_NORMAL, &layout_bg);
1407 register_reset(choose_reset);
1408 /* Create the popup menus */
1410 track_menu = gtk_menu_new();
1411 g_signal_connect(track_menu, "destroy", G_CALLBACK(gtk_widget_destroyed),
1413 for(n = 0; track_menuitems[n].name; ++n) {
1415 track_menuitems[n].w =
1416 gtk_menu_item_new_with_label(track_menuitems[n].name);
1417 gtk_menu_attach(GTK_MENU(track_menu), track_menuitems[n].w,
1421 dir_menu = gtk_menu_new();
1422 g_signal_connect(dir_menu, "destroy", G_CALLBACK(gtk_widget_destroyed),
1424 for(n = 0; dir_menuitems[n].name; ++n) {
1426 dir_menuitems[n].w =
1427 gtk_menu_item_new_with_label(dir_menuitems[n].name);
1428 gtk_menu_attach(GTK_MENU(dir_menu), dir_menuitems[n].w,
1431 /* The layout is scrollable */
1432 scrolled = scroll_widget(chooselayout);
1433 vadjust = gtk_layout_get_vadjustment(GTK_LAYOUT(chooselayout));
1435 /* The scrollable layout and the search hbox go together in a vbox */
1437 vbox = gtk_vbox_new(FALSE/*homogenous*/, 1/*spacing*/);
1438 gtk_box_pack_start(GTK_BOX(vbox), hbox,
1439 FALSE/*expand*/, FALSE/*fill*/, 0/*padding*/);
1440 gtk_box_pack_end(GTK_BOX(vbox), scrolled,
1441 TRUE/*expand*/, TRUE/*fill*/, 0/*padding*/);
1443 g_object_set_data(G_OBJECT(vbox), "type", (void *)&tabtype_choose);
1447 /** @brief Called when something we care about here might have changed */
1448 void choose_update(void) {
1449 redisplay_tree("choose_update");
1457 indent-tabs-mode:nil