]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilechooserentry.c
filechooserentry: Keep an extra column for the full path
[~andy/gtk] / gtk / gtkfilechooserentry.c
index f2933a7ab7daa3e89ca6998395a5ff8c3675a3ba..fc2900b9b8085901426e2220de44994ebddad097 100644 (file)
 
 #include <string.h>
 
-#include "gtkalignment.h"
 #include "gtkcelllayout.h"
 #include "gtkcellrenderertext.h"
 #include "gtkentry.h"
+#include "gtkfilesystemmodel.h"
 #include "gtklabel.h"
 #include "gtkmain.h"
 #include "gtksizerequest.h"
 #include "gtkwindow.h"
 #include "gtkintl.h"
 
-#include "gdkkeysyms.h"
-
 typedef struct _GtkFileChooserEntryClass GtkFileChooserEntryClass;
 
 #define GTK_FILE_CHOOSER_ENTRY_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_ENTRY, GtkFileChooserEntryClass))
@@ -69,26 +67,21 @@ struct _GtkFileChooserEntry
 
   GtkFileChooserAction action;
 
-  GtkFileSystem *file_system;
   GFile *base_folder;
   GFile *current_folder_file;
+  gchar *dir_part;
   gchar *file_part;
   gint file_part_pos;
 
-  /* Folder being loaded or already loaded */
-  GtkFolder *current_folder;
-  GCancellable *load_folder_cancellable;
-
   LoadCompleteAction load_complete_action;
 
-  GtkListStore *completion_store;
-
-  guint start_autocompletion_idle_id;
+  GtkTreeModel *completion_store;
 
   GtkWidget *completion_feedback_window;
   GtkWidget *completion_feedback_label;
   guint completion_feedback_timeout_id;
 
+  guint current_folder_loaded : 1;
   guint has_completion : 1;
   guint in_change      : 1;
   guint eat_tabs       : 1;
@@ -98,6 +91,7 @@ struct _GtkFileChooserEntry
 enum
 {
   DISPLAY_NAME_COLUMN,
+  FULL_PATH_COLUMN,
   FILE_COLUMN,
   N_COLUMNS
 };
@@ -148,10 +142,6 @@ static gboolean completion_match_func     (GtkEntryCompletion  *comp,
                                           const char          *key,
                                           GtkTreeIter         *iter,
                                           gpointer             data);
-static char    *maybe_append_separator_to_file (GtkFileChooserEntry *chooser_entry,
-                                               GFile               *file,
-                                               gchar               *display_name,
-                                               gboolean            *appended);
 
 typedef enum {
   REFRESH_UP_TO_CURSOR_POSITION,
@@ -160,10 +150,11 @@ typedef enum {
 
 static RefreshStatus refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
                                                  RefreshMode refresh_mode);
-static void finished_loading_cb (GtkFolder *folder,
-                                gpointer   data);
+static void finished_loading_cb (GtkFileSystemModel  *model,
+                                 GError              *error,
+                                GtkFileChooserEntry *chooser_entry);
 static void autocomplete (GtkFileChooserEntry *chooser_entry);
-static void install_start_autocompletion_idle (GtkFileChooserEntry *chooser_entry);
+static void start_autocompletion (GtkFileChooserEntry *chooser_entry);
 static void remove_completion_feedback (GtkFileChooserEntry *chooser_entry);
 static void pop_up_completion_feedback (GtkFileChooserEntry *chooser_entry,
                                        const gchar         *feedback);
@@ -210,6 +201,7 @@ _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
   GtkCellRenderer *cell;
 
   chooser_entry->local_only = TRUE;
+  chooser_entry->base_folder = g_file_new_for_path (g_get_home_dir ());
 
   g_object_set (chooser_entry, "truncate-multiline", TRUE, NULL);
 
@@ -226,7 +218,7 @@ _gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
                               cell, TRUE);
   gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (comp),
                                  cell,
-                                 "text", 0);
+                                 "text", DISPLAY_NAME_COLUMN);
 
   g_signal_connect (comp, "match-selected",
                    G_CALLBACK (match_selected_callback), chooser_entry);
@@ -247,41 +239,20 @@ gtk_file_chooser_entry_finalize (GObject *object)
 {
   GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
 
-  if (chooser_entry->base_folder)
-    g_object_unref (chooser_entry->base_folder);
-
-  if (chooser_entry->current_folder)
-    g_object_unref (chooser_entry->current_folder);
+  g_object_unref (chooser_entry->base_folder);
 
   if (chooser_entry->current_folder_file)
     g_object_unref (chooser_entry->current_folder_file);
 
+  g_free (chooser_entry->dir_part);
   g_free (chooser_entry->file_part);
 
   G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->finalize (object);
 }
 
-static void
-discard_current_folder (GtkFileChooserEntry *chooser_entry)
-{
-  if (chooser_entry->current_folder)
-    {
-      g_signal_handlers_disconnect_by_func (chooser_entry->current_folder,
-                                           G_CALLBACK (finished_loading_cb), chooser_entry);
-      g_object_unref (chooser_entry->current_folder);
-      chooser_entry->current_folder = NULL;
-    }
-}
-
 static void
 discard_loading_and_current_folder_file (GtkFileChooserEntry *chooser_entry)
 {
-  if (chooser_entry->load_folder_cancellable)
-    {
-      g_cancellable_cancel (chooser_entry->load_folder_cancellable);
-      chooser_entry->load_folder_cancellable = NULL;
-    }
-
   if (chooser_entry->current_folder_file)
     {
       g_object_unref (chooser_entry->current_folder_file);
@@ -295,27 +266,14 @@ gtk_file_chooser_entry_dispose (GObject *object)
   GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (object);
 
   remove_completion_feedback (chooser_entry);
-  discard_current_folder (chooser_entry);
   discard_loading_and_current_folder_file (chooser_entry);
 
-  if (chooser_entry->start_autocompletion_idle_id != 0)
-    {
-      g_source_remove (chooser_entry->start_autocompletion_idle_id);
-      chooser_entry->start_autocompletion_idle_id = 0;
-    }
-
   if (chooser_entry->completion_store)
     {
       g_object_unref (chooser_entry->completion_store);
       chooser_entry->completion_store = NULL;
     }
 
-  if (chooser_entry->file_system)
-    {
-      g_object_unref (chooser_entry->file_system);
-      chooser_entry->file_system = NULL;
-    }
-
   G_OBJECT_CLASS (_gtk_file_chooser_entry_parent_class)->dispose (object);
 }
 
@@ -329,7 +287,6 @@ match_selected_callback (GtkEntryCompletion  *completion,
   char *display_name;
   GFile *file;
   gint pos;
-  gboolean dummy;
   
   gtk_tree_model_get (model, iter,
                      DISPLAY_NAME_COLUMN, &display_name,
@@ -338,14 +295,13 @@ match_selected_callback (GtkEntryCompletion  *completion,
 
   if (!display_name || !file)
     {
-      /* these shouldn't complain if passed NULL */
-      g_object_unref (file);
+      if (file)
+       g_object_unref (file);
+
       g_free (display_name);
       return FALSE;
     }
 
-  display_name = maybe_append_separator_to_file (chooser_entry, file, display_name, &dummy);
-
   pos = chooser_entry->file_part_pos;
 
   /* We don't set in_change here as we want to update the current_folder
@@ -371,7 +327,7 @@ completion_match_func (GtkEntryCompletion *comp,
                       gpointer            data)
 {
   GtkFileChooserEntry *chooser_entry;
-  char *name;
+  char *name = NULL;
   gboolean result;
   char *norm_file_part;
   char *norm_name;
@@ -386,7 +342,7 @@ completion_match_func (GtkEntryCompletion *comp,
       return FALSE;
     }
 
-  gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store), iter, DISPLAY_NAME_COLUMN, &name, -1);
+  gtk_tree_model_get (chooser_entry->completion_store, iter, DISPLAY_NAME_COLUMN, &name, -1);
   if (!name)
     {
       return FALSE; /* Uninitialized row, ugh */
@@ -450,57 +406,125 @@ beep (GtkFileChooserEntry *chooser_entry)
   gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
 }
 
-/* This function will append a directory separator to paths to
- * display_name iff the path associated with it is a directory.
- * maybe_append_separator_to_file will g_free the display_name and
- * return a new one if needed.  Otherwise, it will return the old one.
- * You should be safe calling
- *
- * display_name = maybe_append_separator_to_file (entry, file, display_name, &appended);
- * ...
- * g_free (display_name);
- */
-static char *
-maybe_append_separator_to_file (GtkFileChooserEntry *chooser_entry,
-                               GFile               *file,
-                               gchar               *display_name,
-                               gboolean            *appended)
+static gboolean
+is_valid_scheme_character (char c)
 {
-  *appended = FALSE;
+  return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
+}
 
-  if (!g_str_has_suffix (display_name, G_DIR_SEPARATOR_S) && file)
-    {
-      GFileInfo *info;
+static gboolean
+has_uri_scheme (const char *str)
+{
+  const char *p;
 
-      info = _gtk_folder_get_info (chooser_entry->current_folder, file);
+  p = str;
 
-      if (info)
-       {
-         if (_gtk_file_info_consider_as_directory (info))
-           {
-             gchar *tmp = display_name;
-             display_name = g_strconcat (tmp, G_DIR_SEPARATOR_S, NULL);
-             *appended = TRUE;
-             g_free (tmp);
-           }
+  if (!is_valid_scheme_character (*p))
+    return FALSE;
 
-         g_object_unref (info);
-       }
-    }
+  do
+    p++;
+  while (is_valid_scheme_character (*p));
 
-  return display_name;
+  return (strncmp (p, "://", 3) == 0);
 }
 
-static char *
-trim_dir_separator_suffix (const char *str)
+static GFile *
+gtk_file_chooser_get_file_for_text (GtkFileChooserEntry *chooser_entry,
+                                    const gchar         *str)
 {
-  int len;
+  GFile *file;
 
-  len = strlen (str);
-  if (len > 0 && G_IS_DIR_SEPARATOR (str[len - 1]))
-    return g_strndup (str, len - 1);
+  if (str[0] == '~' || g_path_is_absolute (str) || has_uri_scheme (str))
+    file = g_file_parse_name (str);
   else
-    return g_strdup (str);
+    file = g_file_resolve_relative_path (chooser_entry->base_folder, str);
+
+  return file;
+}
+
+static GFile *
+gtk_file_chooser_get_directory_for_text (GtkFileChooserEntry *chooser_entry,
+                                         const char *         text)
+{
+  GFile *file, *parent;
+
+  file = gtk_file_chooser_get_file_for_text (chooser_entry, text);
+
+  if (text[0] == 0 || text[strlen (text) - 1] == G_DIR_SEPARATOR)
+    return file;
+
+  parent = g_file_get_parent (file);
+  g_object_unref (file);
+
+  return parent;
+}
+
+static gboolean
+gtk_file_chooser_entry_parse (GtkFileChooserEntry  *chooser_entry,
+                              const gchar          *str,
+                              GFile               **folder,
+                              gchar               **file_part,
+                              GError              **error)
+{
+  GFile *file;
+  gboolean result = FALSE;
+  gboolean is_dir = FALSE;
+  gchar *last_slash = NULL;
+
+  if (str && *str)
+    is_dir = (str [strlen (str) - 1] == G_DIR_SEPARATOR);
+
+  last_slash = strrchr (str, G_DIR_SEPARATOR);
+
+  file = gtk_file_chooser_get_file_for_text (chooser_entry, str);
+
+  if (g_file_equal (chooser_entry->base_folder, file))
+    {
+      /* this is when user types '.', could be the
+       * beginning of a hidden file, ./ or ../
+       */
+      *folder = g_object_ref (file);
+      *file_part = g_strdup (str);
+      result = TRUE;
+    }
+  else if (is_dir)
+    {
+      /* it's a dir, or at least it ends with the dir separator */
+      *folder = g_object_ref (file);
+      *file_part = g_strdup ("");
+      result = TRUE;
+    }
+  else
+    {
+      GFile *parent_file;
+
+      parent_file = g_file_get_parent (file);
+
+      if (!parent_file)
+       {
+         g_set_error (error,
+                      GTK_FILE_CHOOSER_ERROR,
+                      GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
+                      "Could not get parent file");
+         *folder = NULL;
+         *file_part = NULL;
+       }
+      else
+       {
+         *folder = parent_file;
+         result = TRUE;
+
+         if (last_slash)
+           *file_part = g_strdup (last_slash + 1);
+         else
+           *file_part = g_strdup (str);
+       }
+    }
+
+  g_object_unref (file);
+
+  return result;
 }
 
 /* Determines if the completion model has entries with a common prefix relative
@@ -532,12 +556,11 @@ find_common_prefix (GtkFileChooserEntry *chooser_entry,
 
   text_up_to_cursor = gtk_editable_get_chars (editable, 0, gtk_editable_get_position (editable));
 
-  parsed = _gtk_file_system_parse (chooser_entry->file_system,
-                                  chooser_entry->base_folder,
-                                  text_up_to_cursor,
-                                  &parsed_folder_file,
-                                  &parsed_file_part,
-                                  error);
+  parsed = gtk_file_chooser_entry_parse (chooser_entry,
+                                         text_up_to_cursor,
+                                         &parsed_folder_file,
+                                         &parsed_file_part,
+                                         error);
 
   g_free (text_up_to_cursor);
 
@@ -545,21 +568,20 @@ find_common_prefix (GtkFileChooserEntry *chooser_entry,
     return FALSE;
 
   g_assert (parsed_folder_file != NULL
-           && chooser_entry->current_folder != NULL
            && g_file_equal (parsed_folder_file, chooser_entry->current_folder_file));
 
   g_object_unref (parsed_folder_file);
 
   /* First pass: find the common prefix */
 
-  valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (chooser_entry->completion_store), &iter);
+  valid = gtk_tree_model_get_iter_first (chooser_entry->completion_store, &iter);
 
   while (valid)
     {
       gchar *display_name;
       GFile *file;
 
-      gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store),
+      gtk_tree_model_get (chooser_entry->completion_store,
                          &iter,
                          DISPLAY_NAME_COLUMN, &display_name,
                          FILE_COLUMN, &file,
@@ -569,7 +591,7 @@ find_common_prefix (GtkFileChooserEntry *chooser_entry,
        {
          if (!*common_prefix_ret)
            {
-             *common_prefix_ret = trim_dir_separator_suffix (display_name);
+             *common_prefix_ret = g_strdup (display_name);
              *unique_file_ret = g_object_ref (file);
            }
          else
@@ -595,21 +617,21 @@ find_common_prefix (GtkFileChooserEntry *chooser_entry,
 
       g_free (display_name);
       g_object_unref (file);
-      valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser_entry->completion_store), &iter);
+      valid = gtk_tree_model_iter_next (chooser_entry->completion_store, &iter);
     }
 
   /* Second pass: see if the prefix we found is a complete match */
 
   if (*common_prefix_ret != NULL)
     {
-      valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (chooser_entry->completion_store), &iter);
+      valid = gtk_tree_model_get_iter_first (chooser_entry->completion_store, &iter);
 
       while (valid)
        {
          gchar *display_name;
          int len;
 
-         gtk_tree_model_get (GTK_TREE_MODEL (chooser_entry->completion_store),
+         gtk_tree_model_get (chooser_entry->completion_store,
                              &iter,
                              DISPLAY_NAME_COLUMN, &display_name,
                              -1);
@@ -623,7 +645,7 @@ find_common_prefix (GtkFileChooserEntry *chooser_entry,
            *is_complete_not_unique_ret = TRUE;
 
          g_free (display_name);
-         valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser_entry->completion_store), &iter);
+         valid = gtk_tree_model_iter_next (chooser_entry->completion_store, &iter);
        }
 
       /* Finally:  Did we generate a new completion, or was the user's input already completed as far as it could go? */
@@ -636,29 +658,6 @@ find_common_prefix (GtkFileChooserEntry *chooser_entry,
   return TRUE;
 }
 
-static gboolean
-char_after_cursor_is_directory_separator (GtkFileChooserEntry *chooser_entry)
-{
-  int cursor_pos;
-  gboolean result;
-
-  result = FALSE;
-
-  cursor_pos = gtk_editable_get_position (GTK_EDITABLE (chooser_entry));
-  if (cursor_pos < gtk_entry_get_text_length (GTK_ENTRY (chooser_entry)))
-    {
-      char *next_char_str;
-
-      next_char_str = gtk_editable_get_chars (GTK_EDITABLE (chooser_entry), cursor_pos, cursor_pos + 1);
-      if (G_IS_DIR_SEPARATOR (*next_char_str))
-       result = TRUE;
-
-      g_free (next_char_str);
-    }
-
-  return result;
-}
-
 typedef enum {
   INVALID_INPUT,               /* what the user typed is bogus */
   NO_MATCH,                    /* no matches based on what the user typed */
@@ -669,11 +668,13 @@ typedef enum {
   COMPLETE_BUT_NOT_UNIQUE      /* completion inserted, it is a complete name but not unique */
 } CommonPrefixResult;
 
-/* Finds a common prefix based on the contents of the entry and mandatorily appends it */
+/* Finds a common prefix based on the contents of the entry
+ * and mandatorily appends it
+ */
 static CommonPrefixResult
 append_common_prefix (GtkFileChooserEntry *chooser_entry,
-                     gboolean             highlight,
-                     gboolean             show_errors)
+                      gboolean             highlight,
+                      gboolean             show_errors)
 {
   gchar *common_prefix;
   GFile *unique_file;
@@ -691,17 +692,6 @@ append_common_prefix (GtkFileChooserEntry *chooser_entry,
   error = NULL;
   if (!find_common_prefix (chooser_entry, &common_prefix, &unique_file, &is_complete_not_unique, &prefix_expands_the_file_part, &error))
     {
-      /* If the user types an incomplete hostname ("http://foo" without a slash
-       * after that), it's not an error.  We just don't want to pop up a
-       * meaningless completion window in that state.
-       */
-      if (!g_error_matches (error, GTK_FILE_CHOOSER_ERROR, GTK_FILE_CHOOSER_ERROR_INCOMPLETE_HOSTNAME)
-         && show_errors)
-       {
-         beep (chooser_entry);
-         pop_up_completion_feedback (chooser_entry, _("Invalid path"));
-       }
-
       g_error_free (error);
 
       return INVALID_INPUT;
@@ -711,86 +701,73 @@ append_common_prefix (GtkFileChooserEntry *chooser_entry,
 
   if (unique_file)
     {
-      if (!char_after_cursor_is_directory_separator (chooser_entry))
-       {
-         gboolean appended;
-
-         common_prefix = maybe_append_separator_to_file (chooser_entry,
-                                                         unique_file,
-                                                         common_prefix,
-                                                         &appended);
-         if (appended)
-           prefix_expands_the_file_part = TRUE;
-       }
-
       g_object_unref (unique_file);
 
       if (prefix_expands_the_file_part)
-       result = COMPLETED_UNIQUE;
+        result = COMPLETED_UNIQUE;
       else
-       result = NOTHING_INSERTED_UNIQUE;
+        result = NOTHING_INSERTED_UNIQUE;
 
       have_result = TRUE;
     }
   else
     {
       if (is_complete_not_unique)
-       {
-         result = COMPLETE_BUT_NOT_UNIQUE;
-         have_result = TRUE;
-       }
+        {
+          result = COMPLETE_BUT_NOT_UNIQUE;
+          have_result = TRUE;
+        }
     }
 
   if (common_prefix)
     {
       gint cursor_pos;
-      gint common_prefix_len;
       gint pos;
 
       cursor_pos = gtk_editable_get_position (GTK_EDITABLE (chooser_entry));
-      common_prefix_len = g_utf8_strlen (common_prefix, -1);
 
       pos = chooser_entry->file_part_pos;
 
       if (prefix_expands_the_file_part)
-       {
-         chooser_entry->in_change = TRUE;
-         gtk_editable_delete_text (GTK_EDITABLE (chooser_entry),
-                                   pos, cursor_pos);
-         gtk_editable_insert_text (GTK_EDITABLE (chooser_entry),
-                                   common_prefix, -1, 
-                                   &pos);
-         chooser_entry->in_change = FALSE;
-
-         if (highlight)
-           {
-             gtk_editable_select_region (GTK_EDITABLE (chooser_entry),
-                                         cursor_pos,
-                                         pos); /* equivalent to cursor_pos + common_prefix_len); */
-             chooser_entry->has_completion = TRUE;
-           }
-         else
-           gtk_editable_set_position (GTK_EDITABLE (chooser_entry), pos);
-       }
+        {
+          chooser_entry->in_change = TRUE;
+          gtk_editable_delete_text (GTK_EDITABLE (chooser_entry),
+                                    pos, cursor_pos);
+          gtk_editable_insert_text (GTK_EDITABLE (chooser_entry),
+                                    common_prefix, -1,
+                                    &pos);
+          chooser_entry->in_change = FALSE;
+
+          if (highlight)
+            {
+              /* equivalent to cursor_pos + common_prefix_len); */
+              gtk_editable_select_region (GTK_EDITABLE (chooser_entry),
+                                          cursor_pos,
+                                          pos);
+              chooser_entry->has_completion = TRUE;
+            }
+          else
+            gtk_editable_set_position (GTK_EDITABLE (chooser_entry), pos);
+        }
       else if (!have_result)
-       {
-         result = NOTHING_INSERTED_COMPLETE;
-         have_result = TRUE;
-       }
+        {
+          result = NOTHING_INSERTED_COMPLETE;
+          have_result = TRUE;
+        }
 
       g_free (common_prefix);
 
       if (have_result)
-       return result;
+        return result;
       else
-       return COMPLETED;
+        return COMPLETED;
     }
   else
     {
       if (have_result)
-       return result;
+        return result;
       else
-       return NO_MATCH;
+        return NO_MATCH;
     }
 }
 
@@ -817,7 +794,7 @@ gtk_file_chooser_entry_do_insert_text (GtkEditable *editable,
   if ((chooser_entry->action == GTK_FILE_CHOOSER_ACTION_OPEN
        || chooser_entry->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
       && insert_pos == old_text_len)
-    install_start_autocompletion_idle (chooser_entry);
+    start_autocompletion (chooser_entry);
 }
 
 static void
@@ -932,42 +909,37 @@ static void
 create_completion_feedback_window (GtkFileChooserEntry *chooser_entry)
 {
   /* Stolen from gtk_tooltip_init() */
-
+  GtkWidget *window, *label;
   GtkStyleContext *context;
-  GtkWidget *alignment;
-  GtkBorder padding, border;
 
-  chooser_entry->completion_feedback_window = gtk_window_new (GTK_WINDOW_POPUP);
-  gtk_window_set_type_hint (GTK_WINDOW (chooser_entry->completion_feedback_window),
-                           GDK_WINDOW_TYPE_HINT_TOOLTIP);
-  gtk_widget_set_app_paintable (chooser_entry->completion_feedback_window, TRUE);
-  gtk_window_set_resizable (GTK_WINDOW (chooser_entry->completion_feedback_window), FALSE);
-  gtk_widget_set_name (chooser_entry->completion_feedback_window, "gtk-tooltip");
+  window = gtk_window_new (GTK_WINDOW_POPUP);
+  gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_TOOLTIP);
+  gtk_widget_set_app_paintable (window, TRUE);
+  gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
+  gtk_widget_set_name (window, "gtk-tooltip");
 
-  alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
-  context = gtk_widget_get_style_context (chooser_entry->completion_feedback_window);
+  context = gtk_widget_get_style_context (window);
   gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOOLTIP);
 
-  gtk_style_context_get_padding (context, 0, &padding);
-  gtk_style_context_get_border (context, 0, &border);
-
-  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
-                             border.top + padding.top,
-                             border.bottom + padding.bottom,
-                             border.left + padding.left,
-                             border.right + padding.right);
-  gtk_container_add (GTK_CONTAINER (chooser_entry->completion_feedback_window), alignment);
-  gtk_widget_show (alignment);
-
-  g_signal_connect (chooser_entry->completion_feedback_window, "draw",
-                   G_CALLBACK (completion_feedback_window_draw_cb), chooser_entry);
-  g_signal_connect (chooser_entry->completion_feedback_window, "realize",
-                   G_CALLBACK (completion_feedback_window_realize_cb), chooser_entry);
+  g_signal_connect (window, "draw",
+                    G_CALLBACK (completion_feedback_window_draw_cb), chooser_entry);
+  g_signal_connect (window, "realize",
+                    G_CALLBACK (completion_feedback_window_realize_cb), chooser_entry);
   /* FIXME: connect to motion-notify-event, and *show* the cursor when the mouse moves */
 
-  chooser_entry->completion_feedback_label = gtk_label_new (NULL);
-  gtk_container_add (GTK_CONTAINER (alignment), chooser_entry->completion_feedback_label);
-  gtk_widget_show (chooser_entry->completion_feedback_label);
+  label = gtk_label_new (NULL);
+  gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
+  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+  /* FIXME: don't hardcode this */
+  gtk_widget_set_margin_left (label, 6);
+  gtk_widget_set_margin_right (label, 6);
+  gtk_widget_set_margin_top (label, 6);
+  gtk_widget_set_margin_bottom (label, 6);
+  gtk_container_add (GTK_CONTAINER (window), label);
+  gtk_widget_show (label);
+
+  chooser_entry->completion_feedback_window = window;
+  chooser_entry->completion_feedback_label = label;
 }
 
 static gboolean
@@ -1086,8 +1058,7 @@ explicitly_complete (GtkFileChooserEntry *chooser_entry)
 {
   CommonPrefixResult result;
 
-  g_assert (chooser_entry->current_folder != NULL);
-  g_assert (_gtk_folder_is_finished_loading (chooser_entry->current_folder));
+  g_assert (chooser_entry->current_folder_loaded);
 
   /* FIXME: see what Emacs does in case there is no common prefix, or there is more than one match:
    *
@@ -1160,7 +1131,7 @@ start_explicit_completion (GtkFileChooserEntry *chooser_entry)
     case REFRESH_OK:
       g_assert (chooser_entry->current_folder_file != NULL);
 
-      if (chooser_entry->current_folder && _gtk_folder_is_finished_loading (chooser_entry->current_folder))
+      if (chooser_entry->current_folder_loaded)
        explicitly_complete (chooser_entry);
       else
        {
@@ -1318,57 +1289,68 @@ discard_completion_store (GtkFileChooserEntry *chooser_entry)
   chooser_entry->completion_store = NULL;
 }
 
-/* Fills the completion store from the contents of the current folder */
-static void
-populate_completion_store (GtkFileChooserEntry *chooser_entry)
+static gboolean
+completion_store_set (GtkFileSystemModel  *model,
+                      GFile               *file,
+                      GFileInfo           *info,
+                      int                  column,
+                      GValue              *value,
+                      gpointer             data)
 {
-  GSList *files;
-  GSList *tmp_list;
-
-  discard_completion_store (chooser_entry);
-
-  files = _gtk_folder_list_children (chooser_entry->current_folder);
+  GtkFileChooserEntry *chooser_entry = data;
 
-  chooser_entry->completion_store = gtk_list_store_new (N_COLUMNS,
-                                                       G_TYPE_STRING,
-                                                       G_TYPE_FILE);
+  const char *prefix = "";
+  const char *suffix = "";
 
-  for (tmp_list = files; tmp_list; tmp_list = tmp_list->next)
+  switch (column)
     {
-      GFileInfo *info;
-      GFile *file;
-
-      file = tmp_list->data;
-
-      info = _gtk_folder_get_info (chooser_entry->current_folder, file);
-
-      if (info)
-       {
-         gchar *display_name = g_strdup (g_file_info_get_display_name (info));
-         GtkTreeIter iter;
-         gboolean dummy;
-
-          display_name = maybe_append_separator_to_file (chooser_entry, file, display_name, &dummy);
+    case FILE_COLUMN:
+      g_value_set_object (value, file);
+      break;
+    case FULL_PATH_COLUMN:
+      prefix = chooser_entry->dir_part;
+      /* fall through */
+    case DISPLAY_NAME_COLUMN:
+      if (_gtk_file_info_consider_as_directory (info))
+        suffix = G_DIR_SEPARATOR_S;
+
+      g_value_take_string (value, g_strconcat (
+              prefix,
+              g_file_info_get_display_name (info),
+              suffix,
+              NULL));
+      break;
+    default:
+      g_assert_not_reached ();
+      break;
+    }
 
-         gtk_list_store_append (chooser_entry->completion_store, &iter);
-         gtk_list_store_set (chooser_entry->completion_store, &iter,
-                             DISPLAY_NAME_COLUMN, display_name,
-                             FILE_COLUMN, file,
-                             -1);
+  return TRUE;
+}
 
-         g_object_unref (info);
-          g_free (display_name);
-       }
-    }
+/* Fills the completion store from the contents of the current folder */
+static void
+populate_completion_store (GtkFileChooserEntry *chooser_entry)
+{
+  discard_completion_store (chooser_entry);
 
-  g_slist_foreach (files, (GFunc) g_object_unref, NULL);
-  g_slist_free (files);
+  chooser_entry->completion_store = GTK_TREE_MODEL (
+      _gtk_file_system_model_new_for_directory (chooser_entry->current_folder_file,
+                                                "standard::name,standard::display-name,standard::type",
+                                                completion_store_set,
+                                                chooser_entry,
+                                                N_COLUMNS,
+                                                G_TYPE_STRING,
+                                                G_TYPE_STRING,
+                                                G_TYPE_FILE));
+  g_signal_connect (chooser_entry->completion_store, "finished-loading",
+                   G_CALLBACK (finished_loading_cb), chooser_entry);
 
   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (chooser_entry->completion_store),
                                        DISPLAY_NAME_COLUMN, GTK_SORT_ASCENDING);
 
   gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
-                                 GTK_TREE_MODEL (chooser_entry->completion_store));
+                                 chooser_entry->completion_store);
 }
 
 /* When we finish loading the current folder, this function should get called to
@@ -1400,7 +1382,6 @@ perform_load_complete_action (GtkFileChooserEntry *chooser_entry)
 static void
 finish_folder_load (GtkFileChooserEntry *chooser_entry)
 {
-  populate_completion_store (chooser_entry);
   perform_load_complete_action (chooser_entry);
 
   gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_entry), NULL);
@@ -1408,28 +1389,11 @@ finish_folder_load (GtkFileChooserEntry *chooser_entry)
 
 /* Callback when the current folder finishes loading */
 static void
-finished_loading_cb (GtkFolder *folder,
-                    gpointer   data)
+finished_loading_cb (GtkFileSystemModel  *model,
+                     GError              *error,
+                    GtkFileChooserEntry *chooser_entry)
 {
-  GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (data);
-
-  finish_folder_load (chooser_entry);
-}
-
-/* Callback when the current folder's handle gets obtained (not necessarily loaded completely) */
-static void
-load_directory_get_folder_callback (GCancellable  *cancellable,
-                                   GtkFolder     *folder,
-                                   const GError  *error,
-                                   gpointer       data)
-{
-  gboolean cancelled = g_cancellable_is_cancelled (cancellable);
-  GtkFileChooserEntry *chooser_entry = data;
-
-  if (cancellable != chooser_entry->load_folder_cancellable)
-    goto out;
-
-  chooser_entry->load_folder_cancellable = NULL;
+  chooser_entry->current_folder_loaded = TRUE;
 
   if (error)
     {
@@ -1448,90 +1412,37 @@ load_directory_get_folder_callback (GCancellable  *cancellable,
          pop_up_completion_feedback (chooser_entry, error->message);
        }
 
-      discard_current_folder (chooser_entry);
-    }
-
-  if (cancelled || error)
-    goto out;
-
-  g_assert (folder != NULL);
-  chooser_entry->current_folder = g_object_ref (folder);
-
-  discard_completion_store (chooser_entry);
-
-  if (_gtk_folder_is_finished_loading (chooser_entry->current_folder))
-    finish_folder_load (chooser_entry);
-  else
-    g_signal_connect (chooser_entry->current_folder, "finished-loading",
-                     G_CALLBACK (finished_loading_cb), chooser_entry);
-
-out:
-  g_object_unref (chooser_entry);
-  g_object_unref (cancellable);
-}
-
-static RefreshStatus
-start_loading_current_folder (GtkFileChooserEntry *chooser_entry)
-{
-  if (chooser_entry->file_system == NULL)
-    return REFRESH_OK;
-
-  g_assert (chooser_entry->current_folder_file != NULL);
-  g_assert (chooser_entry->current_folder == NULL);
-  g_assert (chooser_entry->load_folder_cancellable == NULL);
-
-  if (chooser_entry->local_only
-      && !g_file_is_native (chooser_entry->current_folder_file))
-    {
-      g_object_unref (chooser_entry->current_folder_file);
-      chooser_entry->current_folder_file = NULL;
-
-      return REFRESH_NOT_LOCAL;
+      return;
     }
 
-  chooser_entry->load_folder_cancellable =
-    _gtk_file_system_get_folder (chooser_entry->file_system,
-                                chooser_entry->current_folder_file,
-                               "standard::name,standard::display-name,standard::type",
-                                load_directory_get_folder_callback,
-                                g_object_ref (chooser_entry));
-
-  return REFRESH_OK;
+  finish_folder_load (chooser_entry);
 }
 
 static RefreshStatus
 reload_current_folder (GtkFileChooserEntry *chooser_entry,
-                      GFile               *folder_file,
-                      gboolean             force_reload)
+                      GFile               *folder_file)
 {
-  gboolean reload = FALSE;
-
   g_assert (folder_file != NULL);
 
+  if (chooser_entry->current_folder_file
+      && g_file_equal (folder_file, chooser_entry->current_folder_file))
+    return REFRESH_OK;
+
   if (chooser_entry->current_folder_file)
     {
-      if ((!(g_file_equal (folder_file, chooser_entry->current_folder_file)
-            && chooser_entry->load_folder_cancellable))
-         || force_reload)
-       {
-         reload = TRUE;
+      discard_loading_and_current_folder_file (chooser_entry);
+    }
+  
+  if (chooser_entry->local_only
+      && !g_file_is_native (folder_file))
+    return REFRESH_NOT_LOCAL;
 
-          discard_current_folder (chooser_entry);
-         discard_loading_and_current_folder_file (chooser_entry);
+  chooser_entry->current_folder_file = g_object_ref (folder_file);
+  chooser_entry->current_folder_loaded = FALSE;
 
-         chooser_entry->current_folder_file = g_object_ref (folder_file);
-       }
-    }
-  else
-    {
-      chooser_entry->current_folder_file = g_object_ref (folder_file);
-      reload = TRUE;
-    }
+  populate_completion_store (chooser_entry);
 
-  if (reload)
-    return start_loading_current_folder (chooser_entry);
-  else
-    return REFRESH_OK;
+  return REFRESH_OK;
 }
 
 static RefreshStatus
@@ -1568,26 +1479,15 @@ refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
   text = gtk_editable_get_chars (editable, 0, end_pos);
 
   error = NULL;
-  if (!chooser_entry->file_system ||
-      !chooser_entry->base_folder ||
-      !_gtk_file_system_parse (chooser_entry->file_system,
-                              chooser_entry->base_folder, text,
-                              &folder_file, &file_part, &error))
+  if (!gtk_file_chooser_entry_parse (chooser_entry,
+                                    text, &folder_file, &file_part, &error))
     {
-      if (g_error_matches (error, GTK_FILE_CHOOSER_ERROR, GTK_FILE_CHOOSER_ERROR_INCOMPLETE_HOSTNAME))
-       {
-         folder_file = NULL;
-         result = REFRESH_INCOMPLETE_HOSTNAME;
-       }
-      else
-       {
-         folder_file = (chooser_entry->base_folder) ? g_object_ref (chooser_entry->base_folder) : NULL;
+      folder_file = g_object_ref (chooser_entry->base_folder);
 
-         if (g_error_matches (error, GTK_FILE_CHOOSER_ERROR, GTK_FILE_CHOOSER_ERROR_NONEXISTENT))
-           result = REFRESH_NONEXISTENT;
-         else
-           result = REFRESH_INVALID_INPUT;
-       }
+      if (g_error_matches (error, GTK_FILE_CHOOSER_ERROR, GTK_FILE_CHOOSER_ERROR_NONEXISTENT))
+        result = REFRESH_NONEXISTENT;
+      else
+       result = REFRESH_INVALID_INPUT;
 
       if (error)
        g_error_free (error);
@@ -1609,20 +1509,21 @@ refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
       result = REFRESH_OK;
     }
 
-  g_free (text);
-
   g_free (chooser_entry->file_part);
+  g_free (chooser_entry->dir_part);
 
+  chooser_entry->dir_part = file_part_pos > 0 ? g_strndup (text, file_part_pos) : g_strdup ("");
   chooser_entry->file_part = file_part;
   chooser_entry->file_part_pos = file_part_pos;
 
+  g_free (text);
+
   if (result == REFRESH_OK)
     {
-      result = reload_current_folder (chooser_entry, folder_file, file_part_pos == -1);
+      result = reload_current_folder (chooser_entry, folder_file);
     }
   else
     {
-      discard_current_folder (chooser_entry);
       discard_loading_and_current_folder_file (chooser_entry);
     }
 
@@ -1631,14 +1532,10 @@ refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
 
   g_assert (/* we are OK and we have a current folder file and (loading process or folder handle)... */
            ((result == REFRESH_OK)
-            && (chooser_entry->current_folder_file != NULL)
-            && (((chooser_entry->load_folder_cancellable != NULL) && (chooser_entry->current_folder == NULL))
-                || ((chooser_entry->load_folder_cancellable == NULL) && (chooser_entry->current_folder != NULL))))
+            && (chooser_entry->current_folder_file != NULL))
            /* ... OR we have an error, and we don't have a current folder file nor a loading process nor a folder handle */
            || ((result != REFRESH_OK)
-               && (chooser_entry->current_folder_file == NULL)
-               && (chooser_entry->load_folder_cancellable == NULL)
-               && (chooser_entry->current_folder == NULL)));
+               && (chooser_entry->current_folder_file == NULL)));
 
   return result;
 }
@@ -1646,8 +1543,7 @@ refresh_current_folder_and_file_part (GtkFileChooserEntry *chooser_entry,
 static void
 autocomplete (GtkFileChooserEntry *chooser_entry)
 {
-  if (!(chooser_entry->current_folder != NULL
-       && _gtk_folder_is_finished_loading (chooser_entry->current_folder)
+  if (!(chooser_entry->current_folder_loaded
        && gtk_editable_get_position (GTK_EDITABLE (chooser_entry)) == gtk_entry_get_text_length (GTK_ENTRY (chooser_entry))))
     return;
 
@@ -1666,7 +1562,7 @@ start_autocompletion (GtkFileChooserEntry *chooser_entry)
     case REFRESH_OK:
       g_assert (chooser_entry->current_folder_file != NULL);
 
-      if (chooser_entry->current_folder && _gtk_folder_is_finished_loading (chooser_entry->current_folder))
+      if (chooser_entry->current_folder_loaded)
        autocomplete (chooser_entry);
       else
        chooser_entry->load_complete_action = LOAD_COMPLETE_AUTOCOMPLETE;
@@ -1687,27 +1583,6 @@ start_autocompletion (GtkFileChooserEntry *chooser_entry)
     }
 }
 
-static gboolean
-start_autocompletion_idle_handler (gpointer data)
-{
-  GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (data);
-
-  start_autocompletion (chooser_entry);
-
-  chooser_entry->start_autocompletion_idle_id = 0;
-
-  return FALSE;
-}
-
-static void
-install_start_autocompletion_idle (GtkFileChooserEntry *chooser_entry)
-{
-  if (chooser_entry->start_autocompletion_idle_id != 0)
-    return;
-
-  chooser_entry->start_autocompletion_idle_id = gdk_threads_add_idle (start_autocompletion_idle_handler, chooser_entry);
-}
-
 #ifdef G_OS_WIN32
 static gint
 insert_text_callback (GtkFileChooserEntry *chooser_entry,
@@ -1784,7 +1659,7 @@ delete_text_callback (GtkFileChooserEntry *chooser_entry,
  * Return value: the newly created #GtkFileChooserEntry
  **/
 GtkWidget *
-_gtk_file_chooser_entry_new (gboolean eat_tabs)
+_gtk_file_chooser_entry_new (gboolean       eat_tabs)
 {
   GtkFileChooserEntry *chooser_entry;
 
@@ -1794,29 +1669,6 @@ _gtk_file_chooser_entry_new (gboolean eat_tabs)
   return GTK_WIDGET (chooser_entry);
 }
 
-/**
- * _gtk_file_chooser_entry_set_file_system:
- * @chooser_entry: a #GtkFileChooser
- * @file_system: an object implementing #GtkFileSystem
- *
- * Sets the file system for @chooser_entry.
- **/
-void
-_gtk_file_chooser_entry_set_file_system (GtkFileChooserEntry *chooser_entry,
-                                        GtkFileSystem       *file_system)
-{
-  g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
-  g_return_if_fail (GTK_IS_FILE_SYSTEM (file_system));
-
-  if (file_system != chooser_entry->file_system)
-    {
-      if (chooser_entry->file_system)
-       g_object_unref (chooser_entry->file_system);
-
-      chooser_entry->file_system = g_object_ref (file_system);
-    }
-}
-
 /**
  * _gtk_file_chooser_entry_set_base_folder:
  * @chooser_entry: a #GtkFileChooserEntry
@@ -1828,16 +1680,23 @@ void
 _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
                                         GFile               *file)
 {
+  if (file)
+    g_object_ref (file);
+  else
+    file = g_file_new_for_path (g_get_home_dir ());
+
+  if (g_file_equal (chooser_entry->base_folder, file))
+    {
+      g_object_unref (file);
+      return;
+    }
+
   if (chooser_entry->base_folder)
     g_object_unref (chooser_entry->base_folder);
 
   chooser_entry->base_folder = file;
 
-  if (chooser_entry->base_folder)
-    g_object_ref (chooser_entry->base_folder);
-
   clear_completions (chooser_entry);
-  _gtk_file_chooser_entry_select_filename (chooser_entry);
 }
 
 /**
@@ -1851,14 +1710,16 @@ _gtk_file_chooser_entry_set_base_folder (GtkFileChooserEntry *chooser_entry,
  * be different.  If the user has entered unparsable text, or text which
  * the entry cannot handle, this will return %NULL.
  *
- * Return value: the file for the current folder - this value is owned by the
- *  chooser entry and must not be modified or freed.
+ * Return value: the file for the current folder - you must g_object_unref()
+ *   the value after use.
  **/
 GFile *
 _gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
 {
-  commit_completion_and_refresh (chooser_entry);
-  return chooser_entry->current_folder_file;
+  g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
+
+  return gtk_file_chooser_get_directory_for_text (chooser_entry,
+                                                  gtk_entry_get_text (GTK_ENTRY (chooser_entry)));
 }
 
 /**
@@ -1876,8 +1737,16 @@ _gtk_file_chooser_entry_get_current_folder (GtkFileChooserEntry *chooser_entry)
 const gchar *
 _gtk_file_chooser_entry_get_file_part (GtkFileChooserEntry *chooser_entry)
 {
-  commit_completion_and_refresh (chooser_entry);
-  return chooser_entry->file_part;
+  const char *last_slash, *text;
+
+  g_return_val_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry), NULL);
+
+  text = gtk_entry_get_text (GTK_ENTRY (chooser_entry));
+  last_slash = strrchr (text, G_DIR_SEPARATOR);
+  if (last_slash)
+    return last_slash + 1;
+  else
+    return text;
 }
 
 /**
@@ -1961,22 +1830,19 @@ gboolean
 _gtk_file_chooser_entry_get_is_folder (GtkFileChooserEntry *chooser_entry,
                                       GFile               *file)
 {
-  gboolean retval = FALSE;
-
-  if (chooser_entry->current_folder)
-    {
-      GFileInfo *file_info;
+  GtkTreeIter iter;
+  GFileInfo *info;
 
-      file_info = _gtk_folder_get_info (chooser_entry->current_folder, file);
+  if (chooser_entry->completion_store == NULL ||
+      !_gtk_file_system_model_get_iter_for_file (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
+                                                 &iter,
+                                                 file))
+    return FALSE;
 
-      if (file_info)
-        {
-         retval = _gtk_file_info_consider_as_directory (file_info);
-         g_object_unref (file_info);
-       }
-    }
+  info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (chooser_entry->completion_store),
+                                          &iter);
 
-  return retval;
+  return _gtk_file_info_consider_as_directory (info);
 }