-/* Selection --------------------------------------------------------------- */
-
-static void display_selection(struct choosenode *cn) {
- /* Need foreground and background colors */
- gtk_widget_set_state(cn->label, (cn->flags & CN_SELECTED
- ? GTK_STATE_SELECTED : GTK_STATE_NORMAL));
- gtk_widget_set_state(cn->container, (cn->flags & CN_SELECTED
- ? GTK_STATE_SELECTED : GTK_STATE_NORMAL));
-}
-
-/* Set the selection state of a widget. Directories can never be selected, we
- * just ignore attempts to do so. */
-static void set_selection(struct choosenode *cn, int selected) {
- unsigned f = selected ? CN_SELECTED : 0;
-
- D(("set_selection %d %s", selected, cn->path));
- if(!(cn->flags & CN_EXPANDABLE) && (cn->flags & CN_SELECTED) != f) {
- cn->flags ^= CN_SELECTED;
- /* Maintain selection count */
- if(selected)
- ++files_selected;
- else
- --files_selected;
- display_selection(cn);
- /* Update main menu sensitivity */
- menu_update(-1);
- }
-}
-
-/* Recursively clear all selection bits from CN down */
-static void clear_selection(struct choosenode *cn) {
- int n;
-
- set_selection(cn, 0);
- for(n = 0; n < cn->children.nvec; ++n)
- clear_selection(cn->children.vec[n]);
-}
-
-/* User actions ------------------------------------------------------------ */
-
-/* Clicked on something */
-static void clicked_choosenode(GtkWidget attribute((unused)) *widget,
- GdkEventButton *event,
- gpointer user_data) {
- struct choosenode *cn = user_data;
- int ind, last_ind, n;
-
- D(("clicked_choosenode %s", cn->path));
- if(event->type == GDK_BUTTON_RELEASE
- && event->button == 1) {
- /* Left click */
- if(cn->flags & CN_EXPANDABLE) {
- /* This is a directory. Flip its expansion status. */
- if(cn->flags & CN_EXPANDED)
- contract_node(cn);
- else
- expand_node(cn);
- last_click = 0;
- } else {
- /* This is a file. Adjust selection status */
- /* TODO the basic logic here is essentially the same as that in queue.c.
- * Can we share code at all? */
- switch(event->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK)) {
- case 0:
- clear_selection(root);
- set_selection(cn, 1);
- last_click = cn;
- break;
- case GDK_CONTROL_MASK:
- set_selection(cn, !(cn->flags & CN_SELECTED));
- last_click = cn;
- break;
- case GDK_SHIFT_MASK:
- case GDK_SHIFT_MASK|GDK_CONTROL_MASK:
- if(last_click && last_click->parent == cn->parent) {
- /* Figure out where the current and last clicks are in the list */
- ind = last_ind = -1;
- for(n = 0; n < cn->parent->children.nvec; ++n) {
- if(cn->parent->children.vec[n] == cn)
- ind = n;
- if(cn->parent->children.vec[n] == last_click)
- last_ind = n;
- }
- /* Test shouldn't ever fail, but still */
- if(ind >= 0 && last_ind >= 0) {
- if(!(event->state & GDK_CONTROL_MASK)) {
- for(n = 0; n < cn->parent->children.nvec; ++n)
- set_selection(cn->parent->children.vec[n], 0);
- }
- if(ind > last_ind)
- for(n = last_ind; n <= ind; ++n)
- set_selection(cn->parent->children.vec[n], 1);
- else
- for(n = ind; n <= last_ind; ++n)
- set_selection(cn->parent->children.vec[n], 1);
- if(event->state & GDK_CONTROL_MASK)
- last_click = cn;
- }
- }
- break;
- }
- }
- } else if(event->type == GDK_BUTTON_RELEASE
- && event->button == 2) {
- /* Middle click - play the pointed track */
- if(!(cn->flags & CN_EXPANDABLE)) {
- clear_selection(root);
- set_selection(cn, 1);
- gtk_label_set_text(GTK_LABEL(report_label), "adding track to queue");
- disorder_eclient_play(client, cn->path, 0, 0);
- last_click = 0;
- }
- } else if(event->type == GDK_BUTTON_PRESS
- && event->button == 3) {
- /* Right click. Pop up a menu. */
- /* If the current file isn't selected, switch the selection to just that.
- * (If we're looking at a directory then leave the selection alone.) */
- if(!(cn->flags & CN_EXPANDABLE) && !(cn->flags & CN_SELECTED)) {
- clear_selection(root);
- set_selection(cn, 1);
- last_click = cn;
- }
- /* Set the item sensitivity and callbacks */
- for(n = 0; n < NMENUITEMS; ++n) {
- if(menuitems[n].handlerid)
- g_signal_handler_disconnect(menuitems[n].w,
- menuitems[n].handlerid);
- gtk_widget_set_sensitive(menuitems[n].w,
- menuitems[n].sensitive(cn));
- menuitems[n].handlerid = g_signal_connect
- (menuitems[n].w, "activate", G_CALLBACK(menuitems[n].activate), cn);
- }
- /* Pop up the menu */
- gtk_widget_show_all(menu);
- gtk_menu_popup(GTK_MENU(menu), 0, 0, 0, 0,
- event->button, event->time);