+}
+
+static gboolean
+check_completion_callback (GtkFileChooserEntry *chooser_entry)
+{
+ GDK_THREADS_ENTER ();
+
+ g_assert (chooser_entry->file_part);
+
+ chooser_entry->check_completion_idle = 0;
+
+ if (strcmp (chooser_entry->file_part, "") == 0)
+ goto done;
+
+ /* We only insert the common prefix without requiring the user to hit Tab in
+ * the "open" modes. For "save" modes, the user must hit Tab to cause the prefix
+ * to be inserted. That happens in gtk_file_chooser_entry_focus().
+ */
+ if (chooser_entry->action == GTK_FILE_CHOOSER_ACTION_OPEN
+ || chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+ append_common_prefix (chooser_entry, TRUE);
+
+ done:
+
+ GDK_THREADS_LEAVE ();
+
+ return FALSE;
+}
+
+static guint
+idle_add (GtkFileChooserEntry *chooser_entry,
+ GCallback cb)
+{
+ GSource *source;
+ guint id;
+
+ source = g_idle_source_new ();
+ g_source_set_priority (source, G_PRIORITY_HIGH);
+ g_source_set_closure (source,
+ g_cclosure_new_object (cb, G_OBJECT (chooser_entry)));
+ id = g_source_attach (source, NULL);
+ g_source_unref (source);
+
+ return id;
+}
+
+static void
+add_completion_idle (GtkFileChooserEntry *chooser_entry)
+{
+ /* idle to update the selection based on the file list */
+ if (chooser_entry->check_completion_idle == 0)
+ chooser_entry->check_completion_idle =
+ idle_add (chooser_entry, G_CALLBACK (check_completion_callback));
+}
+
+
+static void
+update_current_folder_files (GtkFileChooserEntry *chooser_entry,
+ GSList *added_uris)
+{
+ GSList *tmp_list;
+
+ g_assert (chooser_entry->completion_store != NULL);
+
+ /* Bah. Need to turn off sorting */
+ for (tmp_list = added_uris; tmp_list; tmp_list = tmp_list->next)
+ {
+ GtkFileInfo *info;
+ GtkFilePath *path;
+
+ path = tmp_list->data;
+
+ info = gtk_file_folder_get_info (chooser_entry->current_folder,
+ path,
+ NULL); /* NULL-GError */
+ if (info)
+ {
+ gchar *display_name = g_strdup (gtk_file_info_get_display_name (info));
+ GtkTreeIter iter;
+
+ display_name = maybe_append_separator_to_path (chooser_entry, path, display_name);
+
+ gtk_list_store_append (chooser_entry->completion_store, &iter);
+ gtk_list_store_set (chooser_entry->completion_store, &iter,
+ DISPLAY_NAME_COLUMN, display_name,
+ PATH_COLUMN, path,
+ -1);
+
+ gtk_file_info_free (info);
+ g_free (display_name);
+ }
+ }
+
+ /* FIXME: we want to turn off sorting temporarily. I suck... */
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (chooser_entry->completion_store),
+ DISPLAY_NAME_COLUMN, GTK_SORT_ASCENDING);
+
+ add_completion_idle (chooser_entry);
+}
+
+static void
+files_added_cb (GtkFileSystem *file_system,
+ GSList *added_uris,
+ GtkFileChooserEntry *chooser_entry)
+{
+ update_current_folder_files (chooser_entry, added_uris);
+}
+
+static void
+files_deleted_cb (GtkFileSystem *file_system,
+ GSList *deleted_uris,
+ GtkFileChooserEntry *chooser_entry)
+{
+ /* FIXME: gravy... */
+}
+
+static void
+load_directory_get_folder_callback (GtkFileSystemHandle *handle,
+ GtkFileFolder *folder,
+ const GError *error,
+ gpointer data)
+{
+ gboolean cancelled = handle->cancelled;
+ GtkFileChooserEntry *chooser_entry = data;
+
+ if (handle != chooser_entry->load_folder_handle)
+ goto out;
+
+ chooser_entry->load_folder_handle = NULL;
+
+ if (cancelled || error)
+ goto out;
+
+ chooser_entry->current_folder = folder;
+ g_signal_connect (chooser_entry->current_folder, "files-added",
+ G_CALLBACK (files_added_cb), chooser_entry);
+ g_signal_connect (chooser_entry->current_folder, "files-removed",
+ G_CALLBACK (files_deleted_cb), chooser_entry);