]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilechooserdefault.c
Add docs for new ports.
[~andy/gtk] / gtk / gtkfilechooserdefault.c
index 41c61aa8b99e5f8652c457e4ed66670d020c1ac3..4843f28b253cdfecfa2b46f0d9db235d0c5c14ad 100644 (file)
@@ -32,6 +32,7 @@
 #include "gtkentry.h"
 #include "gtkeventbox.h"
 #include "gtkexpander.h"
+#include "gtkfilechooserprivate.h"
 #include "gtkfilechooserdefault.h"
 #include "gtkfilechooserembed.h"
 #include "gtkfilechooserentry.h"
 #include "gtktable.h"
 #include "gtktreednd.h"
 #include "gtktreeprivate.h"
-#include "gtktreeview.h"
-#include "gtktreemodelsort.h"
 #include "gtktreeselection.h"
-#include "gtktreestore.h"
-#include "gtktooltips.h"
 #include "gtktypebuiltins.h"
 #include "gtkvbox.h"
 
 #include <string.h>
 #include <time.h>
 
-typedef struct _GtkFileChooserDefaultClass GtkFileChooserDefaultClass;
-
-#define GTK_FILE_CHOOSER_DEFAULT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
-#define GTK_IS_FILE_CHOOSER_DEFAULT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT))
-#define GTK_FILE_CHOOSER_DEFAULT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
-
-typedef enum {
-  LOAD_EMPTY,                  /* There is no model */
-  LOAD_PRELOAD,                        /* Model is loading and a timer is running; model isn't inserted into the tree yet */
-  LOAD_LOADING,                        /* Timeout expired, model is inserted into the tree, but not fully loaded yet */
-  LOAD_FINISHED                        /* Model is fully loaded and inserted into the tree */
-} LoadState;
-
-#define MAX_LOADING_TIME 500
-
-struct _GtkFileChooserDefaultClass
-{
-  GtkVBoxClass parent_class;
-};
-
-struct _GtkFileChooserDefault
-{
-  GtkVBox parent_instance;
-
-  GtkFileChooserAction action;
-
-  GtkFileSystem *file_system;
-
-  /* Save mode widgets */
-  GtkWidget *save_widgets;
-
-  GtkWidget *save_file_name_entry;
-  GtkWidget *save_folder_label;
-  GtkWidget *save_folder_combo;
-  GtkWidget *save_expander;
-
-  /* The file browsing widgets */
-  GtkWidget *browse_widgets;
-  GtkWidget *browse_shortcuts_tree_view;
-  GtkWidget *browse_shortcuts_add_button;
-  GtkWidget *browse_shortcuts_remove_button;
-  GtkWidget *browse_shortcuts_popup_menu;
-  GtkWidget *browse_shortcuts_popup_menu_remove_item;
-  GtkWidget *browse_shortcuts_popup_menu_rename_item;
-  GtkWidget *browse_files_tree_view;
-  GtkWidget *browse_files_popup_menu;
-  GtkWidget *browse_files_popup_menu_add_shortcut_item;
-  GtkWidget *browse_files_popup_menu_hidden_files_item;
-  GtkWidget *browse_new_folder_button;
-  GtkWidget *browse_path_bar;
-
-  GtkFileSystemModel *browse_files_model;
-
-  GtkWidget *filter_combo_hbox;
-  GtkWidget *filter_combo;
-  GtkWidget *preview_box;
-  GtkWidget *preview_label;
-  GtkWidget *preview_widget;
-  GtkWidget *extra_align;
-  GtkWidget *extra_widget;
-
-  GtkListStore *shortcuts_model;
-  GtkTreeModel *shortcuts_filter_model;
+\f
 
-  GtkTreeModelSort *sort_model;
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
 
-  LoadState load_state;
-  guint load_timeout_id;
+/* Profiling stuff */
+#define PROFILE_FILE_CHOOSER
+#ifdef PROFILE_FILE_CHOOSER
 
-  GSList *pending_select_paths;
 
-  GtkFileFilter *current_filter;
-  GSList *filters;
+#ifndef F_OK 
+#define F_OK 0
+#endif
 
-  GtkTooltips *tooltips;
+#define PROFILE_INDENT 4
+static int profile_indent;
 
-  gboolean has_home;
-  gboolean has_desktop;
+static void
+profile_add_indent (int indent)
+{
+  profile_indent += indent;
+  if (profile_indent < 0)
+    g_error ("You screwed up your indentation");
+}
 
-  int num_volumes;
-  int num_shortcuts;
-  int num_bookmarks;
+void
+_gtk_file_chooser_profile_log (const char *func, int indent, const char *msg1, const char *msg2)
+{
+  char *str;
 
-  gulong volumes_changed_id;
-  gulong bookmarks_changed_id;
+  if (indent < 0)
+    profile_add_indent (indent);
 
-  GtkFilePath *current_volume_path;
-  GtkFilePath *current_folder;
-  GtkFilePath *preview_path;
-  char *preview_display_name;
+  if (profile_indent == 0)
+    str = g_strdup_printf ("MARK: %s %s %s", func ? func : "", msg1 ? msg1 : "", msg2 ? msg2 : "");
+  else
+    str = g_strdup_printf ("MARK: %*c %s %s %s", profile_indent - 1, ' ', func ? func : "", msg1 ? msg1 : "", msg2 ? msg2 : "");
 
-  GtkTreeViewColumn *list_name_column;
-  GtkCellRenderer *list_name_renderer;
+  access (str, F_OK);
+  g_free (str);
 
-  GSource *edited_idle;
-  char *edited_new_text;
+  if (indent > 0)
+    profile_add_indent (indent);
+}
 
-  gulong settings_signal_id;
-  int icon_size;
+#define profile_start(x, y) _gtk_file_chooser_profile_log (G_STRFUNC, PROFILE_INDENT, x, y)
+#define profile_end(x, y) _gtk_file_chooser_profile_log (G_STRFUNC, -PROFILE_INDENT, x, y)
+#define profile_msg(x, y) _gtk_file_chooser_profile_log (NULL, 0, x, y)
+#else
+#define profile_start(x, y)
+#define profile_end(x, y)
+#define profile_msg(x, y)
+#endif
 
-  gulong toplevel_set_focus_id;
-  GtkWidget *toplevel_last_focus_widget;
+\f
 
-#if 0
-  GdkDragContext *shortcuts_drag_context;
-  GSource *shortcuts_drag_outside_idle;
-#endif
+typedef struct _GtkFileChooserDefaultClass GtkFileChooserDefaultClass;
 
-  /* Flags */
+#define GTK_FILE_CHOOSER_DEFAULT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
+#define GTK_IS_FILE_CHOOSER_DEFAULT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT))
+#define GTK_FILE_CHOOSER_DEFAULT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
 
-  guint local_only : 1;
-  guint preview_widget_active : 1;
-  guint use_preview_label : 1;
-  guint select_multiple : 1;
-  guint show_hidden : 1;
-  guint list_sort_ascending : 1;
-  guint changing_folder : 1;
-  guint shortcuts_current_folder_active : 1;
+#define MAX_LOADING_TIME 500
 
-#if 0
-  guint shortcuts_drag_outside : 1;
-#endif
+struct _GtkFileChooserDefaultClass
+{
+  GtkVBoxClass parent_class;
 };
 
 /* Signal IDs */
@@ -209,6 +155,8 @@ enum {
   UP_FOLDER,
   DOWN_FOLDER,
   HOME_FOLDER,
+  DESKTOP_FOLDER,
+  QUICK_BOOKMARK,
   LAST_SIGNAL
 };
 
@@ -264,6 +212,15 @@ static const GtkTargetEntry file_list_source_targets[] = {
 static const int num_file_list_source_targets = (sizeof (file_list_source_targets)
                                                 / sizeof (file_list_source_targets[0]));
 
+/* Target types for dropping into the file list */
+static const GtkTargetEntry file_list_dest_targets[] = {
+  { "text/uri-list", 0, TEXT_URI_LIST }
+};
+
+static const int num_file_list_dest_targets = (sizeof (file_list_dest_targets)
+                                              / sizeof (file_list_dest_targets[0]));
+
+
 /* Interesting places in the shortcuts bar */
 typedef enum {
   SHORTCUTS_HOME,
@@ -303,6 +260,7 @@ static void     gtk_file_chooser_default_get_property (GObject               *ob
 static void     gtk_file_chooser_default_dispose      (GObject               *object);
 static void     gtk_file_chooser_default_show_all       (GtkWidget             *widget);
 static void     gtk_file_chooser_default_map            (GtkWidget             *widget);
+static void     gtk_file_chooser_default_unmap          (GtkWidget             *widget);
 static void     gtk_file_chooser_default_hierarchy_changed (GtkWidget          *widget,
                                                            GtkWidget          *previous_toplevel);
 static void     gtk_file_chooser_default_style_set      (GtkWidget             *widget,
@@ -313,6 +271,10 @@ static void     gtk_file_chooser_default_screen_changed (GtkWidget             *
 static gboolean       gtk_file_chooser_default_set_current_folder         (GtkFileChooser    *chooser,
                                                                            const GtkFilePath *path,
                                                                            GError           **error);
+static gboolean       gtk_file_chooser_default_update_current_folder      (GtkFileChooser    *chooser,
+                                                                           const GtkFilePath *path,
+                                                                           gboolean           keep_trail,
+                                                                           GError           **error);
 static GtkFilePath *  gtk_file_chooser_default_get_current_folder         (GtkFileChooser    *chooser);
 static void           gtk_file_chooser_default_set_current_name           (GtkFileChooser    *chooser,
                                                                            const gchar       *name);
@@ -353,6 +315,9 @@ static void location_popup_handler (GtkFileChooserDefault *impl,
 static void up_folder_handler      (GtkFileChooserDefault *impl);
 static void down_folder_handler    (GtkFileChooserDefault *impl);
 static void home_folder_handler    (GtkFileChooserDefault *impl);
+static void desktop_folder_handler (GtkFileChooserDefault *impl);
+static void quick_bookmark_handler (GtkFileChooserDefault *impl,
+                                   gint                   bookmark_index);
 static void update_appearance      (GtkFileChooserDefault *impl);
 
 static void set_current_filter   (GtkFileChooserDefault *impl,
@@ -406,6 +371,7 @@ static void select_func (GtkFileSystemModel *model,
 
 static void path_bar_clicked           (GtkPathBar            *path_bar,
                                        GtkFilePath           *file_path,
+                                       GtkFilePath           *child_path,
                                        gboolean               child_is_hidden,
                                        GtkFileChooserDefault *impl);
 
@@ -441,6 +407,7 @@ static const GtkFileInfo *get_list_file_info (GtkFileChooserDefault *impl,
                                              GtkTreeIter           *iter);
 
 static void load_remove_timer (GtkFileChooserDefault *impl);
+static void browse_files_center_selected_row (GtkFileChooserDefault *impl);
 
 static GObjectClass *parent_class;
 
@@ -509,7 +476,7 @@ _gtk_file_chooser_default_get_type (void)
        NULL                                                           /* interface_data */
       };
 
-      file_chooser_default_type = g_type_register_static (GTK_TYPE_VBOX, "GtkFileChooserDefault",
+      file_chooser_default_type = g_type_register_static (GTK_TYPE_VBOX, I_("GtkFileChooserDefault"),
                                                         &file_chooser_default_info, 0);
 
       g_type_add_interface_static (file_chooser_default_type,
@@ -526,9 +493,13 @@ _gtk_file_chooser_default_get_type (void)
 static void
 gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
 {
+  static const guint quick_bookmark_keyvals[10] = {
+    GDK_1, GDK_2, GDK_3, GDK_4, GDK_5, GDK_6, GDK_7, GDK_8, GDK_9, GDK_0
+  };
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
   GtkBindingSet *binding_set;
+  int i;
 
   parent_class = g_type_class_peek_parent (class);
 
@@ -540,12 +511,13 @@ gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
 
   widget_class->show_all = gtk_file_chooser_default_show_all;
   widget_class->map = gtk_file_chooser_default_map;
+  widget_class->unmap = gtk_file_chooser_default_unmap;
   widget_class->hierarchy_changed = gtk_file_chooser_default_hierarchy_changed;
   widget_class->style_set = gtk_file_chooser_default_style_set;
   widget_class->screen_changed = gtk_file_chooser_default_screen_changed;
 
   signals[LOCATION_POPUP] =
-    _gtk_binding_signal_new ("location-popup",
+    _gtk_binding_signal_new (I_("location-popup"),
                             G_OBJECT_CLASS_TYPE (class),
                             G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
                             G_CALLBACK (location_popup_handler),
@@ -553,7 +525,7 @@ gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
                             _gtk_marshal_VOID__STRING,
                             G_TYPE_NONE, 1, G_TYPE_STRING);
   signals[UP_FOLDER] =
-    _gtk_binding_signal_new ("up-folder",
+    _gtk_binding_signal_new (I_("up-folder"),
                             G_OBJECT_CLASS_TYPE (class),
                             G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
                             G_CALLBACK (up_folder_handler),
@@ -561,7 +533,7 @@ gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
                             _gtk_marshal_VOID__VOID,
                             G_TYPE_NONE, 0);
   signals[DOWN_FOLDER] =
-    _gtk_binding_signal_new ("down-folder",
+    _gtk_binding_signal_new (I_("down-folder"),
                             G_OBJECT_CLASS_TYPE (class),
                             G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
                             G_CALLBACK (down_folder_handler),
@@ -569,13 +541,29 @@ gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
                             _gtk_marshal_VOID__VOID,
                             G_TYPE_NONE, 0);
   signals[HOME_FOLDER] =
-    _gtk_binding_signal_new ("home-folder",
+    _gtk_binding_signal_new (I_("home-folder"),
                             G_OBJECT_CLASS_TYPE (class),
                             G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
                             G_CALLBACK (home_folder_handler),
                             NULL, NULL,
                             _gtk_marshal_VOID__VOID,
                             G_TYPE_NONE, 0);
+  signals[DESKTOP_FOLDER] =
+    _gtk_binding_signal_new (I_("desktop-folder"),
+                            G_OBJECT_CLASS_TYPE (class),
+                            G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+                            G_CALLBACK (desktop_folder_handler),
+                            NULL, NULL,
+                            _gtk_marshal_VOID__VOID,
+                            G_TYPE_NONE, 0);
+  signals[QUICK_BOOKMARK] =
+    _gtk_binding_signal_new (I_("quick-bookmark"),
+                            G_OBJECT_CLASS_TYPE (class),
+                            G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+                            G_CALLBACK (quick_bookmark_handler),
+                            NULL, NULL,
+                            _gtk_marshal_VOID__INT,
+                            G_TYPE_NONE, 1, G_TYPE_INT);
 
   binding_set = gtk_binding_set_by_class (class);
 
@@ -588,6 +576,17 @@ gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
                                GDK_slash, 0,
                                "location-popup",
                                1, G_TYPE_STRING, "/");
+  gtk_binding_entry_add_signal (binding_set,
+                               GDK_KP_Divide, 0,
+                               "location-popup",
+                               1, G_TYPE_STRING, "/");
+
+#ifdef G_OS_UNIX
+  gtk_binding_entry_add_signal (binding_set,
+                               GDK_asciitilde, 0,
+                               "location-popup",
+                               1, G_TYPE_STRING, "~");
+#endif
 
   gtk_binding_entry_add_signal (binding_set,
                                GDK_Up, GDK_MOD1_MASK,
@@ -619,6 +618,16 @@ gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
                                GDK_KP_Home, GDK_MOD1_MASK,
                                "home-folder",
                                0);
+  gtk_binding_entry_add_signal (binding_set,
+                               GDK_d, GDK_MOD1_MASK,
+                               "desktop-folder",
+                               0);
+
+  for (i = 0; i < 10; i++)
+    gtk_binding_entry_add_signal (binding_set,
+                                 quick_bookmark_keyvals[i], GDK_MOD1_MASK,
+                                 "quick-bookmark",
+                                 1, G_TYPE_INT, i);
 
   _gtk_file_chooser_install_properties (gobject_class);
 
@@ -661,6 +670,10 @@ gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface)
 static void
 gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
 {
+  profile_start ("start", NULL);
+#ifdef PROFILE_FILE_CHOOSER
+  access ("MARK: *** CREATE FILE CHOOSER", F_OK);
+#endif
   impl->local_only = TRUE;
   impl->preview_widget_active = TRUE;
   impl->use_preview_label = TRUE;
@@ -668,13 +681,15 @@ gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
   impl->show_hidden = FALSE;
   impl->icon_size = FALLBACK_ICON_SIZE;
   impl->load_state = LOAD_EMPTY;
+  impl->reload_state = RELOAD_EMPTY;
   impl->pending_select_paths = NULL;
 
   gtk_box_set_spacing (GTK_BOX (impl), 12);
 
   impl->tooltips = gtk_tooltips_new ();
-  g_object_ref (impl->tooltips);
-  gtk_object_sink (GTK_OBJECT (impl->tooltips));
+  g_object_ref_sink (impl->tooltips);
+
+  profile_end ("end", NULL);
 }
 
 /* Frees the data columns for the specified iter in the shortcuts model*/
@@ -857,6 +872,10 @@ error_message_with_parent (GtkWindow  *parent,
                                   msg);
   gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                            "%s", detail);
+
+  if (parent->group)
+    gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
+
   gtk_dialog_run (GTK_DIALOG (dialog));
   gtk_widget_destroy (dialog);
 }
@@ -951,6 +970,21 @@ error_creating_folder_dialog (GtkFileChooserDefault *impl,
                path, error);
 }
 
+/* Shows an error about not being able to create a folder because a file with
+ * the same name is already there.
+ */
+static void
+error_creating_folder_over_existing_file_dialog (GtkFileChooserDefault *impl,
+                                                const GtkFilePath     *path,
+                                                GError                *error)
+{
+  error_dialog (impl,
+               _("The folder could not be created, as a file with the same name "
+                 "already exists.  Try using a different name for the folder, "
+                 "or rename the file first."),
+               path, error);
+}
+
 /* Shows an error dialog about not being able to create a filename */
 static void
 error_building_filename_dialog (GtkFileChooserDefault *impl,
@@ -981,6 +1015,10 @@ change_folder_and_display_error (GtkFileChooserDefault *impl,
   gboolean result;
   GtkFilePath *path_copy;
 
+  g_return_val_if_fail (path != NULL, FALSE);
+
+  profile_start ("start", (char *) path);
+
   /* We copy the path because of this case:
    *
    * list_row_activated()
@@ -993,13 +1031,15 @@ change_folder_and_display_error (GtkFileChooserDefault *impl,
   path_copy = gtk_file_path_copy (path);
 
   error = NULL;
-  result = _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), path_copy, &error);
+  result = gtk_file_chooser_default_update_current_folder (GTK_FILE_CHOOSER (impl), path_copy, TRUE, &error);
 
   if (!result)
     error_changing_folder_dialog (impl, path_copy, error);
 
   gtk_file_path_free (path_copy);
 
+  profile_end ("end", (char *) path);
+
   return result;
 }
 
@@ -1064,8 +1104,10 @@ shortcuts_reload_icons (GtkFileChooserDefault *impl)
 {
   GtkTreeIter iter;
 
+  profile_start ("start", NULL);
+
   if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
-    return;
+    goto out;
 
   do {
     gpointer data;
@@ -1105,6 +1147,10 @@ shortcuts_reload_icons (GtkFileChooserDefault *impl)
          g_object_unref (pixbuf);
       }
   } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model),&iter));
+
+ out:
+
+  profile_end ("end", NULL);
 }
 
 static void 
@@ -1149,6 +1195,8 @@ get_file_info (GtkFileSystem      *file_system,
   GtkFileInfo *info;
   GError *tmp = NULL;
 
+  profile_start ("start", (char *) path);
+
   parent_path = NULL;
   info = NULL;
 
@@ -1180,6 +1228,8 @@ get_file_info (GtkFileSystem      *file_system,
       g_error_free (tmp);
     }
 
+  profile_end ("end", (char *) path);
+
   return info;
 }
 
@@ -1191,11 +1241,18 @@ check_is_folder (GtkFileSystem      *file_system,
 {
   GtkFileFolder *folder;
 
+  profile_start ("start", (char *) path);
+
   folder = gtk_file_system_get_folder (file_system, path, 0, error);
   if (!folder)
-    return FALSE;
+    {
+      profile_end ("end - is not folder", (char *) path);
+      return FALSE;
+    }
 
   g_object_unref (folder);
+
+  profile_end ("end", (char *) path);
   return TRUE;
 }
 
@@ -1217,6 +1274,8 @@ shortcuts_insert_path (GtkFileChooserDefault *impl,
   gpointer data;
   GtkTreeIter iter;
 
+  profile_start ("start", is_volume ? "volume" : (char *) path);
+
   if (is_volume)
     {
       data = volume;
@@ -1226,9 +1285,6 @@ shortcuts_insert_path (GtkFileChooserDefault *impl,
     }
   else
     {
-      if (!check_is_folder (impl->file_system, path, error))
-       return FALSE;
-
       if (label)
        label_copy = g_strdup (label);
       else
@@ -1236,7 +1292,10 @@ shortcuts_insert_path (GtkFileChooserDefault *impl,
          GtkFileInfo *info = get_file_info (impl->file_system, path, TRUE, error);
 
          if (!info)
-           return FALSE;
+           {
+             profile_end ("end - could not get info", (char *) path);
+             return FALSE;
+           }
 
          label_copy = g_strdup (gtk_file_info_get_display_name (info));
          gtk_file_info_free (info);
@@ -1266,6 +1325,8 @@ shortcuts_insert_path (GtkFileChooserDefault *impl,
   if (pixbuf)
     g_object_unref (pixbuf);
 
+  profile_end ("end", NULL);
+
   return TRUE;
 }
 
@@ -1277,18 +1338,25 @@ shortcuts_append_home (GtkFileChooserDefault *impl)
   GtkFilePath *home_path;
   GError *error;
 
+  profile_start ("start", NULL);
+
   home = g_get_home_dir ();
   if (home == NULL)
-    return;
+    {
+      profile_end ("end - no home directory!?", NULL);
+      return;
+    }
 
   home_path = gtk_file_system_filename_to_path (impl->file_system, home);
 
   error = NULL;
-  impl->has_home = shortcuts_insert_path (impl, -1, FALSE, NULL, home_path, _("Home"), FALSE, &error);
+  impl->has_home = shortcuts_insert_path (impl, -1, FALSE, NULL, home_path, NULL, FALSE, &error);
   if (!impl->has_home)
     error_getting_info_dialog (impl, home_path, error);
 
   gtk_file_path_free (home_path);
+
+  profile_end ("end", NULL);
 }
 
 /* Appends the ~/Desktop directory to the shortcuts model */
@@ -1296,14 +1364,20 @@ static void
 shortcuts_append_desktop (GtkFileChooserDefault *impl)
 {
   char *name;
+  const char *home;
   GtkFilePath *path;
 
+  profile_start ("start", NULL);
+
 #ifdef G_OS_WIN32
   name = _gtk_file_system_win32_get_desktop ();
 #else
-  const char *home = g_get_home_dir ();
+  home = g_get_home_dir ();
   if (home == NULL)
-    return;
+    {
+      profile_end ("end - no home directory!?", NULL);
+      return;
+    }
 
   name = g_build_filename (home, "Desktop", NULL);
 #endif
@@ -1317,6 +1391,8 @@ shortcuts_append_desktop (GtkFileChooserDefault *impl)
    */
 
   gtk_file_path_free (path);
+
+  profile_end ("end", NULL);
 }
 
 /* Appends a list of GtkFilePath to the shortcuts model; returns how many were inserted */
@@ -1328,6 +1404,8 @@ shortcuts_append_paths (GtkFileChooserDefault *impl,
   int num_inserted;
   gchar *label;
 
+  profile_start ("start", NULL);
+
   /* As there is no separator now, we want to start there.
    */
   start_row = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR);
@@ -1336,10 +1414,8 @@ shortcuts_append_paths (GtkFileChooserDefault *impl,
   for (; paths; paths = paths->next)
     {
       GtkFilePath *path;
-      GError *error;
 
       path = paths->data;
-      error = NULL;
 
       if (impl->local_only &&
          !gtk_file_system_path_is_local (impl->file_system, path))
@@ -1354,6 +1430,8 @@ shortcuts_append_paths (GtkFileChooserDefault *impl,
       g_free (label);
     }
 
+  profile_end ("end", NULL);
+
   return num_inserted;
 }
 
@@ -1445,6 +1523,8 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
   int n;
   gboolean old_changing_folders;
 
+  profile_start ("start", NULL);
+
   old_changing_folders = impl->changing_folder;
   impl->changing_folder = TRUE;
 
@@ -1464,14 +1544,22 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
 
       if (impl->local_only)
        {
-         GtkFilePath *base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
-         gboolean is_local = gtk_file_system_path_is_local (impl->file_system, base_path);
-         gtk_file_path_free (base_path);
-
-         if (!is_local)
+         if (gtk_file_system_volume_get_is_mounted (impl->file_system, volume))
            {
-             gtk_file_system_volume_free (impl->file_system, volume);
-             continue;
+             GtkFilePath *base_path;
+
+             base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
+             if (base_path != NULL)
+               {
+                 gboolean is_local = gtk_file_system_path_is_local (impl->file_system, base_path);
+                 gtk_file_path_free (base_path);
+
+                 if (!is_local)
+                   {
+                     gtk_file_system_volume_free (impl->file_system, volume);
+                     continue;
+                   }
+               }
            }
        }
 
@@ -1488,6 +1576,8 @@ shortcuts_add_volumes (GtkFileChooserDefault *impl)
     gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (impl->shortcuts_filter_model));
 
   impl->changing_folder = old_changing_folders;
+
+  profile_end ("end", NULL);
 }
 
 /* Inserts a separator node in the shortcuts list */
@@ -1520,6 +1610,8 @@ shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
   GtkFilePath *combo_selected = NULL;
   gboolean is_volume;
   gpointer col_data;
+
+  profile_start ("start", NULL);
         
   old_changing_folders = impl->changing_folder;
   impl->changing_folder = TRUE;
@@ -1583,6 +1675,8 @@ shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
     }
   
   impl->changing_folder = old_changing_folders;
+
+  profile_end ("end", NULL);
 }
 
 /* Appends a separator and a row to the shortcuts list for the current folder */
@@ -1640,7 +1734,7 @@ shortcuts_add_current_folder (GtkFileChooserDefault *impl)
       impl->shortcuts_current_folder_active = success;
     }
 
-  if (success)
+  if (success && impl->save_folder_combo != NULL)
     gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), pos);
 }
 
@@ -1701,7 +1795,6 @@ shortcuts_model_create (GtkFileChooserDefault *impl)
       shortcuts_append_home (impl);
       shortcuts_append_desktop (impl);
       shortcuts_add_volumes (impl);
-      shortcuts_add_bookmarks (impl);
     }
 
   impl->shortcuts_filter_model = shortcuts_model_filter_new (impl,
@@ -1842,6 +1935,8 @@ static GtkWidget *
 filter_create (GtkFileChooserDefault *impl)
 {
   impl->filter_combo = gtk_combo_box_new_text ();
+  gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
+
   g_signal_connect (impl->filter_combo, "changed",
                    G_CALLBACK (filter_combo_changed), impl);
 
@@ -1857,29 +1952,15 @@ button_new (GtkFileChooserDefault *impl,
            GCallback   callback)
 {
   GtkWidget *button;
-  GtkWidget *hbox;
-  GtkWidget *widget;
-  GtkWidget *align;
+  GtkWidget *image;
 
-  button = gtk_button_new ();
-  hbox = gtk_hbox_new (FALSE, 2);
-  align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
-
-  gtk_container_add (GTK_CONTAINER (button), align);
-  gtk_container_add (GTK_CONTAINER (align), hbox);
-  widget = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
-
-  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
-
-  widget = gtk_label_new_with_mnemonic (text);
-  gtk_label_set_mnemonic_widget (GTK_LABEL (widget), GTK_WIDGET (button));
-  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
+  button = gtk_button_new_with_mnemonic (text);
+  image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
+  gtk_button_set_image (GTK_BUTTON (button), image);
 
   gtk_widget_set_sensitive (button, sensitive);
   g_signal_connect (button, "clicked", callback, impl);
 
-  gtk_widget_show_all (align);
-
   if (show)
     gtk_widget_show (button);
 
@@ -1921,8 +2002,8 @@ shortcut_find_position (GtkFileChooserDefault *impl,
              volume = col_data;
              base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
 
-             exists = strcmp (gtk_file_path_get_string (path),
-                              gtk_file_path_get_string (base_path)) == 0;
+             exists = base_path && strcmp (gtk_file_path_get_string (path),
+                                           gtk_file_path_get_string (base_path)) == 0;
              g_free (base_path);
 
              if (exists)
@@ -1939,7 +2020,11 @@ shortcut_find_position (GtkFileChooserDefault *impl,
            }
        }
 
-      gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
+      if (i < current_folder_separator_idx - 1)
+       {
+         if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
+           g_assert_not_reached ();
+       }
     }
 
   return -1;
@@ -1953,17 +2038,11 @@ shortcuts_add_bookmark_from_path (GtkFileChooserDefault *impl,
 {
   GError *error;
 
+  g_return_val_if_fail (path != NULL, FALSE);
   if (shortcut_find_position (impl, path) != -1)
     return FALSE;
 
-  /* FIXME: this check really belongs in gtk_file_system_insert_bookmark.  */
-  error = NULL;
-  if (!check_is_folder (impl->file_system, path, &error))
-    {
-      error_adding_bookmark_dialog (impl, path, error);
-      return FALSE;
-    }
-
   error = NULL;
   if (!gtk_file_system_insert_bookmark (impl->file_system, path, pos, &error))
     {
@@ -2740,6 +2819,7 @@ shortcuts_reorder (GtkFileChooserDefault *impl,
   const GtkFilePath *file_path;
   GtkFilePath *file_path_copy;
   GError *error;
+  gchar *name;
 
   /* Get the selected path */
 
@@ -2755,12 +2835,13 @@ shortcuts_reorder (GtkFileChooserDefault *impl,
   g_assert (old_position >= 0 && old_position < impl->num_bookmarks);
 
   gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
+                     SHORTCUTS_COL_NAME, &name,
                      SHORTCUTS_COL_DATA, &col_data,
                      SHORTCUTS_COL_IS_VOLUME, &is_volume,
                      -1);
   g_assert (col_data != NULL);
   g_assert (!is_volume);
-
+  
   file_path = col_data;
   file_path_copy = gtk_file_path_copy (file_path); /* removal below will free file_path, so we need a copy */
 
@@ -2774,7 +2855,10 @@ shortcuts_reorder (GtkFileChooserDefault *impl,
 
   error = NULL;
   if (gtk_file_system_remove_bookmark (impl->file_system, file_path_copy, &error))
-    shortcuts_add_bookmark_from_path (impl, file_path_copy, new_position);
+    {
+      shortcuts_add_bookmark_from_path (impl, file_path_copy, new_position);
+      gtk_file_system_set_bookmark_label (impl->file_system, file_path_copy, name);
+    }
   else
     error_adding_bookmark_dialog (impl, file_path_copy, error);
 
@@ -2818,9 +2902,9 @@ shortcuts_drag_data_received_cb (GtkWidget          *widget,
   g_assert (position >= bookmarks_index);
   position -= bookmarks_index;
 
-  if (selection_data->target == gdk_atom_intern ("text/uri-list", FALSE))
-    shortcuts_drop_uris (impl, selection_data->data, position);
-  else if (selection_data->target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
+  if (selection_data->target == gdk_atom_intern_static_string ("text/uri-list"))
+    shortcuts_drop_uris (impl, (const char *) selection_data->data, position);
+  else if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
     shortcuts_reorder (impl, position);
 
   g_signal_stop_emission_by_name (widget, "drag-data-received");
@@ -2861,10 +2945,14 @@ tree_view_keybinding_cb (GtkWidget             *tree_view,
                         GdkEventKey           *event,
                         GtkFileChooserDefault *impl)
 {
-  if (event->keyval == GDK_slash &&
-      ! (event->state & (~GDK_SHIFT_MASK & gtk_accelerator_get_default_mod_mask ())))
+  if ((event->keyval == GDK_slash
+       || event->keyval == GDK_KP_Divide
+#ifdef G_OS_UNIX
+       || event->keyval == GDK_asciitilde
+#endif
+       ) && ! (event->state & (~GDK_SHIFT_MASK & gtk_accelerator_get_default_mod_mask ())))
     {
-      location_popup_handler (impl, "/");
+      location_popup_handler (impl, event->string);
       return TRUE;
     }
   
@@ -2893,9 +2981,9 @@ remove_shortcut_cb (GtkMenuItem           *item,
   remove_selected_bookmarks (impl);
 }
 
+/* Rename the selected bookmark */
 static void
-rename_shortcut_cb (GtkMenuItem           *item,
-                   GtkFileChooserDefault *impl)
+rename_selected_bookmark (GtkFileChooserDefault *impl)
 {
   GtkTreeIter iter;
   GtkTreePath *path;
@@ -2917,6 +3005,13 @@ rename_shortcut_cb (GtkMenuItem           *item,
     }
 }
 
+static void
+rename_shortcut_cb (GtkMenuItem           *item,
+                   GtkFileChooserDefault *impl)
+{
+  rename_selected_bookmark (impl);
+}
+
 /* Constructs the popup menu for the file list if needed */
 static void
 shortcuts_build_popup_menu (GtkFileChooserDefault *impl)
@@ -3000,9 +3095,22 @@ shortcuts_button_press_event_cb (GtkWidget             *widget,
                                 GdkEventButton        *event,
                                 GtkFileChooserDefault *impl)
 {
+  static gboolean in_press = FALSE;
+  gboolean handled;
+
+  if (in_press)
+    return FALSE;
+
   if (event->button != 3)
     return FALSE;
 
+  in_press = TRUE;
+  handled = gtk_widget_event (impl->browse_shortcuts_tree_view, (GdkEvent *) event);
+  in_press = FALSE;
+
+  if (!handled)
+    return FALSE;
+
   shortcuts_popup_menu (impl, event);
   return TRUE;
 }
@@ -3020,7 +3128,9 @@ shortcuts_edited (GtkCellRenderer       *cell,
   g_object_set (cell, "editable", FALSE, NULL);
 
   path = gtk_tree_path_new_from_string (path_string);
-  gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path);
+  if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
+    g_assert_not_reached ();
+
   gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
                      SHORTCUTS_COL_DATA, &shortcut,
                      -1);
@@ -3057,14 +3167,17 @@ shortcuts_list_create (GtkFileChooserDefault *impl)
   /* Tree */
 
   impl->browse_shortcuts_tree_view = gtk_tree_view_new ();
+#ifdef PROFILE_FILE_CHOOSER
+  g_object_set_data (G_OBJECT (impl->browse_shortcuts_tree_view), "fmq-name", "shortcuts");
+#endif
   g_signal_connect (impl->browse_shortcuts_tree_view, "key-press-event",
                    G_CALLBACK (tree_view_keybinding_cb), impl);
   g_signal_connect (impl->browse_shortcuts_tree_view, "popup-menu",
                    G_CALLBACK (shortcuts_popup_menu_cb), impl);
   g_signal_connect (impl->browse_shortcuts_tree_view, "button-press-event",
                    G_CALLBACK (shortcuts_button_press_event_cb), impl);
-  atk_object_set_name (gtk_widget_get_accessible (impl->browse_shortcuts_tree_view), _("Shortcuts"));
-  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), FALSE);
+  /* Accessible object name for the file chooser's shortcuts pane */
+  atk_object_set_name (gtk_widget_get_accessible (impl->browse_shortcuts_tree_view), _("Places"));
 
   gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view), impl->shortcuts_filter_model);
 
@@ -3117,7 +3230,8 @@ shortcuts_list_create (GtkFileChooserDefault *impl)
   /* Column */
 
   column = gtk_tree_view_column_new ();
-  gtk_tree_view_column_set_title (column, _("Folder"));
+  /* Column header for the file chooser's shortcuts pane */
+  gtk_tree_view_column_set_title (column, _("_Places"));
 
   renderer = gtk_cell_renderer_pixbuf_new ();
   gtk_tree_view_column_pack_start (column, renderer, FALSE);
@@ -3207,13 +3321,20 @@ trap_activate_cb (GtkWidget   *widget,
                  gpointer     data)
 {
   GtkFileChooserDefault *impl;
+  int modifiers;
 
   impl = (GtkFileChooserDefault *) data;
+
+  modifiers = gtk_accelerator_get_default_mod_mask ();
   
-  if (event->keyval == GDK_slash &&
-      ! (event->state & (~GDK_SHIFT_MASK & gtk_accelerator_get_default_mod_mask ())))
+  if ((event->keyval == GDK_slash
+       || event->keyval == GDK_KP_Divide
+#ifdef G_OS_UNIX
+       || event->keyval == GDK_asciitilde
+#endif
+       ) && ! (event->state & (~GDK_SHIFT_MASK & modifiers)))
     {
-      location_popup_handler (impl, "/");
+      location_popup_handler (impl, event->string);
       return TRUE;
     }
 
@@ -3221,6 +3342,7 @@ trap_activate_cb (GtkWidget   *widget,
        || event->keyval == GDK_ISO_Enter
        || event->keyval == GDK_KP_Enter
        || event->keyval == GDK_space)
+      && ((event->state & modifiers) == 0)
       && !(impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
           impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
     {
@@ -3281,6 +3403,127 @@ show_hidden_toggled_cb (GtkCheckMenuItem      *item,
                NULL);
 }
 
+/* Shows an error dialog about not being able to select a dragged file */
+static void
+error_selecting_dragged_file_dialog (GtkFileChooserDefault *impl,
+                                    const GtkFilePath     *path,
+                                    GError                *error)
+{
+  error_dialog (impl,
+               _("Could not select file"),
+               path, error);
+}
+
+static void
+file_list_drag_data_received_cb (GtkWidget          *widget,
+                                GdkDragContext     *context,
+                                gint                x,
+                                gint                y,
+                                GtkSelectionData   *selection_data,
+                                guint               info,
+                                guint               time_,
+                                gpointer            data)
+{
+  GtkFileChooserDefault *impl;
+  GtkFileChooser *chooser;
+  gchar **uris;
+  char *uri;
+  GtkFilePath *path;
+  GError *error = NULL;
+  gint i;
+  impl = GTK_FILE_CHOOSER_DEFAULT (data);
+  chooser = GTK_FILE_CHOOSER (data);
+  
+  /* Parse the text/uri-list string, navigate to the first one */
+  uris = g_uri_list_extract_uris ((const char *) selection_data->data);
+  if (uris[0]) 
+    {
+      uri = uris[0];
+      path = gtk_file_system_uri_to_path (impl->file_system, uri);
+      
+      if (path)
+       {
+         if ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
+              impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) &&
+             uris[1] == 0 &&
+             check_is_folder (impl->file_system, path, NULL))
+           change_folder_and_display_error (impl, path);
+          else
+            {
+              gtk_file_chooser_default_unselect_all (chooser);
+              gtk_file_chooser_default_select_path (chooser, path, &error);
+              if (error)
+               error_selecting_dragged_file_dialog (impl, path, error);
+             else
+               browse_files_center_selected_row (impl);
+            }
+
+         gtk_file_path_free (path);
+       }
+      else
+       {
+         g_set_error (&error,
+                      GTK_FILE_CHOOSER_ERROR,
+                      GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
+                      _("Could not select file '%s' "
+                        "because it is an invalid path name."),
+                      uri);
+         error_selecting_dragged_file_dialog (impl, NULL, error);
+       }
+
+      
+      if (impl->select_multiple)
+       {
+         for (i = 1; uris[i]; i++)
+           {
+             uri = uris[i];
+             path = gtk_file_system_uri_to_path (impl->file_system, uri);
+             
+             if (path)
+               {
+                 gtk_file_chooser_default_select_path (chooser, path, &error);
+                 if (error)
+                   error_selecting_dragged_file_dialog (impl, path, error);
+
+                 gtk_file_path_free (path);
+               }
+           }
+       }
+    }
+
+  g_strfreev (uris);
+
+  g_signal_stop_emission_by_name (widget, "drag-data-received");
+}
+
+/* Don't do anything with the drag_drop signal */
+static gboolean
+file_list_drag_drop_cb (GtkWidget             *widget,
+                       GdkDragContext        *context,
+                       gint                   x,
+                       gint                   y,
+                       guint                  time_,
+                       GtkFileChooserDefault *impl)
+{
+  g_signal_stop_emission_by_name (widget, "drag-drop");
+  return TRUE;
+}
+
+/* Disable the normal tree drag motion handler, it makes it look like you're
+   dropping the dragged item onto a tree item */
+static gboolean
+file_list_drag_motion_cb (GtkWidget             *widget,
+                          GdkDragContext        *context,
+                          gint                   x,
+                          gint                   y,
+                          guint                  time_,
+                          GtkFileChooserDefault *impl)
+{
+  g_signal_stop_emission_by_name (widget, "drag-motion");
+  return TRUE;
+}
+
 /* Constructs the popup menu for the file list if needed */
 static void
 file_list_build_popup_menu (GtkFileChooserDefault *impl)
@@ -3413,9 +3656,19 @@ list_button_press_event_cb (GtkWidget             *widget,
                            GdkEventButton        *event,
                            GtkFileChooserDefault *impl)
 {
+  static gboolean in_press = FALSE;
+  gboolean handled;
+
+  if (in_press)
+    return FALSE;
+
   if (event->button != 3)
     return FALSE;
 
+  in_press = TRUE;
+  handled = gtk_widget_event (impl->browse_files_tree_view, (GdkEvent *) event);
+  in_press = FALSE;
+
   file_list_popup_menu (impl, event);
   return TRUE;
 }
@@ -3440,11 +3693,21 @@ create_file_list (GtkFileChooserDefault *impl)
   /* Tree/list view */
 
   impl->browse_files_tree_view = gtk_tree_view_new ();
-  g_object_set_data (G_OBJECT (impl->browse_files_tree_view), "GtkFileChooserDefault", impl);
+#ifdef PROFILE_FILE_CHOOSER
+  g_object_set_data (G_OBJECT (impl->browse_files_tree_view), "fmq-name", "file_list");
+#endif
+  g_object_set_data (G_OBJECT (impl->browse_files_tree_view), I_("GtkFileChooserDefault"), impl);
   atk_object_set_name (gtk_widget_get_accessible (impl->browse_files_tree_view), _("Files"));
 
   gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->browse_files_tree_view), TRUE);
   gtk_container_add (GTK_CONTAINER (swin), impl->browse_files_tree_view);
+
+  gtk_drag_dest_set (impl->browse_files_tree_view,
+                     GTK_DEST_DEFAULT_ALL,
+                     file_list_dest_targets,
+                     num_file_list_dest_targets,
+                     GDK_ACTION_COPY | GDK_ACTION_MOVE);
+  
   g_signal_connect (impl->browse_files_tree_view, "row-activated",
                    G_CALLBACK (list_row_activated), impl);
   g_signal_connect (impl->browse_files_tree_view, "key-press-event",
@@ -3454,6 +3717,13 @@ create_file_list (GtkFileChooserDefault *impl)
   g_signal_connect (impl->browse_files_tree_view, "button-press-event",
                    G_CALLBACK (list_button_press_event_cb), impl);
 
+  g_signal_connect (impl->browse_files_tree_view, "drag-data-received",
+                    G_CALLBACK (file_list_drag_data_received_cb), impl);
+  g_signal_connect (impl->browse_files_tree_view, "drag-drop",
+                    G_CALLBACK (file_list_drag_drop_cb), impl);
+  g_signal_connect (impl->browse_files_tree_view, "drag-motion",
+                    G_CALLBACK (file_list_drag_motion_cb), impl);
+
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
   gtk_tree_selection_set_select_function (selection,
                                          list_select_func,
@@ -3569,21 +3839,6 @@ file_pane_create (GtkFileChooserDefault *impl,
   vbox = gtk_vbox_new (FALSE, 6);
   gtk_widget_show (vbox);
 
-  /* The path bar and 'Create Folder' button */
-  hbox = gtk_hbox_new (FALSE, 12);
-  gtk_widget_show (hbox);
-  impl->browse_path_bar = create_path_bar (impl);
-  g_signal_connect (impl->browse_path_bar, "path-clicked", G_CALLBACK (path_bar_clicked), impl);
-  gtk_widget_show_all (impl->browse_path_bar);
-  gtk_box_pack_start (GTK_BOX (hbox), impl->browse_path_bar, TRUE, TRUE, 0);
-
-  /* Create Folder */
-  impl->browse_new_folder_button = gtk_button_new_with_mnemonic (_("Create Fo_lder"));
-  g_signal_connect (impl->browse_new_folder_button, "clicked",
-                   G_CALLBACK (new_folder_button_clicked), impl);
-  gtk_box_pack_end (GTK_BOX (hbox), impl->browse_new_folder_button, FALSE, FALSE, 0);
-  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-
   /* Box for lists and preview */
 
   hbox = gtk_hbox_new (FALSE, PREVIEW_HBOX_SPACING);
@@ -3618,6 +3873,7 @@ file_pane_create (GtkFileChooserDefault *impl,
 
   return vbox;
 }
+
 /* Callback used when the "Browse for more folders" expander is toggled */
 static void
 expander_changed_cb (GtkExpander           *expander,
@@ -3681,7 +3937,7 @@ save_folder_combo_create (GtkFileChooserDefault *impl)
 }
 
 /* Creates the widgets specific to Save mode */
-static GtkWidget *
+static void
 save_widgets_create (GtkFileChooserDefault *impl)
 {
   GtkWidget *vbox;
@@ -3689,6 +3945,9 @@ save_widgets_create (GtkFileChooserDefault *impl)
   GtkWidget *widget;
   GtkWidget *alignment;
 
+  if (impl->save_widgets != NULL)
+    return;
+
   vbox = gtk_vbox_new (FALSE, 12);
 
   table = gtk_table_new (2, 2, FALSE);
@@ -3746,7 +4005,25 @@ save_widgets_create (GtkFileChooserDefault *impl)
                    impl);
   gtk_widget_show_all (alignment);
 
-  return vbox;
+  impl->save_widgets = vbox;
+  gtk_box_pack_start (GTK_BOX (impl), impl->save_widgets, FALSE, FALSE, 0);
+  gtk_box_reorder_child (GTK_BOX (impl), impl->save_widgets, 0);
+  gtk_widget_show (impl->save_widgets);
+}
+
+/* Destroys the widgets specific to Save mode */
+static void
+save_widgets_destroy (GtkFileChooserDefault *impl)
+{
+  if (impl->save_widgets == NULL)
+    return;
+
+  gtk_widget_destroy (impl->save_widgets);
+  impl->save_widgets = NULL;
+  impl->save_file_name_entry = NULL;
+  impl->save_folder_label = NULL;
+  impl->save_folder_combo = NULL;
+  impl->save_expander = NULL;
 }
 
 /* Creates the main hpaned with the widgets shared by Open and Save mode */
@@ -3754,6 +4031,7 @@ static GtkWidget *
 browse_widgets_create (GtkFileChooserDefault *impl)
 {
   GtkWidget *vbox;
+  GtkWidget *hbox;
   GtkWidget *hpaned;
   GtkWidget *widget;
   GtkSizeGroup *size_group;
@@ -3762,6 +4040,22 @@ browse_widgets_create (GtkFileChooserDefault *impl)
   size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
   vbox = gtk_vbox_new (FALSE, 12);
 
+  /* The path bar and 'Create Folder' button */
+  hbox = gtk_hbox_new (FALSE, 12);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+  gtk_widget_show (hbox);
+
+  impl->browse_path_bar = create_path_bar (impl);
+  g_signal_connect (impl->browse_path_bar, "path-clicked", G_CALLBACK (path_bar_clicked), impl);
+  gtk_widget_show_all (impl->browse_path_bar);
+  gtk_box_pack_start (GTK_BOX (hbox), impl->browse_path_bar, TRUE, TRUE, 0);
+
+  /* Create Folder */
+  impl->browse_new_folder_button = gtk_button_new_with_mnemonic (_("Create Fo_lder"));
+  g_signal_connect (impl->browse_new_folder_button, "clicked",
+                   G_CALLBACK (new_folder_button_clicked), impl);
+  gtk_box_pack_end (GTK_BOX (hbox), impl->browse_new_folder_button, FALSE, FALSE, 0);
+
   /* Paned widget */
   hpaned = gtk_hpaned_new ();
   gtk_widget_show (hpaned);
@@ -3786,6 +4080,8 @@ gtk_file_chooser_default_constructor (GType                  type,
   GtkFileChooserDefault *impl;
   GObject *object;
 
+  profile_start ("start", NULL);
+
   object = parent_class->constructor (type,
                                      n_construct_properties,
                                      construct_params);
@@ -3799,10 +4095,6 @@ gtk_file_chooser_default_constructor (GType                  type,
 
   shortcuts_model_create (impl);
 
-  /* Widgets for Save mode */
-  impl->save_widgets = save_widgets_create (impl);
-  gtk_box_pack_start (GTK_BOX (impl), impl->save_widgets, FALSE, FALSE, 0);
-
   /* The browse widgets */
   impl->browse_widgets = browse_widgets_create (impl);
   gtk_box_pack_start (GTK_BOX (impl), impl->browse_widgets, TRUE, TRUE, 0);
@@ -3814,6 +4106,8 @@ gtk_file_chooser_default_constructor (GType                  type,
   gtk_widget_pop_composite_child ();
   update_appearance (impl);
 
+  profile_end ("end", NULL);
+
   return object;
 }
 
@@ -3927,6 +4221,8 @@ static void
 set_file_system_backend (GtkFileChooserDefault *impl,
                         const char *backend)
 {
+  profile_start ("start for backend", backend ? backend : "default");
+
   if (impl->file_system)
     {
       g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
@@ -3972,6 +4268,8 @@ set_file_system_backend (GtkFileChooserDefault *impl,
                                                     G_CALLBACK (bookmarks_changed_cb),
                                                     impl);
     }
+
+  profile_end ("end", NULL);
 }
 
 /* This function is basically a do_all function.
@@ -3987,7 +4285,7 @@ update_appearance (GtkFileChooserDefault *impl)
     {
       const char *text;
 
-      gtk_widget_show (impl->save_widgets);
+      save_widgets_create (impl);
 
       if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
        text = _("Save in _folder:");
@@ -3996,6 +4294,8 @@ update_appearance (GtkFileChooserDefault *impl)
 
       gtk_label_set_text_with_mnemonic (GTK_LABEL (impl->save_folder_label), text);
 
+      _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry), impl->action);
+
       if (gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander)))
        {
          gtk_widget_set_sensitive (impl->save_folder_label, FALSE);
@@ -4021,7 +4321,7 @@ update_appearance (GtkFileChooserDefault *impl)
   else if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
           impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
     {
-      gtk_widget_hide (impl->save_widgets);
+      save_widgets_destroy (impl);
       gtk_widget_show (impl->browse_widgets);
     }
 
@@ -4030,6 +4330,9 @@ update_appearance (GtkFileChooserDefault *impl)
   else
     gtk_widget_show (impl->browse_new_folder_button);
 
+  /* This *is* needed; we need to redraw the file list because the "sensitivity"
+   * of files may change depending whether we are in a file or folder-only mode.
+   */
   gtk_widget_queue_draw (impl->browse_files_tree_view);
 
   g_signal_emit_by_name (impl, "default-size-changed");
@@ -4054,55 +4357,66 @@ gtk_file_chooser_default_set_property (GObject      *object,
          {
            gtk_file_chooser_default_unselect_all (GTK_FILE_CHOOSER (impl));
            
-           if (action == GTK_FILE_CHOOSER_ACTION_SAVE && impl->select_multiple)
+           if ((action == GTK_FILE_CHOOSER_ACTION_SAVE || action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
+               && impl->select_multiple)
              {
-               g_warning ("Multiple selection mode is not allowed in Save mode");
+               g_warning ("Tried to change the file chooser action to SAVE or CREATE_FOLDER, but "
+                          "this is not allowed in multiple selection mode.  Resetting the file chooser "
+                          "to single selection mode.");
                set_select_multiple (impl, FALSE, TRUE);
              }
            impl->action = action;
            update_appearance (impl);
          }
-       
-       if (impl->save_file_name_entry)
-         _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry),
-                                             action);
       }
       break;
+
     case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
       set_file_system_backend (impl, g_value_get_string (value));
       break;
+
     case GTK_FILE_CHOOSER_PROP_FILTER:
       set_current_filter (impl, g_value_get_object (value));
       break;
+
     case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
       set_local_only (impl, g_value_get_boolean (value));
       break;
+
     case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
       set_preview_widget (impl, g_value_get_object (value));
       break;
+
     case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
       impl->preview_widget_active = g_value_get_boolean (value);
       update_preview_widget_visibility (impl);
       break;
+
     case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
       impl->use_preview_label = g_value_get_boolean (value);
       update_preview_widget_visibility (impl);
       break;
+
     case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
       set_extra_widget (impl, g_value_get_object (value));
       break;
+
     case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
       {
        gboolean select_multiple = g_value_get_boolean (value);
-       if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE && select_multiple)
+       if ((impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
+           && select_multiple)
          {
-           g_warning ("Multiple selection mode is not allowed in Save mode");
+           g_warning ("Tried to set the file chooser to multiple selection mode, but this is "
+                      "not allowed in SAVE or CREATE_FOLDER modes.  Ignoring the change and "
+                      "leaving the file chooser in single selection mode.");
            return;
          }
 
        set_select_multiple (impl, select_multiple, FALSE);
       }
       break;
+
     case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
       {
        gboolean show_hidden = g_value_get_boolean (value);
@@ -4115,6 +4429,14 @@ gtk_file_chooser_default_set_property (GObject      *object,
          }
       }
       break;
+
+    case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
+      {
+       gboolean do_overwrite_confirmation = g_value_get_boolean (value);
+       impl->do_overwrite_confirmation = do_overwrite_confirmation;
+      }
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -4134,30 +4456,43 @@ gtk_file_chooser_default_get_property (GObject    *object,
     case GTK_FILE_CHOOSER_PROP_ACTION:
       g_value_set_enum (value, impl->action);
       break;
+
     case GTK_FILE_CHOOSER_PROP_FILTER:
       g_value_set_object (value, impl->current_filter);
       break;
+
     case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
       g_value_set_boolean (value, impl->local_only);
       break;
+
     case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
       g_value_set_object (value, impl->preview_widget);
       break;
+
     case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
       g_value_set_boolean (value, impl->preview_widget_active);
       break;
+
     case GTK_FILE_CHOOSER_PROP_USE_PREVIEW_LABEL:
       g_value_set_boolean (value, impl->use_preview_label);
       break;
+
     case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
       g_value_set_object (value, impl->extra_widget);
       break;
+
     case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
       g_value_set_boolean (value, impl->select_multiple);
       break;
+
     case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
       g_value_set_boolean (value, impl->show_hidden);
       break;
+
+    case GTK_FILE_CHOOSER_PROP_DO_OVERWRITE_CONFIRMATION:
+      g_value_set_boolean (value, impl->do_overwrite_confirmation);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -4260,6 +4595,8 @@ change_icon_theme (GtkFileChooserDefault *impl)
   GtkSettings *settings;
   gint width, height;
 
+  profile_start ("start", NULL);
+
   settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
 
   if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
@@ -4269,6 +4606,8 @@ change_icon_theme (GtkFileChooserDefault *impl)
 
   shortcuts_reload_icons (impl);
   gtk_widget_queue_resize (impl->browse_files_tree_view);
+
+  profile_end ("end", NULL);
 }
 
 /* Callback used when a GtkSettings value changes */
@@ -4279,11 +4618,15 @@ settings_notify_cb (GObject               *object,
 {
   const char *name;
 
+  profile_start ("start", NULL);
+
   name = g_param_spec_get_name (pspec);
 
   if (strcmp (name, "gtk-icon-theme-name") == 0
       || strcmp (name, "gtk-icon-sizes") == 0)
     change_icon_theme (impl);
+
+  profile_end ("end", NULL);
 }
 
 /* Installs a signal handler for GtkSettings so that we can monitor changes in
@@ -4294,8 +4637,13 @@ check_icon_theme (GtkFileChooserDefault *impl)
 {
   GtkSettings *settings;
 
+  profile_start ("start", NULL);
+
   if (impl->settings_signal_id)
-    return;
+    {
+      profile_end ("end", NULL);
+      return;
+    }
 
   if (gtk_widget_has_screen (GTK_WIDGET (impl)))
     {
@@ -4305,6 +4653,8 @@ check_icon_theme (GtkFileChooserDefault *impl)
 
       change_icon_theme (impl);
     }
+
+  profile_end ("end", NULL);
 }
 
 static void
@@ -4313,15 +4663,23 @@ gtk_file_chooser_default_style_set (GtkWidget *widget,
 {
   GtkFileChooserDefault *impl;
 
+  profile_start ("start", NULL);
+
   impl = GTK_FILE_CHOOSER_DEFAULT (widget);
 
+  profile_msg ("    parent class style_set start", NULL);
   if (GTK_WIDGET_CLASS (parent_class)->style_set)
     GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
+  profile_msg ("    parent class style_set end", NULL);
 
   if (gtk_widget_has_screen (GTK_WIDGET (impl)))
     change_icon_theme (impl);
 
+  profile_msg ("    emit default-size-changed start", NULL);
   g_signal_emit_by_name (widget, "default-size-changed");
+  profile_msg ("    emit default-size-changed end", NULL);
+
+  profile_end ("end", NULL);
 }
 
 static void
@@ -4330,6 +4688,8 @@ gtk_file_chooser_default_screen_changed (GtkWidget *widget,
 {
   GtkFileChooserDefault *impl;
 
+  profile_start ("start", NULL);
+
   impl = GTK_FILE_CHOOSER_DEFAULT (widget);
 
   if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
@@ -4339,6 +4699,8 @@ gtk_file_chooser_default_screen_changed (GtkWidget *widget,
   check_icon_theme (impl);
 
   g_signal_emit_by_name (widget, "default-size-changed");
+
+  profile_end ("end", NULL);
 }
 
 static gboolean
@@ -4393,18 +4755,55 @@ static void
 gtk_file_chooser_default_map (GtkWidget *widget)
 {
   GtkFileChooserDefault *impl;
+  char *current_working_dir;
+
+  profile_start ("start", NULL);
 
   impl = GTK_FILE_CHOOSER_DEFAULT (widget);
 
   GTK_WIDGET_CLASS (parent_class)->map (widget);
 
-  if (impl->current_folder)
+  switch (impl->reload_state)
     {
+    case RELOAD_EMPTY:
+      /* The user didn't explicitly give us a folder to display, so we'll use the cwd */
+      current_working_dir = g_get_current_dir ();
+      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), current_working_dir);
+      g_free (current_working_dir);
+      break;
+
+    case RELOAD_HAS_FOLDER:
+      /* Nothing; we are already loading or loaded, so we don't need to reload */
+      break;
+
+    case RELOAD_WAS_UNMAPPED:
+      /* Just reload the current folder */
+      g_assert (impl->current_folder != NULL);
+
       pending_select_paths_store_selection (impl);
       change_folder_and_display_error (impl, impl->current_folder);
+      break;
+
+    default:
+      g_assert_not_reached ();
     }
 
   bookmarks_changed_cb (impl->file_system, impl);
+
+  profile_end ("end", NULL);
+}
+
+/* GtkWidget::unmap method */
+static void
+gtk_file_chooser_default_unmap (GtkWidget *widget)
+{
+  GtkFileChooserDefault *impl;
+
+  impl = GTK_FILE_CHOOSER_DEFAULT (widget);
+
+  GTK_WIDGET_CLASS (parent_class)->unmap (widget);
+
+  impl->reload_state = RELOAD_WAS_UNMAPPED;
 }
 
 static gboolean
@@ -4556,9 +4955,12 @@ set_busy_cursor (GtkFileChooserDefault *impl,
 static void
 load_set_model (GtkFileChooserDefault *impl)
 {
+  profile_start ("start", NULL);
+
   g_assert (impl->browse_files_model != NULL);
   g_assert (impl->sort_model == NULL);
 
+  profile_msg ("    gtk_tree_model_sort_new_with_model start", NULL);
   impl->sort_model = (GtkTreeModelSort *)gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (impl->browse_files_model));
   gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, name_sort_func, impl, NULL);
   gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_SIZE, size_sort_func, impl, NULL);
@@ -4566,15 +4968,20 @@ load_set_model (GtkFileChooserDefault *impl)
   gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->sort_model), NULL, NULL, NULL);
   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, GTK_SORT_ASCENDING);
   impl->list_sort_ascending = TRUE;
+  profile_msg ("    gtk_tree_model_sort_new_with_model end", NULL);
 
   g_signal_connect (impl->sort_model, "sort-column-changed",
                    G_CALLBACK (list_sort_column_changed_cb), impl);
 
+  profile_msg ("    gtk_tree_view_set_model start", NULL);
   gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
                           GTK_TREE_MODEL (impl->sort_model));
   gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->browse_files_tree_view));
   gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->browse_files_tree_view),
                                   GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
+  profile_msg ("    gtk_tree_view_set_model end", NULL);
+
+  profile_end ("end", NULL);
 }
 
 /* Timeout callback used when the loading timer expires */
@@ -4583,6 +4990,8 @@ load_timeout_cb (gpointer data)
 {
   GtkFileChooserDefault *impl;
 
+  profile_start ("start", NULL);
+
   GDK_THREADS_ENTER ();
 
   impl = GTK_FILE_CHOOSER_DEFAULT (data);
@@ -4597,6 +5006,8 @@ load_timeout_cb (gpointer data)
 
   GDK_THREADS_LEAVE ();
 
+  profile_end ("end", NULL);
+
   return FALSE;
 }
 
@@ -4684,96 +5095,73 @@ browse_files_center_selected_row (GtkFileChooserDefault *impl)
 static gboolean
 show_and_select_paths (GtkFileChooserDefault *impl,
                       const GtkFilePath     *parent_path,
-                      const GtkFilePath     *only_one_path,
                       GSList                *paths,
-                      GError               **error)
+                      GError                **error)
 {
   GtkFileFolder *folder;
-  gboolean success;
   gboolean have_hidden;
   gboolean have_filtered;
+  GSList *l;
 
-  if (!only_one_path && !paths)
-    return TRUE;
+  profile_start ("start", NULL);
+
+  if (!paths)
+    {
+      profile_end ("end", NULL);
+      return TRUE;
+    }
 
-  folder = gtk_file_system_get_folder (impl->file_system, parent_path, GTK_FILE_INFO_IS_HIDDEN, error);
+  folder = gtk_file_system_get_folder (impl->file_system, parent_path, GTK_FILE_INFO_IS_FOLDER | GTK_FILE_INFO_IS_HIDDEN, error);
   if (!folder)
-    return FALSE;
+    {
+      profile_end ("end", NULL);
+      return FALSE;
+    }
 
-  success = FALSE;
   have_hidden = FALSE;
   have_filtered = FALSE;
 
-  if (only_one_path)
+  for (l = paths; l; l = l->next)
     {
+      const GtkFilePath *path;
       GtkFileInfo *info;
 
-      info = gtk_file_folder_get_info (folder, only_one_path, error);
-      if (info)
-       {
-         success = TRUE;
-         have_hidden = gtk_file_info_get_is_hidden (info);
-         have_filtered = get_is_file_filtered (impl, only_one_path, info);
-         gtk_file_info_free (info);
-       }
-    }
-  else
-    {
-      GSList *l;
+      path = l->data;
 
-      for (l = paths; l; l = l->next)
+      /* NULL GError */
+      info = gtk_file_folder_get_info (folder, path, NULL);
+      if (info)
        {
-         const GtkFilePath *path;
-         GtkFileInfo *info;
+         if (!have_hidden)
+           have_hidden = gtk_file_info_get_is_hidden (info);
 
-         path = l->data;
-
-         /* NULL GError */
-         info = gtk_file_folder_get_info (folder, path, NULL);
-         if (info)
-           {
-             if (!have_hidden)
-               have_hidden = gtk_file_info_get_is_hidden (info);
+         if (!have_filtered)
+           have_filtered = !gtk_file_info_get_is_folder (info) && get_is_file_filtered (impl, path, info);
 
-             if (!have_filtered)
-               have_filtered = get_is_file_filtered (impl, path, info);
-
-             gtk_file_info_free (info);
+         gtk_file_info_free (info);
 
-             if (have_hidden && have_filtered)
-               break; /* we now have all the information we need */
-           }
+         if (have_hidden && have_filtered)
+           break; /* we now have all the information we need */
        }
-
-      success = TRUE;
     }
 
   g_object_unref (folder);
 
-  if (!success)
-    return FALSE;
-
   if (have_hidden)
     g_object_set (impl, "show-hidden", TRUE, NULL);
 
   if (have_filtered)
     set_current_filter (impl, NULL);
 
-  if (only_one_path)
-    _gtk_file_system_model_path_do (impl->browse_files_model, only_one_path, select_func, impl);
-  else
+  for (l = paths; l; l = l->next)
     {
-      GSList *l;
-
-      for (l = paths; l; l = l->next)
-       {
-         const GtkFilePath *path;
+      const GtkFilePath *path;
 
-         path = l->data;
-         _gtk_file_system_model_path_do (impl->browse_files_model, path, select_func, impl);
-       }
+      path = l->data;
+      _gtk_file_system_model_path_do (impl->browse_files_model, path, select_func, impl);
     }
 
+  profile_end ("end", NULL);
   return TRUE;
 }
 
@@ -4788,7 +5176,7 @@ pending_select_paths_process (GtkFileChooserDefault *impl)
   if (impl->pending_select_paths)
     {
       /* NULL GError */
-      show_and_select_paths (impl, impl->current_folder, NULL, impl->pending_select_paths, NULL);
+      show_and_select_paths (impl, impl->current_folder, impl->pending_select_paths, NULL);
       pending_select_paths_free (impl);
       browse_files_center_selected_row (impl);
     }
@@ -4819,6 +5207,8 @@ static void
 browse_files_model_finished_loading_cb (GtkFileSystemModel    *model,
                                        GtkFileChooserDefault *impl)
 {
+  profile_start ("start", NULL);
+
   if (impl->load_state == LOAD_PRELOAD)
     {
       load_remove_timer (impl);
@@ -4833,6 +5223,7 @@ browse_files_model_finished_loading_cb (GtkFileSystemModel    *model,
       /* We can't g_assert_not_reached(), as something other than us may have
        *  initiated a folder reload.  See #165556.
        */
+      profile_end ("end", NULL);
       return;
     }
 
@@ -4842,6 +5233,11 @@ browse_files_model_finished_loading_cb (GtkFileSystemModel    *model,
 
   pending_select_paths_process (impl);
   set_busy_cursor (impl, FALSE);
+#ifdef PROFILE_FILE_CHOOSER
+  access ("MARK: *** FINISHED LOADING", F_OK);
+#endif
+
+  profile_end ("end", NULL);
 }
 
 /* Gets rid of the old list model and creates a new one for the current folder */
@@ -4851,6 +5247,8 @@ set_list_model (GtkFileChooserDefault *impl,
 {
   g_assert (impl->current_folder != NULL);
 
+  profile_start ("start", NULL);
+
   load_remove_timer (impl); /* This changes the state to LOAD_EMPTY */
 
   if (impl->browse_files_model)
@@ -4875,6 +5273,7 @@ set_list_model (GtkFileChooserDefault *impl,
   if (!impl->browse_files_model)
     {
       set_busy_cursor (impl, FALSE);
+      profile_end ("end", NULL);
       return FALSE;
     }
 
@@ -4887,6 +5286,8 @@ set_list_model (GtkFileChooserDefault *impl,
 
   install_list_model_filter (impl);
 
+  profile_end ("end", NULL);
+
   return TRUE;
 }
 
@@ -4897,15 +5298,26 @@ update_chooser_entry (GtkFileChooserDefault *impl)
   const GtkFileInfo *info;
   GtkTreeIter iter;
   GtkTreeIter child_iter;
+  gboolean change_entry;
 
-  if (impl->action != GTK_FILE_CHOOSER_ACTION_SAVE)
+  if (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER))
     return;
 
   g_assert (!impl->select_multiple);
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
 
   if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
-    return;
+    {
+      /* If nothing is selected, we only reset the file name entry if we are in
+       * CREATE_FOLDER mode.  In SAVE mode, nothing will be selected when the
+       * user starts typeahead in the treeview, and we don't want to clear the
+       * file name entry in that case --- the user could be typing-ahead to look
+       * for a folder name.  See http://bugzilla.gnome.org/show_bug.cgi?id=308332
+       */
+      if (impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
+       _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry), "");
+      return;
+    }
 
   gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
                                                  &child_iter,
@@ -4913,7 +5325,12 @@ update_chooser_entry (GtkFileChooserDefault *impl)
 
   info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
 
-  if (!gtk_file_info_get_is_folder (info))
+  if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
+    change_entry = !gtk_file_info_get_is_folder (info); /* We don't want the name to change when clicking on a folder... */
+  else
+    change_entry = TRUE;                                /* ... unless we are in CREATE_FOLDER mode */
+
+  if (change_entry)
     _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry),
                                           gtk_file_info_get_display_name (info));
 }
@@ -4922,10 +5339,21 @@ static gboolean
 gtk_file_chooser_default_set_current_folder (GtkFileChooser    *chooser,
                                             const GtkFilePath *path,
                                             GError           **error)
+{
+  return gtk_file_chooser_default_update_current_folder (chooser, path, FALSE, error);
+}
+
+static gboolean
+gtk_file_chooser_default_update_current_folder (GtkFileChooser    *chooser,
+                                               const GtkFilePath *path,
+                                               gboolean           keep_trail,
+                                               GError           **error)
 {
   GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
   gboolean result;
 
+  profile_start ("start", (char *) path);
+
   g_assert (path != NULL);
 
   if (impl->local_only &&
@@ -4936,15 +5364,22 @@ gtk_file_chooser_default_set_current_folder (GtkFileChooser    *chooser,
                   GTK_FILE_CHOOSER_ERROR_BAD_FILENAME,
                   _("Cannot change to folder because it is not local"));
 
+      profile_end ("end - not local", (char *) path);
       return FALSE;
     }
 
   /* Test validity of path here.  */
   if (!check_is_folder (impl->file_system, path, error))
-    return FALSE;
+    {
+      profile_end ("end - not a folder", (char *) path);
+      return FALSE;
+    }
 
-  if (!_gtk_path_bar_set_path (GTK_PATH_BAR (impl->browse_path_bar), path, error))
-    return FALSE;
+  if (!_gtk_path_bar_set_path (GTK_PATH_BAR (impl->browse_path_bar), path, keep_trail, error))
+    {
+      profile_end ("end - could not set path bar", (char *) path);
+      return FALSE;
+    }
 
   if (impl->current_folder != path)
     {
@@ -4952,6 +5387,8 @@ gtk_file_chooser_default_set_current_folder (GtkFileChooser    *chooser,
        gtk_file_path_free (impl->current_folder);
 
       impl->current_folder = gtk_file_path_copy (path);
+
+      impl->reload_state = RELOAD_HAS_FOLDER;
     }
 
   /* Update the widgets that may trigger a folder change themselves.  */
@@ -4967,8 +5404,9 @@ gtk_file_chooser_default_set_current_folder (GtkFileChooser    *chooser,
 
   /* Set the folder on the save entry */
 
-  _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry),
-                                          impl->current_folder);
+  if (impl->save_file_name_entry)
+    _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry),
+                                            impl->current_folder);
 
   /* Create a new list model.  This is slightly evil; we store the result value
    * but perform more actions rather than returning immediately even if it
@@ -4987,6 +5425,7 @@ gtk_file_chooser_default_set_current_folder (GtkFileChooser    *chooser,
 
   g_signal_emit_by_name (impl, "selection-changed", 0);
 
+  profile_end ("end", NULL);
   return result;
 }
 
@@ -4995,6 +5434,21 @@ gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser)
 {
   GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
 
+  if (impl->reload_state == RELOAD_EMPTY)
+    {
+      char *current_working_dir;
+      GtkFilePath *path;
+
+      /* We are unmapped, or we had an error while loading the last folder.  We'll return
+       * the $cwd since once we get (re)mapped, we'll load $cwd anyway unless the caller
+       * explicitly calls set_current_folder() on us.
+       */
+      current_working_dir = g_get_current_dir ();
+      path = gtk_file_system_filename_to_path (impl->file_system, current_working_dir);
+      g_free (current_working_dir);
+      return path;
+    }
+
   return gtk_file_path_copy (impl->current_folder);
 }
 
@@ -5007,6 +5461,7 @@ gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
   g_return_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
                    || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
 
+  pending_select_paths_free (impl);
   _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry), name);
 }
 
@@ -5053,8 +5508,12 @@ gtk_file_chooser_default_select_path (GtkFileChooser    *chooser,
   if (same_path && impl->load_state == LOAD_FINISHED)
     {
       gboolean result;
+      GSList paths;
 
-      result = show_and_select_paths (impl, parent_path, path, NULL, error);
+      paths.data = (gpointer) path;
+      paths.next = NULL;
+
+      result = show_and_select_paths (impl, parent_path, &paths, error);
       gtk_file_path_free (parent_path);
       return result;
     }
@@ -5145,13 +5604,24 @@ gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser)
   GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
 
   gtk_tree_selection_unselect_all (selection);
+  pending_select_paths_free (impl);
 }
 
-/* Checks whether the filename entry for the Save modes contains a valid filename */
-static GtkFilePath *
+/* Checks whether the filename entry for the Save modes contains a well-formed filename.
+ *
+ * is_well_formed_ret - whether what the user typed passes gkt_file_system_make_path()
+ *
+ * is_empty_ret - whether the file entry is totally empty
+ *
+ * is_file_part_empty_ret - whether the file part is empty (will be if user types "foobar/", and
+ *                          the path will be "$cwd/foobar")
+ */
+static void
 check_save_entry (GtkFileChooserDefault *impl,
-                 gboolean              *is_valid,
-                 gboolean              *is_empty)
+                 GtkFilePath          **path_ret,
+                 gboolean              *is_well_formed_ret,
+                 gboolean              *is_empty_ret,
+                 gboolean              *is_file_part_empty_ret)
 {
   GtkFileChooserEntry *chooser_entry;
   const GtkFilePath *current_folder;
@@ -5164,17 +5634,31 @@ check_save_entry (GtkFileChooserDefault *impl,
 
   chooser_entry = GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry);
 
+  if (strlen (gtk_entry_get_text (GTK_ENTRY (chooser_entry))) == 0)
+    {
+      *path_ret = NULL;
+      *is_well_formed_ret = TRUE;
+      *is_empty_ret = TRUE;
+      *is_file_part_empty_ret = TRUE;
+
+      return;
+    }
+
+  *is_empty_ret = FALSE;
+
   current_folder = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
   file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
 
   if (!file_part || file_part[0] == '\0')
     {
-      *is_valid = FALSE;
-      *is_empty = TRUE;
-      return NULL;
+      *path_ret = gtk_file_path_copy (current_folder);
+      *is_well_formed_ret = TRUE;
+      *is_file_part_empty_ret = TRUE;
+
+      return;
     }
 
-  *is_empty = FALSE;
+  *is_file_part_empty_ret = FALSE;
 
   error = NULL;
   path = gtk_file_system_make_path (impl->file_system, current_folder, file_part, &error);
@@ -5182,12 +5666,14 @@ check_save_entry (GtkFileChooserDefault *impl,
   if (!path)
     {
       error_building_filename_dialog (impl, current_folder, file_part, error);
-      *is_valid = FALSE;
-      return NULL;
+      *path_ret = NULL;
+      *is_well_formed_ret = FALSE;
+
+      return;
     }
 
-  *is_valid = TRUE;
-  return path;
+  *path_ret = path;
+  *is_well_formed_ret = TRUE;
 }
 
 struct get_paths_closure {
@@ -5233,11 +5719,21 @@ gtk_file_chooser_default_get_paths (GtkFileChooser *chooser)
   if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
       || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
     {
-      gboolean is_valid, is_empty;
+      gboolean is_well_formed, is_empty, is_file_part_empty;
 
-      info.path_from_entry = check_save_entry (impl, &is_valid, &is_empty);
-      if (!is_valid && !is_empty)
+      check_save_entry (impl, &info.path_from_entry, &is_well_formed, &is_empty, &is_file_part_empty);
+
+      if (!is_well_formed)
        return NULL;
+
+      if (!is_empty)
+       {
+         if (is_file_part_empty && impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
+           {
+             gtk_file_path_free (info.path_from_entry);
+             return NULL;
+           }
+       }
     }
 
   if (!info.path_from_entry || impl->select_multiple)
@@ -5256,7 +5752,7 @@ gtk_file_chooser_default_get_paths (GtkFileChooser *chooser)
   if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER &&
       info.result == NULL)
     {
-      info.result = g_slist_prepend (info.result, gtk_file_path_copy (impl->current_folder));
+      info.result = g_slist_prepend (info.result, _gtk_file_chooser_get_current_folder_path (chooser));
     }
 
   return g_slist_reverse (info.result);
@@ -5305,8 +5801,7 @@ gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
       return;
     }
 
-  g_object_ref (filter);
-  gtk_object_sink (GTK_OBJECT (filter));
+  g_object_ref_sink (filter);
   impl->filters = g_slist_append (impl->filters, filter);
 
   name = gtk_file_filter_get_name (filter);
@@ -5350,7 +5845,9 @@ gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
 
   /* Remove row from the combo box */
   model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
-  gtk_tree_model_iter_nth_child  (model, &iter, NULL, filter_index);
+  if (!gtk_tree_model_iter_nth_child  (model, &iter, NULL, filter_index))
+    g_assert_not_reached ();
+
   gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 
   g_object_unref (filter);
@@ -5388,6 +5885,23 @@ gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser    *chooser,
   if (!check_is_folder (impl->file_system, path, error))
     return FALSE;
 
+  /* Avoid adding duplicates */
+  pos = shortcut_find_position (impl, path);
+  if (pos >= 0 && pos < shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS_SEPARATOR))
+    {
+      gchar *uri;
+
+      uri = gtk_file_system_path_to_uri (impl->file_system, path);
+      g_set_error (error,
+                  GTK_FILE_CHOOSER_ERROR,
+                  GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS,
+                  _("shortcut %s already exists"),
+                  uri);
+      g_free (uri);
+
+      return FALSE;
+    }
+
   pos = shortcuts_get_pos_for_shortcut_folder (impl, impl->num_shortcuts);
 
   result = shortcuts_insert_path (impl, pos, FALSE, NULL, path, NULL, FALSE, error);
@@ -5625,6 +6139,198 @@ switch_to_selected_folder (GtkFileChooserDefault *impl)
   change_folder_and_display_error (impl, closure.path);
 }
 
+/* Gets the GtkFileInfo for the selected row in the file list; assumes single
+ * selection mode.
+ */
+static const GtkFileInfo *
+get_selected_file_info_from_file_list (GtkFileChooserDefault *impl,
+                                      gboolean              *had_selection)
+{
+  GtkTreeSelection *selection;
+  GtkTreeIter iter, child_iter;
+  const GtkFileInfo *info;
+
+  g_assert (!impl->select_multiple);
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
+  if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
+    {
+      *had_selection = FALSE;
+      return NULL;
+    }
+
+  *had_selection = TRUE;
+
+  gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
+                                                 &child_iter,
+                                                 &iter);
+
+  info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
+  return info;
+}
+
+/* Gets the display name of the selected file in the file list; assumes single
+ * selection mode and that something is selected.
+ */
+static const gchar *
+get_display_name_from_file_list (GtkFileChooserDefault *impl)
+{
+  const GtkFileInfo *info;
+  gboolean had_selection;
+
+  info = get_selected_file_info_from_file_list (impl, &had_selection);
+  g_assert (had_selection);
+  g_assert (info != NULL);
+
+  return gtk_file_info_get_display_name (info);
+}
+
+static void
+add_custom_button_to_dialog (GtkDialog   *dialog,
+                            const gchar *mnemonic_label,
+                            const gchar *stock_id,
+                            gint         response_id)
+{
+  GtkWidget *button;
+
+  button = gtk_button_new_with_mnemonic (mnemonic_label);
+  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+  gtk_button_set_image (GTK_BUTTON (button),
+                       gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON));
+  gtk_widget_show (button);
+
+  gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
+}
+
+/* Presents an overwrite confirmation dialog; returns whether we should accept
+ * the filename.
+ */
+static gboolean
+confirm_dialog_should_accept_filename (GtkFileChooserDefault *impl,
+                                      const gchar           *file_part,
+                                      const gchar           *folder_display_name)
+{
+  GtkWindow *toplevel;
+  GtkWidget *dialog;
+  int response;
+
+  toplevel = get_toplevel (GTK_WIDGET (impl));
+
+  dialog = gtk_message_dialog_new (toplevel,
+                                  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                  GTK_MESSAGE_QUESTION,
+                                  GTK_BUTTONS_NONE,
+                                  _("A file named \"%s\" already exists.  Do you want to replace it?"),
+                                  file_part);
+  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                           _("The file already exists in \"%s\".  Replacing it will "
+                                             "overwrite its contents."),
+                                           folder_display_name);
+
+  gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+  add_custom_button_to_dialog (GTK_DIALOG (dialog), _("_Replace"), GTK_STOCK_SAVE_AS, GTK_RESPONSE_ACCEPT);
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
+  
+  if (toplevel->group)
+    gtk_window_group_add_window (toplevel->group, GTK_WINDOW (dialog));
+
+  response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+  gtk_widget_destroy (dialog);
+
+  return (response == GTK_RESPONSE_ACCEPT);
+}
+
+static char *
+get_display_name_for_folder (GtkFileChooserDefault *impl,
+                            const GtkFilePath     *path)
+{
+  char *display_name;
+  GtkFilePath *parent_path;
+  GtkFileFolder *parent_folder;
+  GtkFileInfo *info;
+
+  display_name = NULL;
+  parent_path = NULL;
+  parent_folder = NULL;
+  info = NULL;
+
+  if (!gtk_file_system_get_parent (impl->file_system, path, &parent_path, NULL))
+    goto out;
+
+  parent_folder = gtk_file_system_get_folder (impl->file_system,
+                                             parent_path ? parent_path : path,
+                                             GTK_FILE_INFO_DISPLAY_NAME,
+                                             NULL);
+  if (!parent_folder)
+    goto out;
+
+  info = gtk_file_folder_get_info (parent_folder, parent_path ? path : NULL, NULL);
+  if (!info)
+    goto out;
+
+  display_name = g_strdup (gtk_file_info_get_display_name (info));
+
+ out:
+
+  if (parent_path)
+    gtk_file_path_free (parent_path);
+
+  if (parent_folder)
+    g_object_unref (parent_folder);
+
+  if (info)
+    gtk_file_info_free (info);
+
+  return display_name;
+}
+
+/* Does overwrite confirmation if appropriate, and returns whether the dialog
+ * should respond.  Can get the file part from the file list or the save entry.
+ */
+static gboolean
+should_respond_after_confirm_overwrite (GtkFileChooserDefault *impl,
+                                       const gchar           *file_part,
+                                       const GtkFilePath     *parent_path)
+{
+  GtkFileChooserConfirmation conf;
+
+  if (!impl->do_overwrite_confirmation)
+    return TRUE;
+
+  conf = GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM;
+
+  g_signal_emit_by_name (impl, "confirm-overwrite", &conf);
+
+  switch (conf)
+    {
+    case GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM:
+      {
+       char *parent_display_name;
+       gboolean retval;
+
+       g_assert (file_part != NULL);
+
+       parent_display_name = get_display_name_for_folder (impl, parent_path);
+       if (!parent_display_name)
+         return TRUE; /* Huh?  Did the folder disappear?  Let the caller deal with it */
+
+       retval = confirm_dialog_should_accept_filename (impl, file_part, parent_display_name);
+       g_free (parent_display_name);
+       return retval;
+      }
+
+    case GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME:
+      return TRUE;
+
+    case GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN:
+      return FALSE;
+
+    default:
+      g_assert_not_reached ();
+      return FALSE;
+    }
+}
+
 /* Implementation for GtkFileChooserEmbed::should_respond() */
 static gboolean
 gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed)
@@ -5642,49 +6348,88 @@ gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed)
 
   if (current_focus == impl->browse_files_tree_view)
     {
+      /* The following array encodes what we do based on the impl->action and the
+       * number of files selected.
+       */
+      typedef enum {
+       NOOP,                   /* Do nothing (don't respond) */
+       RESPOND,                /* Respond immediately */
+       RESPOND_OR_SWITCH,      /* Respond immediately if the selected item is a file; switch to it if it is a folder */
+       ALL_FILES,              /* Respond only if everything selected is a file */
+       ALL_FOLDERS,            /* Respond only if everything selected is a folder */
+       SAVE_ENTRY,             /* Go to the code for handling the save entry */
+       NOT_REACHED             /* Sanity check */
+      } ActionToTake;
+      static const ActionToTake what_to_do[4][3] = {
+       /*                                0 selected            1 selected              many selected */
+       /* ACTION_OPEN */               { NOOP,                 RESPOND_OR_SWITCH,      ALL_FILES   },
+       /* ACTION_SAVE */               { SAVE_ENTRY,           RESPOND_OR_SWITCH,      NOT_REACHED },
+       /* ACTION_SELECT_FOLDER */      { RESPOND,              ALL_FOLDERS,            ALL_FOLDERS },
+       /* ACTION_CREATE_FOLDER */      { SAVE_ENTRY,           ALL_FOLDERS,            NOT_REACHED }
+      };
+
       int num_selected;
       gboolean all_files, all_folders;
+      int k;
+      ActionToTake action;
 
     file_list:
 
+      g_assert (impl->action >= GTK_FILE_CHOOSER_ACTION_OPEN && impl->action <= GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
+
       selection_check (impl, &num_selected, &all_files, &all_folders);
 
-      if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+      if (num_selected > 2)
+       k = 2;
+      else
+       k = num_selected;
+
+      action = what_to_do [impl->action] [k];
+
+      switch (action)
        {
-         if (num_selected != 1)         
-           return TRUE; /* zero means current folder; more than one means use the whole selection */    
-         else if (current_focus != impl->browse_files_tree_view)        
+       case NOOP:
+         return FALSE;
+
+       case RESPOND:
+         return TRUE;
+
+       case RESPOND_OR_SWITCH:
+         g_assert (num_selected == 1);
+
+         if (all_folders)
            {
-             /* a single folder is selected and a button was clicked */
-             switch_to_selected_folder (impl);          
-             return TRUE;
+             switch_to_selected_folder (impl);
+             return FALSE;
            }
-       }
-
-      if (num_selected == 0)
-       {
-         if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
-             || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
-           goto save_entry; /* it makes sense to use the typed name */
+         else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
+           return should_respond_after_confirm_overwrite (impl,
+                                                          get_display_name_from_file_list (impl),
+                                                          impl->current_folder);
          else
-           return FALSE;
-       }
+           return TRUE;
 
-      if (num_selected == 1 && all_folders)
-       {
-         switch_to_selected_folder (impl);
-         return FALSE;
+       case ALL_FILES:
+         return all_files;
+
+       case ALL_FOLDERS:
+         return all_folders;
+
+       case SAVE_ENTRY:
+         goto save_entry;
+
+       default:
+         g_assert_not_reached ();
        }
-      else
-       return all_files;
     }
-  else if (current_focus == impl->save_file_name_entry)
+  else if ((impl->save_file_name_entry != NULL) && (current_focus == impl->save_file_name_entry))
     {
       GtkFilePath *path;
-      gboolean is_valid, is_empty;
+      gboolean is_well_formed, is_empty, is_file_part_empty;
       gboolean is_folder;
       gboolean retval;
-      GtkFileChooserEntry *entry;  
+      GtkFileChooserEntry *entry;
+      GError *error;
 
     save_entry:
 
@@ -5692,34 +6437,93 @@ gtk_file_chooser_default_should_respond (GtkFileChooserEmbed *chooser_embed)
                || impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER);
 
       entry = GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry);
-      path = check_save_entry (impl, &is_valid, &is_empty);
+      check_save_entry (impl, &path, &is_well_formed, &is_empty, &is_file_part_empty);
 
-      if (!is_empty && !is_valid)
+      if (is_empty || !is_well_formed)
        return FALSE;
 
-      if (is_empty)
-       path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
-      
-      is_folder = check_is_folder (impl->file_system, path, NULL);
+      g_assert (path != NULL);
+
+      error = NULL;
+      is_folder = check_is_folder (impl->file_system, path, &error);
       if (is_folder)
        {
-         _gtk_file_chooser_entry_set_file_part (entry, "");
-         change_folder_and_display_error (impl, path);
-         retval = FALSE;
+         if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
+           {
+             _gtk_file_chooser_entry_set_file_part (entry, "");
+             change_folder_and_display_error (impl, path);
+             retval = FALSE;
+           }
+         else /* GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER */
+           {
+             /* The folder already exists, so we do not need to create it.
+              * Just respond to terminate the dialog.
+              */
+             retval = TRUE;
+           }
        }
       else
        {
-         /* check that everything up to the last component exists */
-         gtk_file_path_free (path);
-         path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
-         is_folder = check_is_folder (impl->file_system, path, NULL);
-         if (!is_folder)
+         gboolean file_exists_and_is_not_folder;
+
+         file_exists_and_is_not_folder = g_error_matches (error, GTK_FILE_SYSTEM_ERROR, GTK_FILE_SYSTEM_ERROR_NOT_FOLDER);
+
+         if (impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER && file_exists_and_is_not_folder)
            {
-             change_folder_and_display_error (impl, path);
+             /* Oops, the user typed the name of an existing path which is not a folder */
+             error_creating_folder_over_existing_file_dialog (impl, path, error);
+             error = NULL; /* as it will be freed below for the general case */
              retval = FALSE;
            }
          else
-           retval = TRUE;
+           {
+             GtkFilePath *parent_path;
+             gboolean parent_is_folder;
+
+             /* check that everything up to the last component exists */
+
+             parent_path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
+             parent_is_folder = check_is_folder (impl->file_system, parent_path, NULL);
+             if (parent_is_folder)
+               {
+                 if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
+                   {
+                     if (file_exists_and_is_not_folder)
+                       {
+                         const char *file_part;
+
+                         file_part = _gtk_file_chooser_entry_get_file_part (GTK_FILE_CHOOSER_ENTRY (impl->save_file_name_entry));
+                         retval = should_respond_after_confirm_overwrite (impl, file_part, parent_path);
+                       }
+                     else
+                       retval = TRUE;
+                   }
+                 else /* GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER */
+                   {
+                     GError *create_error;
+
+                     create_error = NULL;
+                     if (gtk_file_system_create_folder (impl->file_system, path, &create_error))
+                       retval = TRUE;
+                     else
+                       {
+                         error_creating_folder_dialog (impl, path, create_error);
+                         retval = FALSE;
+                       }
+                   }
+               }
+             else
+               {
+                 /* This will display an error, which is what we want */
+                 change_folder_and_display_error (impl, parent_path);
+                 retval = FALSE;
+               }
+
+             gtk_file_path_free (parent_path);
+           }
+
+         if (error != NULL)
+           g_error_free (error);
        }
 
       gtk_file_path_free (path);
@@ -5806,8 +6610,7 @@ set_current_filter (GtkFileChooserDefault *impl,
       impl->current_filter = filter;
       if (impl->current_filter)
        {
-         g_object_ref (impl->current_filter);
-         gtk_object_sink (GTK_OBJECT (filter));
+         g_object_ref_sink (impl->current_filter);
        }
 
       if (impl->filters)
@@ -5844,7 +6647,9 @@ check_preview_change (GtkFileChooserDefault *impl)
       GtkTreeIter iter;
       GtkTreeIter child_iter;
 
-      gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, cursor_path);
+      if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, cursor_path))
+       g_assert_not_reached ();
+
       gtk_tree_path_free (cursor_path);
 
       gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
@@ -5928,8 +6733,11 @@ shortcuts_activate_volume (GtkFileChooserDefault *impl,
     }
 
   path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
-  change_folder_and_display_error (impl, path);
-  gtk_file_path_free (path);
+  if (path != NULL)
+    {
+      change_folder_and_display_error (impl, path);
+      gtk_file_path_free (path);
+    }
 
  out:
 
@@ -5965,7 +6773,10 @@ shortcuts_activate_iter (GtkFileChooserDefault *impl,
       const GtkFilePath *file_path;
 
       file_path = col_data;
-      change_folder_and_display_error (impl, file_path);
+      if (check_is_folder (impl->file_system, file_path, NULL))
+       change_folder_and_display_error (impl, file_path);
+      else
+       gtk_file_chooser_default_select_path (GTK_FILE_CHOOSER (impl), file_path, NULL);
     }
 }
 
@@ -6009,6 +6820,13 @@ shortcuts_key_press_event_cb (GtkWidget             *widget,
       return TRUE;
     }
 
+  if ((event->keyval == GDK_F2)
+      && (event->state & modifiers) == 0)
+    {
+      rename_selected_bookmark (impl);
+      return TRUE;
+    }
+
   return FALSE;
 }
 
@@ -6060,24 +6878,19 @@ list_selection_changed (GtkTreeSelection      *selection,
   /* See if we are in the new folder editable row for Save mode */
   if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
     {
-      GtkTreeSelection *selection;
-      GtkTreeIter iter, child_iter;
       const GtkFileInfo *info;
+      gboolean had_selection;
 
-      g_assert (!impl->select_multiple);
-      selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
-      if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
-       return;
+      info = get_selected_file_info_from_file_list (impl, &had_selection);
+      if (!had_selection)
+       goto out; /* normal processing */
 
-      gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
-                                                     &child_iter,
-                                                     &iter);
-
-      info = _gtk_file_system_model_get_info (impl->browse_files_model, &child_iter);
       if (!info)
        return; /* We are on the editable row for New Folder */
     }
 
+ out:
+
   update_chooser_entry (impl);
   check_preview_change (impl);
   bookmarks_check_add_sensitivity (impl);
@@ -6120,9 +6933,13 @@ list_row_activated (GtkTreeView           *tree_view,
 static void
 path_bar_clicked (GtkPathBar            *path_bar,
                  GtkFilePath           *file_path,
+                 GtkFilePath           *child_path,
                  gboolean               child_is_hidden,
                  GtkFileChooserDefault *impl)
 {
+  if (child_path)
+    pending_select_paths_add (impl, child_path);
+
   if (!change_folder_and_display_error (impl, file_path))
     return;
 
@@ -6160,6 +6977,8 @@ list_icon_data_func (GtkTreeViewColumn *tree_column,
   GdkPixbuf *pixbuf;
   const GtkFileInfo *info; 
   gboolean sensitive = TRUE;
+
+  profile_start ("start", NULL);
   
   info = get_list_file_info (impl, iter);
 
@@ -6191,6 +7010,8 @@ list_icon_data_func (GtkTreeViewColumn *tree_column,
     
   if (pixbuf)
     g_object_unref (pixbuf);
+
+  profile_end ("end", NULL);
 }
 
 static void
@@ -6280,7 +7101,7 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column,
 {
   GtkFileChooserDefault *impl;
   const GtkFileInfo *info;
-  GtkFileTime time_mtime, time_now;
+  GtkFileTime time_mtime;
   GDate mtime, now;
   int days_diff;
   char buf[256];
@@ -6304,10 +7125,10 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column,
     strcpy (buf, _("Unknown"));
   else
     {
-      g_date_set_time (&mtime, (GTime) time_mtime);
-
-      time_now = (GTime ) time (NULL);
-      g_date_set_time (&now, (GTime) time_now);
+      time_t time_now;
+      g_date_set_time_t (&mtime, time_mtime);
+      time_now = time (NULL);
+      g_date_set_time_t (&now, time_now);
 
       days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
 
@@ -6359,15 +7180,11 @@ location_entry_create (GtkFileChooserDefault *impl,
   gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
   _gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (entry), impl->file_system);
   _gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (entry), impl->action);
+  _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (entry), impl->current_folder);
   if (path[0])
-    {
-      _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (entry), 
-                                              gtk_file_path_new_steal ((gchar *)path));
-      _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (entry), path);
-    }
+    gtk_entry_set_text (GTK_ENTRY (entry), path);
   else
     {
-      _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (entry), impl->current_folder);
       if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
          || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
        _gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (entry), "");
@@ -6529,6 +7346,9 @@ location_popup_handler (GtkFileChooserDefault *impl,
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                        accept_stock, GTK_RESPONSE_ACCEPT,
                                        NULL);
+  if (toplevel->group)
+    gtk_window_group_add_window (toplevel->group, GTK_WINDOW (dialog));
+  
   gtk_window_set_default_size (GTK_WINDOW (dialog), 300, -1);
   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
   gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
@@ -6598,7 +7418,6 @@ location_popup_handler (GtkFileChooserDefault *impl,
 static void
 up_folder_handler (GtkFileChooserDefault *impl)
 {
-  pending_select_paths_add (impl, impl->current_folder);
   _gtk_path_bar_up (GTK_PATH_BAR (impl->browse_path_bar));
 }
 
@@ -6609,23 +7428,56 @@ down_folder_handler (GtkFileChooserDefault *impl)
   _gtk_path_bar_down (GTK_PATH_BAR (impl->browse_path_bar));
 }
 
-/* Handler for the "home-folder" keybinding signal */
+/* Switches to the shortcut in the specified index */
 static void
-home_folder_handler (GtkFileChooserDefault *impl)
+switch_to_shortcut (GtkFileChooserDefault *impl,
+                   int pos)
 {
-  int pos;
   GtkTreeIter iter;
 
-  if (!impl->has_home)
-    return; /* Should we put up an error dialog? */
-
-  pos = shortcuts_get_index (impl, SHORTCUTS_HOME);
   if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
     g_assert_not_reached ();
 
   shortcuts_activate_iter (impl, &iter);
 }
 
+/* Handler for the "home-folder" keybinding signal */
+static void
+home_folder_handler (GtkFileChooserDefault *impl)
+{
+  if (impl->has_home)
+    switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_HOME));
+}
+
+/* Handler for the "desktop-folder" keybinding signal */
+static void
+desktop_folder_handler (GtkFileChooserDefault *impl)
+{
+  if (impl->has_desktop)
+    switch_to_shortcut (impl, shortcuts_get_index (impl, SHORTCUTS_DESKTOP));
+}
+
+static void
+quick_bookmark_handler (GtkFileChooserDefault *impl,
+                       gint bookmark_index)
+{
+  int bookmark_pos;
+  GtkTreePath *path;
+
+  if (bookmark_index < 0 || bookmark_index >= impl->num_bookmarks)
+    return;
+
+  bookmark_pos = shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS) + bookmark_index;
+
+  path = gtk_tree_path_new_from_indices (bookmark_pos, -1);
+  gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view),
+                               path, NULL,
+                               FALSE, 0.0, 0.0);
+  gtk_tree_path_free (path);
+
+  switch_to_shortcut (impl, bookmark_pos);
+}
+
 \f
 
 /* Drag and drop interfaces */