+
+/* handle both "select_row" and "unselect_row". note that we're using the
+ * entry box to put there the selected file names in. we're not using these
+ * entry box to get the selected file names. instead we use the clist selection.
+ * the entry box is used only to retrieve dir name. */
+static void filesel_file_list_select_row_multi(GtkCList *clist, gint row, gint col,
+ GdkEventButton *event, gpointer userdata)
+{
+ /* simple implementation in which we clear the file entry and refill it */
+ GList *list = clist->selection;
+ GtkEntry *entry = GTK_ENTRY(GTK_FILE_SELECTION(filesel)->selection_entry);
+
+ gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
+
+#define INVALID_FILENAME_CHARS " "
+ for (; list; list = list->next) {
+ gint row = GPOINTER_TO_INT(list->data);
+ gchar *text = NULL, *tmp;
+
+ if (!gtk_clist_get_text(clist, row, 0, &text))
+ break;
+
+ /* NOTE: quick glance in source code of GtkCList
+ * reveals we should not free the returned 'text' */
+
+ tmp = g_strconcat(text, " ", NULL);
+ text = tmp;
+ gtk_entry_append_text(entry, text);
+ g_free(text);
+ }
+#undef INVALID_FILENAME_CHARS
+}
+
+static void filesel_dir_list_select_row_multi(GtkCList *clist, gint row, gint col,
+ GdkEventButton *event, gpointer userdata)
+{
+ GtkEntry *entry = GTK_ENTRY(GTK_FILE_SELECTION(filesel)->selection_entry);
+ GtkCList *file_list = GTK_CLIST(GTK_FILE_SELECTION(filesel)->file_list);
+
+ /* if dir list is selected we clean everything */
+ gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
+ gtk_clist_unselect_all(file_list);
+}
+
+static void filesel_file_list_select_row_single(GtkCList *clist, gint row, gint col,
+ GdkEventButton *event, gpointer userdata)
+{
+ GtkEntry *entry = GTK_ENTRY(GTK_FILE_SELECTION(filesel)->selection_entry);
+
+ g_free(filesel_oldfilename);
+ filesel_oldfilename = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
+}
+
+static void filesel_dir_list_select_row_single(GtkCList *clist, gint row, gint col,
+ GdkEventButton *event, gpointer userdata)
+{
+ GtkEntry *entry = GTK_ENTRY(GTK_FILE_SELECTION(filesel)->selection_entry);
+
+ gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
+ if(filesel_oldfilename) {
+ gtk_entry_append_text(entry, filesel_oldfilename);
+ }
+}
+
+static GList *filesel_get_multiple_filenames(void)
+{
+ /* as noted before we are not using the entry text when selecting
+ * multiple files. to much hassle to parse out invalid chars (chars
+ * that need to be escaped). instead we use the file_list. the
+ * entry is only useful for extracting the current directory. */
+ GtkCList *file_list = GTK_CLIST(GTK_FILE_SELECTION(filesel)->file_list);
+ GtkEntry *file_entry = GTK_ENTRY(GTK_FILE_SELECTION(filesel)->selection_entry);
+ GList *list = NULL, *sel_list;
+ gchar *cwd, *tmp;
+ gboolean separator;
+
+ g_return_val_if_fail(file_list->selection != NULL, NULL);
+
+ tmp = gtk_file_selection_get_filename(GTK_FILE_SELECTION(filesel));
+ tmp = g_strdup(tmp);
+ cwd = g_dirname(tmp);
+ g_free(tmp);
+ g_return_val_if_fail(cwd != NULL, NULL);
+
+ /* only quick way to check the end of a multi byte string for our
+ * separator... */
+ g_strreverse(cwd);
+ separator = 0 == g_strncasecmp(cwd, G_DIR_SEPARATOR_S, strlen(G_DIR_SEPARATOR_S))
+ ? TRUE : FALSE;
+ g_strreverse(cwd);
+
+ /* fetch the selected file names */
+ for (sel_list = file_list->selection; sel_list; sel_list = sel_list->next) {
+ gint sel = GPOINTER_TO_INT(sel_list->data);
+ gchar *sel_text = NULL;
+ gchar *fname = NULL;
+
+ gtk_clist_get_text(file_list, sel, 0, &sel_text);
+ if (!sel_text) continue;
+ sel_text = g_strdup(sel_text);
+
+ if (separator)
+ fname = g_strconcat(cwd, sel_text, NULL);
+ else
+ fname = g_strconcat(cwd, G_DIR_SEPARATOR_S, sel_text, NULL);
+
+ list = g_list_append(list, fname);
+ g_free(sel_text);
+ }
+
+ return list;
+}
+