+/** @brief Called for key-*-event on the main view
+ */
+static gboolean choose_key_event(GtkWidget attribute((unused)) *widget,
+ GdkEventKey *event,
+ gpointer user_data) {
+ /*fprintf(stderr, "choose_key_event type=%d state=%#x keyval=%#x\n",
+ event->type, event->state, event->keyval);*/
+ switch(event->keyval) {
+ case GDK_Page_Up:
+ case GDK_Page_Down:
+ case GDK_Up:
+ case GDK_Down:
+ case GDK_Home:
+ case GDK_End:
+ return FALSE; /* We'll take these */
+ case 'f': case 'F':
+ /* ^F is expected to start a search. We implement this by focusing the
+ * search entry box. */
+ if((event->state & ~(GDK_LOCK_MASK|GDK_SHIFT_MASK)) == GDK_CONTROL_MASK
+ && event->type == GDK_KEY_PRESS) {
+ choose_search_new();
+ return TRUE; /* Handled it */
+ }
+ break;
+ case 'g': case 'G':
+ /* ^G is expected to go the next match. We simulate a click on the 'next'
+ * button. */
+ if((event->state & ~(GDK_LOCK_MASK|GDK_SHIFT_MASK)) == GDK_CONTROL_MASK
+ && event->type == GDK_KEY_PRESS) {
+ choose_next_clicked(0, 0);
+ return TRUE; /* Handled it */
+ }
+ break;
+ }
+ /* Anything not handled we redirected to the search entry field */
+ gtk_widget_event(user_data, (GdkEvent *)event);
+ return TRUE; /* Handled it */
+}
+
+static gboolean choose_multidrag_predicate(GtkTreePath attribute((unused)) *path,
+ GtkTreeIter *iter) {
+ return choose_is_file(iter);
+}
+
+
+/** @brief Callback to add selected tracks to the selection data
+ *
+ * Called from choose_drag_data_get().
+ */
+static void choose_drag_data_get_collect(GtkTreeModel attribute((unused)) *model,
+ GtkTreePath attribute((unused)) *path,
+ GtkTreeIter *iter,
+ gpointer data) {
+ struct dynstr *const result = data;
+
+ if(choose_is_file(iter)) { /* no diretories */
+ dynstr_append_string(result, ""); /* no ID */
+ dynstr_append(result, '\n');
+ dynstr_append_string(result, choose_get_track(iter));
+ dynstr_append(result, '\n');
+ }
+}
+
+/** @brief Called to extract the dragged data from the choose view
+ * @param w Source widget (the tree view)
+ * @param dc Drag context
+ * @param data Where to put the answer
+ * @param info_ Target @c info parameter
+ * @param time_ Time data requested (for some reason not a @c time_t)
+ * @param user_data The queuelike
+ *
+ * Closely analogous to ql_drag_data_get(), and uses the same data format.
+ * IDs are sent as empty strings.
+ */
+static void choose_drag_data_get(GtkWidget *w,
+ GdkDragContext attribute((unused)) *dc,
+ GtkSelectionData *data,
+ guint attribute((unused)) info_,
+ guint attribute((unused)) time_,
+ gpointer attribute((unused)) user_data) {
+ struct dynstr result[1];
+ GtkTreeSelection *sel;
+
+ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(w));
+ dynstr_init(result);
+ gtk_tree_selection_selected_foreach(sel,
+ choose_drag_data_get_collect,
+ result);
+ gtk_selection_data_set(data,
+ GDK_TARGET_STRING,
+ 8, (guchar *)result->vec, result->nvec);
+}
+