]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilesel.c
Fix obvious reallocation bug in rarely or never hit code path (#118071,
[~andy/gtk] / gtk / gtkfilesel.c
index ae80fbf0d66176285c1bbb49508148816121f46b..647deb45387c3480101d33a47cfc044cbb2685d0 100644 (file)
@@ -32,9 +32,6 @@
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #endif
-#ifdef HAVE_DIRENT_H
-#include <dirent.h>
-#endif
 #include <stdlib.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #include <pwd.h>
 #endif
 
-#include "fnmatch.h"
+#include <glib.h>              /* Include early to get G_OS_WIN32 etc */
+
+#if defined(G_PLATFORM_WIN32)
+#include <ctype.h>
+#define STRICT
+#include <windows.h>
+#undef STRICT
+#endif /* G_PLATFORM_WIN32 */
+#ifdef G_OS_WIN32
+#include <winsock.h>           /* For gethostname */
+#endif
 
 #include "gdk/gdkkeysyms.h"
 #include "gtkbutton.h"
+#include "gtkcellrenderertext.h"
 #include "gtkentry.h"
 #include "gtkfilesel.h"
 #include "gtkhbox.h"
 #include "gtkhbbox.h"
+#include "gtkintl.h"
 #include "gtklabel.h"
-#include "gtklist.h"
-#include "gtklistitem.h"
+#include "gtkliststore.h"
 #include "gtkmain.h"
+#include "gtkprivate.h"
 #include "gtkscrolledwindow.h"
 #include "gtkstock.h"
-#include "gtksignal.h"
+#include "gtktreeselection.h"
+#include "gtktreeview.h"
 #include "gtkvbox.h"
 #include "gtkmenu.h"
 #include "gtkmenuitem.h"
 #include "gtkoptionmenu.h"
-#include "gtkclist.h"
 #include "gtkdialog.h"
-#include "gtkintl.h"
+#include "gtkmessagedialog.h"
+#include "gtkdnd.h"
+#include "gtkeventbox.h"
 
-#if defined(G_OS_WIN32) || defined(G_WITH_CYGWIN)
-#define STRICT
-#include <windows.h>
+#define WANT_HPANED 1
+#include "gtkhpaned.h"
 
 #ifdef G_OS_WIN32
 #include <direct.h>
 #ifndef S_ISDIR
 #define S_ISDIR(mode) ((mode)&_S_IFDIR)
 #endif
-
 #endif /* G_OS_WIN32 */
 
-#endif /* G_OS_WIN32 || G_WITH_CYGWIN */
+#ifdef G_WITH_CYGWIN
+#include <sys/cygwin.h>                /* For cygwin_conv_to_posix_path */
+#endif
 
 #define DIR_LIST_WIDTH   180
 #define DIR_LIST_HEIGHT  180
 #define FILE_LIST_WIDTH  180
 #define FILE_LIST_HEIGHT 180
 
+/* The Hurd doesn't define either PATH_MAX or MAXPATHLEN, so we put this
+ * in here, since the rest of the code in the file does require some
+ * fixed maximum.
+ */
+#ifndef MAXPATHLEN
+#  ifdef PATH_MAX
+#    define MAXPATHLEN PATH_MAX
+#  else
+#    define MAXPATHLEN 2048
+#  endif
+#endif
+
 /* I've put this here so it doesn't get confused with the 
  * file completion interface */
 typedef struct _HistoryCallbackArg HistoryCallbackArg;
@@ -117,11 +140,8 @@ typedef struct _PossibleCompletion PossibleCompletion;
  * match by first_diff_index()
  */
 #define PATTERN_MATCH -1
-/* The arguments used by all fnmatch() calls below
- */
-#define FNMATCH_FLAGS (FNM_PATHNAME | FNM_PERIOD)
-
 #define CMPL_ERRNO_TOO_LONG ((1<<16)-1)
+#define CMPL_ERRNO_DID_NOT_CONVERT ((1<<16)-2)
 
 /* This structure contains all the useful information about a directory
  * for the purposes of filename completion.  These structures are cached
@@ -129,9 +149,11 @@ typedef struct _PossibleCompletion PossibleCompletion;
  */
 struct _CompletionDirSent
 {
+#ifndef G_PLATFORM_WIN32
   ino_t inode;
   time_t mtime;
   dev_t device;
+#endif
 
   gint entry_count;
   struct _CompletionDirEntry *entries;
@@ -161,6 +183,7 @@ struct _CompletionDirEntry
 {
   gboolean is_dir;
   gchar *entry_name;
+  gchar *sort_key;
 };
 
 struct _CompletionUserDir
@@ -211,6 +234,20 @@ struct _CompletionState
   struct _CompletionUserDir *user_directories;
 };
 
+enum {
+  PROP_0,
+  PROP_SHOW_FILEOPS,
+  PROP_FILENAME,
+  PROP_SELECT_MULTIPLE
+};
+
+enum {
+  DIR_COLUMN
+};
+
+enum {
+  FILE_COLUMN
+};
 
 /* File completion functions which would be external, were they used
  * outside of this file.
@@ -219,7 +256,7 @@ struct _CompletionState
 static CompletionState*    cmpl_init_state        (void);
 static void                cmpl_free_state        (CompletionState *cmpl_state);
 static gint                cmpl_state_okay        (CompletionState* cmpl_state);
-static gchar*              cmpl_strerror          (gint);
+static const gchar*        cmpl_strerror          (gint);
 
 static PossibleCompletion* cmpl_completion_matches(gchar           *text_to_complete,
                                                   gchar          **remaining_text,
@@ -272,14 +309,14 @@ static gint                cmpl_last_valid_char    (CompletionState* cmpl_state)
 /* When the user selects a non-directory, call cmpl_completion_fullname
  * to get the full name of the selected file.
  */
-static gchar*              cmpl_completion_fullname (gchar*, CompletionState* cmpl_state);
+static const gchar*        cmpl_completion_fullname (const gchar*, CompletionState* cmpl_state);
 
 
 /* Directory operations. */
 static CompletionDir* open_ref_dir         (gchar* text_to_complete,
                                            gchar** remaining_text,
                                            CompletionState* cmpl_state);
-#if !defined(G_OS_WIN32) && !defined(G_WITH_CYGWIN)
+#ifndef G_PLATFORM_WIN32
 static gboolean       check_dir            (gchar *dir_name, 
                                            struct stat *result, 
                                            gboolean *stat_subdirs);
@@ -287,7 +324,7 @@ static gboolean       check_dir            (gchar *dir_name,
 static CompletionDir* open_dir             (gchar* dir_name,
                                            CompletionState* cmpl_state);
 #ifdef HAVE_PWD_H
-static CompletionDir* open_user_dir        (gchar* text_to_complete,
+static CompletionDir* open_user_dir        (const gchar* text_to_complete,
                                            CompletionState *cmpl_state);
 #endif
 static CompletionDir* open_relative_dir    (gchar* dir_name, CompletionDir* dir,
@@ -298,7 +335,9 @@ static CompletionDirSent* open_new_dir     (gchar* dir_name,
 static gint           correct_dir_fullname (CompletionDir* cmpl_dir);
 static gint           correct_parent       (CompletionDir* cmpl_dir,
                                            struct stat *sbuf);
+#ifndef G_PLATFORM_WIN32
 static gchar*         find_parent_dir_fullname    (gchar* dirname);
+#endif
 static CompletionDir* attach_dir           (CompletionDirSent* sent,
                                            gchar* dir_name,
                                            CompletionState *cmpl_state);
@@ -307,8 +346,10 @@ static void           free_dir      (CompletionDir  *dir);
 static void           prune_memory_usage(CompletionState *cmpl_state);
 
 /* Completion operations */
+#ifdef HAVE_PWD_H
 static PossibleCompletion* attempt_homedir_completion(gchar* text_to_complete,
                                                      CompletionState *cmpl_state);
+#endif
 static PossibleCompletion* attempt_file_completion(CompletionState *cmpl_state);
 static CompletionDir* find_completion_dir(gchar* text_to_complete,
                                          gchar** remaining_text,
@@ -325,37 +366,98 @@ static void update_cmpl(PossibleCompletion* poss,
                        CompletionState* cmpl_state);
 
 static void gtk_file_selection_class_init    (GtkFileSelectionClass *klass);
+static void gtk_file_selection_set_property  (GObject         *object,
+                                             guint            prop_id,
+                                             const GValue    *value,
+                                             GParamSpec      *pspec);
+static void gtk_file_selection_get_property  (GObject         *object,
+                                             guint            prop_id,
+                                             GValue          *value,
+                                             GParamSpec      *pspec);
 static void gtk_file_selection_init          (GtkFileSelection      *filesel);
+static void gtk_file_selection_finalize      (GObject               *object);
 static void gtk_file_selection_destroy       (GtkObject             *object);
+static void gtk_file_selection_map           (GtkWidget             *widget);
 static gint gtk_file_selection_key_press     (GtkWidget             *widget,
                                              GdkEventKey           *event,
                                              gpointer               user_data);
-
-static void gtk_file_selection_file_button (GtkWidget *widget,
-                                           gint row, 
-                                           gint column, 
-                                           GdkEventButton *bevent,
-                                           gpointer user_data);
-
-static void gtk_file_selection_dir_button (GtkWidget *widget,
-                                          gint row, 
-                                          gint column, 
-                                          GdkEventButton *bevent,
-                                          gpointer data);
+static gint gtk_file_selection_insert_text   (GtkWidget             *widget,
+                                             const gchar           *new_text,
+                                             gint                   new_text_length,
+                                             gint                  *position,
+                                             gpointer               user_data);
+static void gtk_file_selection_update_fileops (GtkFileSelection     *filesel);
+
+static void gtk_file_selection_file_activate (GtkTreeView       *tree_view,
+                                             GtkTreePath       *path,
+                                             GtkTreeViewColumn *column,
+                                             gpointer           user_data);
+static void gtk_file_selection_file_changed  (GtkTreeSelection  *selection,
+                                             gpointer           user_data);
+static void gtk_file_selection_dir_activate  (GtkTreeView       *tree_view,
+                                             GtkTreePath       *path,
+                                             GtkTreeViewColumn *column,
+                                             gpointer           user_data);
 
 static void gtk_file_selection_populate      (GtkFileSelection      *fs,
                                              gchar                 *rel_path,
-                                             gint                   try_complete);
+                                             gboolean               try_complete,
+                                             gboolean               reset_entry);
 static void gtk_file_selection_abort         (GtkFileSelection      *fs);
 
 static void gtk_file_selection_update_history_menu (GtkFileSelection       *fs,
                                                    gchar                  *current_dir);
 
-static void gtk_file_selection_create_dir (GtkWidget *widget, gpointer data);
+static void gtk_file_selection_create_dir  (GtkWidget *widget, gpointer data);
 static void gtk_file_selection_delete_file (GtkWidget *widget, gpointer data);
 static void gtk_file_selection_rename_file (GtkWidget *widget, gpointer data);
 
+static void free_selected_names (GPtrArray *names);
+
+#ifndef G_PLATFORM_WIN32
+
+#define compare_utf8_filenames(a, b) strcmp(a, b)
+#define compare_sys_filenames(a, b) strcmp(a, b)
+
+#else
+
+static gint
+compare_utf8_filenames (const gchar *a,
+                       const gchar *b)
+{
+  gchar *a_folded, *b_folded;
+  gint retval;
+
+  a_folded = g_utf8_strdown (a, -1);
+  b_folded = g_utf8_strdown (b, -1);
+
+  retval = strcmp (a_folded, b_folded);
 
+  g_free (a_folded);
+  g_free (b_folded);
+
+  return retval;
+}
+
+static gint
+compare_sys_filenames (const gchar *a,
+                      const gchar *b)
+{
+  gchar *a_utf8, *b_utf8;
+  gint retval;
+
+  a_utf8 = g_filename_to_utf8 (a, -1, NULL, NULL, NULL);
+  b_utf8 = g_filename_to_utf8 (b, -1, NULL, NULL, NULL);
+
+  retval = compare_utf8_filenames (a_utf8, b_utf8);
+
+  g_free (a_utf8);
+  g_free (b_utf8);
+
+  return retval;
+}
+
+#endif
 
 static GtkWindowClass *parent_class = NULL;
 
@@ -366,85 +468,61 @@ static gint cmpl_errno;
 /*
  * Take the path currently in the file selection
  * entry field and translate as necessary from
- * a WIN32 style to CYGWIN32 style path.  For
+ * a Win32 style to Cygwin style path.  For
  * instance translate:
  * x:\somepath\file.jpg
  * to:
- * //x/somepath/file.jpg
+ * /cygdrive/x/somepath/file.jpg
  *
  * Replace the path in the selection text field.
  * Return a boolean value concerning whether a
  * translation had to be made.
  */
-int
+static int
 translate_win32_path (GtkFileSelection *filesel)
 {
   int updated = 0;
-  gchar *path;
+  const gchar *path;
+  gchar newPath[MAX_PATH];
 
   /*
    * Retrieve the current path
    */
   path = gtk_entry_get_text (GTK_ENTRY (filesel->selection_entry));
 
-  /*
-   * Translate only if this looks like a DOS-ish
-   * path... First handle any drive letters.
-   */
-  if (isalpha (path[0]) && (path[1] == ':')) {
-    /*
-     * This part kind of stinks... It isn't possible
-     * to know if there is enough space in the current
-     * string for the extra character required in this
-     * conversion.  Assume that there isn't enough space
-     * and use the set function on the text field to
-     * set the newly created string.
-     */
-    gchar *newPath = g_strdup_printf ("//%c/%s", path[0], (path + 3));
-    gtk_entry_set_text (GTK_ENTRY (filesel->selection_entry), newPath);
-
-    path = newPath;
-    updated = 1;
-  }
+  cygwin_conv_to_posix_path (path, newPath);
+  updated = (strcmp (path, newPath) != 0);
 
-  /*
-   * Now, replace backslashes with forward slashes 
-   * if necessary.
-   */
-  if (strchr (path, '\\'))
-    {
-      int index;
-      for (index = 0; path[index] != '\0'; index++)
-       if (path[index] == '\\')
-         path[index] = '/';
-      
-      updated = 1;
-    }
+  if (updated)
+    gtk_entry_set_text (GTK_ENTRY (filesel->selection_entry), newPath);
     
   return updated;
 }
 #endif
 
-GtkType
+GType
 gtk_file_selection_get_type (void)
 {
-  static GtkType file_selection_type = 0;
+  static GType file_selection_type = 0;
 
   if (!file_selection_type)
     {
-      static const GtkTypeInfo filesel_info =
+      static const GTypeInfo filesel_info =
       {
-       "GtkFileSelection",
-       sizeof (GtkFileSelection),
        sizeof (GtkFileSelectionClass),
-       (GtkClassInitFunc) gtk_file_selection_class_init,
-       (GtkObjectInitFunc) gtk_file_selection_init,
-       /* reserved_1 */ NULL,
-       /* reserved_2 */ NULL,
-        (GtkClassInitFunc) NULL,
+       NULL,           /* base_init */
+       NULL,           /* base_finalize */
+       (GClassInitFunc) gtk_file_selection_class_init,
+       NULL,           /* class_finalize */
+       NULL,           /* class_data */
+       sizeof (GtkFileSelection),
+       0,              /* n_preallocs */
+       (GInstanceInitFunc) gtk_file_selection_init,
       };
 
-      file_selection_type = gtk_type_unique (GTK_TYPE_DIALOG, &filesel_info);
+      file_selection_type =
+       g_type_register_static (GTK_TYPE_DIALOG, "GtkFileSelection",
+                               &filesel_info, 0);
     }
 
   return file_selection_type;
@@ -453,31 +531,137 @@ gtk_file_selection_get_type (void)
 static void
 gtk_file_selection_class_init (GtkFileSelectionClass *class)
 {
+  GObjectClass *gobject_class;
   GtkObjectClass *object_class;
+  GtkWidgetClass *widget_class;
 
+  gobject_class = (GObjectClass*) class;
   object_class = (GtkObjectClass*) class;
+  widget_class = (GtkWidgetClass*) class;
+
+  parent_class = g_type_class_peek_parent (class);
+
+  gobject_class->finalize = gtk_file_selection_finalize;
+  gobject_class->set_property = gtk_file_selection_set_property;
+  gobject_class->get_property = gtk_file_selection_get_property;
+   
+  g_object_class_install_property (gobject_class,
+                                   PROP_FILENAME,
+                                   g_param_spec_string ("filename",
+                                                        _("Filename"),
+                                                        _("The currently selected filename"),
+                                                        NULL,
+                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
+  g_object_class_install_property (gobject_class,
+                                  PROP_SHOW_FILEOPS,
+                                  g_param_spec_boolean ("show_fileops",
+                                                        _("Show file operations"),
+                                                        _("Whether buttons for creating/manipulating files should be displayed"),
+                                                        FALSE,
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE));
+  g_object_class_install_property (gobject_class,
+                                  PROP_SELECT_MULTIPLE,
+                                  g_param_spec_boolean ("select_multiple",
+                                                        _("Select multiple"),
+                                                        _("Whether to allow multiple files to be selected"),
+                                                        FALSE,
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE));
+  object_class->destroy = gtk_file_selection_destroy;
+  widget_class->map = gtk_file_selection_map;
+}
+
+static void gtk_file_selection_set_property (GObject         *object,
+                                            guint            prop_id,
+                                            const GValue    *value,
+                                            GParamSpec      *pspec)
+{
+  GtkFileSelection *filesel;
 
-  parent_class = gtk_type_class (GTK_TYPE_DIALOG);
+  filesel = GTK_FILE_SELECTION (object);
 
-  object_class->destroy = gtk_file_selection_destroy;
+  switch (prop_id)
+    {
+    case PROP_FILENAME:
+      gtk_file_selection_set_filename (filesel,
+                                       g_value_get_string (value));
+      break;
+    case PROP_SHOW_FILEOPS:
+      if (g_value_get_boolean (value))
+        gtk_file_selection_show_fileop_buttons (filesel);
+      else
+        gtk_file_selection_hide_fileop_buttons (filesel);
+      break;
+    case PROP_SELECT_MULTIPLE:
+      gtk_file_selection_set_select_multiple (filesel, g_value_get_boolean (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
 }
 
+static void gtk_file_selection_get_property (GObject         *object,
+                                            guint            prop_id,
+                                            GValue          *value,
+                                            GParamSpec      *pspec)
+{
+  GtkFileSelection *filesel;
+
+  filesel = GTK_FILE_SELECTION (object);
+
+  switch (prop_id)
+    {
+    case PROP_FILENAME:
+      g_value_set_string (value,
+                          gtk_file_selection_get_filename(filesel));
+      break;
+
+    case PROP_SHOW_FILEOPS:
+      /* This is a little bit hacky, but doing otherwise would require
+       * adding a field to the object.
+       */
+      g_value_set_boolean (value, (filesel->fileop_c_dir && 
+                                  filesel->fileop_del_file &&
+                                  filesel->fileop_ren_file));
+      break;
+    case PROP_SELECT_MULTIPLE:
+      g_value_set_boolean (value, gtk_file_selection_get_select_multiple (filesel));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static gboolean
+grab_default (GtkWidget *widget)
+{
+  gtk_widget_grab_default (widget);
+  return FALSE;
+}
+     
 static void
 gtk_file_selection_init (GtkFileSelection *filesel)
 {
   GtkWidget *entry_vbox;
   GtkWidget *label;
-  GtkWidget *list_hbox;
+  GtkWidget *list_hbox, *list_container;
   GtkWidget *confirm_area;
   GtkWidget *pulldown_hbox;
   GtkWidget *scrolled_win;
+  GtkWidget *eventbox;
+  GtkWidget *spacer;
   GtkDialog *dialog;
+
+  GtkListStore *model;
+  GtkTreeViewColumn *column;
   
-  char *dir_title [2];
-  char *file_title [2];
+  gtk_widget_push_composite_child ();
 
   dialog = GTK_DIALOG (filesel);
-  
+
   filesel->cmpl_state = cmpl_init_state ();
 
   /* The dialog-sized vertical box  */
@@ -487,7 +671,7 @@ gtk_file_selection_init (GtkFileSelection *filesel)
   /* The horizontal box containing create, rename etc. buttons */
   filesel->button_area = gtk_hbutton_box_new ();
   gtk_button_box_set_layout (GTK_BUTTON_BOX (filesel->button_area), GTK_BUTTONBOX_START);
-  gtk_button_box_set_spacing (GTK_BUTTON_BOX (filesel->button_area), 0);
+  gtk_box_set_spacing (GTK_BOX (filesel->button_area), 0);
   gtk_box_pack_start (GTK_BOX (filesel->main_vbox), filesel->button_area, 
                      FALSE, FALSE, 0);
   gtk_widget_show (filesel->button_area);
@@ -506,47 +690,98 @@ gtk_file_selection_init (GtkFileSelection *filesel)
                      FALSE, FALSE, 0);
     
   /*  The horizontal box containing the directory and file listboxes  */
+
+  spacer = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_size_request (spacer, -1, 5);
+  gtk_box_pack_start (GTK_BOX (filesel->main_vbox), spacer, FALSE, FALSE, 0);
+  gtk_widget_show (spacer);
+  
   list_hbox = gtk_hbox_new (FALSE, 5);
   gtk_box_pack_start (GTK_BOX (filesel->main_vbox), list_hbox, TRUE, TRUE, 0);
   gtk_widget_show (list_hbox);
+  if (WANT_HPANED)
+    list_container = g_object_new (GTK_TYPE_HPANED,
+                                  "visible", TRUE,
+                                  "parent", list_hbox,
+                                  "border_width", 0,
+                                  NULL);
+  else
+    list_container = list_hbox;
+
+  spacer = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_size_request (spacer, -1, 5);
+  gtk_box_pack_start (GTK_BOX (filesel->main_vbox), spacer, FALSE, FALSE, 0);  
+  gtk_widget_show (spacer);
+  
+  /* The directories list */
+
+  model = gtk_list_store_new (1, G_TYPE_STRING);
+  filesel->dir_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
+  g_object_unref (model);
+
+  column = gtk_tree_view_column_new_with_attributes (_("Folders"),
+                                                    gtk_cell_renderer_text_new (),
+                                                    "text", DIR_COLUMN,
+                                                    NULL);
+  label = gtk_label_new_with_mnemonic (_("Fol_ders"));
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), filesel->dir_list);
+  gtk_widget_show (label);
+  gtk_tree_view_column_set_widget (column, label);
+  gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (filesel->dir_list), column);
+
+  gtk_widget_set_size_request (filesel->dir_list,
+                              DIR_LIST_WIDTH, DIR_LIST_HEIGHT);
+  g_signal_connect (filesel->dir_list, "row_activated",
+                   G_CALLBACK (gtk_file_selection_dir_activate), filesel);
 
-  /* The directories clist */
-  dir_title[0] = _("Directories");
-  dir_title[1] = NULL;
-  filesel->dir_list = gtk_clist_new_with_titles (1, (gchar**) dir_title);
-  gtk_widget_set_usize (filesel->dir_list, DIR_LIST_WIDTH, DIR_LIST_HEIGHT);
-  gtk_signal_connect (GTK_OBJECT (filesel->dir_list), "select_row",
-                     (GtkSignalFunc) gtk_file_selection_dir_button, 
-                     (gpointer) filesel);
-  gtk_clist_set_column_auto_resize (GTK_CLIST (filesel->dir_list), 0, TRUE);
-  gtk_clist_column_titles_passive (GTK_CLIST (filesel->dir_list));
+  /*  gtk_clist_column_titles_passive (GTK_CLIST (filesel->dir_list)); */
 
   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
+  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN);  
   gtk_container_add (GTK_CONTAINER (scrolled_win), filesel->dir_list);
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
-  gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 5);
-  gtk_box_pack_start (GTK_BOX (list_hbox), scrolled_win, TRUE, TRUE, 0);
+  gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 0);
+  if (GTK_IS_PANED (list_container))
+    gtk_paned_pack1 (GTK_PANED (list_container), scrolled_win, TRUE, TRUE);
+  else
+    gtk_container_add (GTK_CONTAINER (list_container), scrolled_win);
   gtk_widget_show (filesel->dir_list);
   gtk_widget_show (scrolled_win);
 
-  /* The files clist */
-  file_title[0] = _("Files");
-  file_title[1] = NULL;
-  filesel->file_list = gtk_clist_new_with_titles (1, (gchar**) file_title);
-  gtk_widget_set_usize (filesel->file_list, FILE_LIST_WIDTH, FILE_LIST_HEIGHT);
-  gtk_signal_connect (GTK_OBJECT (filesel->file_list), "select_row",
-                     (GtkSignalFunc) gtk_file_selection_file_button, 
-                     (gpointer) filesel);
-  gtk_clist_set_column_auto_resize (GTK_CLIST (filesel->file_list), 0, TRUE);
-  gtk_clist_column_titles_passive (GTK_CLIST (filesel->file_list));
+  /* The files list */
+  model = gtk_list_store_new (1, G_TYPE_STRING);
+  filesel->file_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
+  g_object_unref (model);
+
+  column = gtk_tree_view_column_new_with_attributes (_("Files"),
+                                                    gtk_cell_renderer_text_new (),
+                                                    "text", FILE_COLUMN,
+                                                    NULL);
+  label = gtk_label_new_with_mnemonic (_("_Files"));
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), filesel->file_list);
+  gtk_widget_show (label);
+  gtk_tree_view_column_set_widget (column, label);
+  gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (filesel->file_list), column);
+
+  gtk_widget_set_size_request (filesel->file_list,
+                              FILE_LIST_WIDTH, FILE_LIST_HEIGHT);
+  g_signal_connect (filesel->file_list, "row_activated",
+                   G_CALLBACK (gtk_file_selection_file_activate), filesel);
+  g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (filesel->file_list)), "changed",
+                   G_CALLBACK (gtk_file_selection_file_changed), filesel);
+
+  /* gtk_clist_column_titles_passive (GTK_CLIST (filesel->file_list)); */
 
   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
+  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN);
   gtk_container_add (GTK_CONTAINER (scrolled_win), filesel->file_list);
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
-  gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 5);
-  gtk_box_pack_start (GTK_BOX (list_hbox), scrolled_win, TRUE, TRUE, 0);
+  gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 0);
+  gtk_container_add (GTK_CONTAINER (list_container), scrolled_win);
   gtk_widget_show (filesel->file_list);
   gtk_widget_show (scrolled_win);
 
@@ -559,54 +794,292 @@ gtk_file_selection_init (GtkFileSelection *filesel)
   /*  The OK/Cancel button area */
   confirm_area = dialog->action_area;
 
+  /*  The Cancel button  */
+  filesel->cancel_button = gtk_dialog_add_button (dialog,
+                                                  GTK_STOCK_CANCEL,
+                                                  GTK_RESPONSE_CANCEL);
   /*  The OK button  */
   filesel->ok_button = gtk_dialog_add_button (dialog,
-                                              GTK_STOCK_BUTTON_OK,
+                                              GTK_STOCK_OK,
                                               GTK_RESPONSE_OK);
   
   gtk_widget_grab_default (filesel->ok_button);
 
-  /*  The Cancel button  */
-  filesel->cancel_button = gtk_dialog_add_button (dialog,
-                                                  GTK_STOCK_BUTTON_CANCEL,
-                                                  GTK_RESPONSE_CANCEL);
-
   /*  The selection entry widget  */
   entry_vbox = gtk_vbox_new (FALSE, 2);
   gtk_box_pack_end (GTK_BOX (filesel->main_vbox), entry_vbox, FALSE, FALSE, 2);
   gtk_widget_show (entry_vbox);
-
+  
+  eventbox = gtk_event_box_new ();
   filesel->selection_text = label = gtk_label_new ("");
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-  gtk_box_pack_start (GTK_BOX (entry_vbox), label, FALSE, FALSE, 0);
+  gtk_container_add (GTK_CONTAINER (eventbox), label);
+  gtk_box_pack_start (GTK_BOX (entry_vbox), eventbox, FALSE, FALSE, 0);
   gtk_widget_show (label);
+  gtk_widget_show (eventbox);
 
   filesel->selection_entry = gtk_entry_new ();
-  gtk_signal_connect (GTK_OBJECT (filesel->selection_entry), "key_press_event",
-                     (GtkSignalFunc) gtk_file_selection_key_press, filesel);
-  gtk_signal_connect_object (GTK_OBJECT (filesel->selection_entry), "focus_in_event",
-                            (GtkSignalFunc) gtk_widget_grab_default,
-                            GTK_OBJECT (filesel->ok_button));
-  gtk_signal_connect_object (GTK_OBJECT (filesel->selection_entry), "activate",
-                             (GtkSignalFunc) gtk_button_clicked,
-                             GTK_OBJECT (filesel->ok_button));
+  g_signal_connect (filesel->selection_entry, "key_press_event",
+                   G_CALLBACK (gtk_file_selection_key_press), filesel);
+  g_signal_connect (filesel->selection_entry, "insert_text",
+                   G_CALLBACK (gtk_file_selection_insert_text), NULL);
+  g_signal_connect_swapped (filesel->selection_entry, "changed",
+                           G_CALLBACK (gtk_file_selection_update_fileops), filesel);
+  g_signal_connect_swapped (filesel->selection_entry, "focus_in_event",
+                           G_CALLBACK (grab_default),
+                           filesel->ok_button);
+  g_signal_connect_swapped (filesel->selection_entry, "activate",
+                           G_CALLBACK (gtk_button_clicked),
+                           filesel->ok_button);
+  
   gtk_box_pack_start (GTK_BOX (entry_vbox), filesel->selection_entry, TRUE, TRUE, 0);
   gtk_widget_show (filesel->selection_entry);
 
+  gtk_label_set_mnemonic_widget (GTK_LABEL (filesel->selection_text),
+                                filesel->selection_entry);
+
   if (!cmpl_state_okay (filesel->cmpl_state))
     {
       gchar err_buf[256];
 
-      sprintf (err_buf, _("Directory unreadable: %s"), cmpl_strerror (cmpl_errno));
+      g_snprintf (err_buf, sizeof (err_buf), _("Folder unreadable: %s"), cmpl_strerror (cmpl_errno));
 
       gtk_label_set_text (GTK_LABEL (filesel->selection_text), err_buf);
     }
   else
     {
-      gtk_file_selection_populate (filesel, "", FALSE);
+      gtk_file_selection_populate (filesel, "", FALSE, TRUE);
     }
 
   gtk_widget_grab_focus (filesel->selection_entry);
+
+  gtk_widget_pop_composite_child ();
+}
+
+static gchar *
+uri_list_extract_first_uri (const gchar* uri_list)
+{
+  const gchar *p, *q;
+  
+  g_return_val_if_fail (uri_list != NULL, NULL);
+  
+  p = uri_list;
+  /* We don't actually try to validate the URI according to RFC
+   * 2396, or even check for allowed characters - we just ignore
+   * comments and trim whitespace off the ends.  We also
+   * allow LF delimination as well as the specified CRLF.
+   *
+   * We do allow comments like specified in RFC 2483.
+   */
+  while (p)
+    {
+      if (*p != '#')
+       {
+         while (g_ascii_isspace(*p))
+           p++;
+         
+         q = p;
+         while (*q && (*q != '\n') && (*q != '\r'))
+           q++;
+         
+         if (q > p)
+           {
+             q--;
+             while (q > p && g_ascii_isspace (*q))
+               q--;
+
+             if (q > p)
+               return g_strndup (p, q - p + 1);
+           }
+       }
+      p = strchr (p, '\n');
+      if (p)
+       p++;
+    }
+  return NULL;
+}
+
+static void
+dnd_really_drop  (GtkWidget *dialog, gint response_id, GtkFileSelection *fs)
+{
+  gchar *filename;
+  
+  if (response_id == GTK_RESPONSE_YES)
+    {
+      filename = g_object_get_data (G_OBJECT (dialog), "gtk-fs-dnd-filename");
+
+      gtk_file_selection_set_filename (fs, filename);
+    }
+  
+  gtk_widget_destroy (dialog);
+}
+
+
+static void
+filenames_dropped (GtkWidget        *widget,
+                  GdkDragContext   *context,
+                  gint              x,
+                  gint              y,
+                  GtkSelectionData *selection_data,
+                  guint             info,
+                  guint             time)
+{
+  char *uri = NULL;
+  char *filename = NULL;
+  char *hostname;
+  char this_hostname[257];
+  int res;
+  GError *error = NULL;
+       
+  if (!selection_data->data)
+    return;
+
+  uri = uri_list_extract_first_uri ((char *)selection_data->data);
+  
+  if (!uri)
+    return;
+
+  filename = g_filename_from_uri (uri, &hostname, &error);
+  g_free (uri);
+  
+  if (!filename)
+    {
+      g_warning ("Error getting dropped filename: %s\n",
+                error->message);
+      g_error_free (error);
+      return;
+    }
+
+  res = gethostname (this_hostname, 256);
+  this_hostname[256] = 0;
+  
+  if ((hostname == NULL) ||
+      (res == 0 && strcmp (hostname, this_hostname) == 0) ||
+      (strcmp (hostname, "localhost") == 0))
+    gtk_file_selection_set_filename (GTK_FILE_SELECTION (widget),
+                                    filename);
+  else
+    {
+      GtkWidget *dialog;
+      gchar *filename_utf8;
+
+      /* Conversion back to UTF-8 should always succeed for the result
+       * of g_filename_from_uri()
+       */
+      filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
+      g_assert (filename_utf8);
+      
+      dialog = gtk_message_dialog_new (GTK_WINDOW (widget),
+                                      GTK_DIALOG_DESTROY_WITH_PARENT,
+                                      GTK_MESSAGE_QUESTION,
+                                      GTK_BUTTONS_YES_NO,
+                                      _("The file \"%s\" resides on another machine (called %s) and may not be available to this program.\n"
+                                        "Are you sure that you want to select it?"), filename_utf8, hostname);
+      g_free (filename_utf8);
+
+      g_object_set_data_full (G_OBJECT (dialog), "gtk-fs-dnd-filename", g_strdup (filename), g_free);
+      
+      g_signal_connect_data (dialog, "response",
+                            (GCallback) dnd_really_drop, 
+                            widget, NULL, 0);
+      
+      gtk_widget_show (dialog);
+    }
+
+  g_free (hostname);
+  g_free (filename);
+}
+
+enum
+{
+  TARGET_URILIST,
+  TARGET_UTF8_STRING,
+  TARGET_STRING,
+  TARGET_TEXT,
+  TARGET_COMPOUND_TEXT
+};
+
+
+static void
+filenames_drag_get (GtkWidget        *widget,
+                   GdkDragContext   *context,
+                   GtkSelectionData *selection_data,
+                   guint             info,
+                   guint             time,
+                   GtkFileSelection *filesel)
+{
+  const gchar *file;
+  gchar *uri_list;
+  char hostname[256];
+  int res;
+  GError *error;
+
+  file = gtk_file_selection_get_filename (filesel);
+
+  if (file)
+    {
+      if (info == TARGET_URILIST)
+       {
+         res = gethostname (hostname, 256);
+         
+         error = NULL;
+         uri_list = g_filename_to_uri (file, (!res)?hostname:NULL, &error);
+         if (!uri_list)
+           {
+             g_warning ("Error getting filename: %s\n",
+                        error->message);
+             g_error_free (error);
+             return;
+           }
+         
+         gtk_selection_data_set (selection_data,
+                                 selection_data->target, 8,
+                                 (void *)uri_list, strlen((char *)uri_list));
+         g_free (uri_list);
+       }
+      else
+       {
+         gchar *filename_utf8 = g_filename_to_utf8 (file, -1, NULL, NULL, NULL);
+         g_assert (filename_utf8);
+         gtk_selection_data_set_text (selection_data, filename_utf8, -1);
+         g_free (filename_utf8);
+       }
+    }
+}
+
+static void
+file_selection_setup_dnd (GtkFileSelection *filesel)
+{
+  GtkWidget *eventbox;
+  static const GtkTargetEntry drop_types[] = {
+    { "text/uri-list", 0, TARGET_URILIST}
+  };
+  static gint n_drop_types = sizeof(drop_types)/sizeof(drop_types[0]);
+  static const GtkTargetEntry drag_types[] = {
+    { "text/uri-list", 0, TARGET_URILIST},
+    { "UTF8_STRING", 0, TARGET_UTF8_STRING },
+    { "STRING", 0, 0 },
+    { "TEXT",   0, 0 }, 
+    { "COMPOUND_TEXT", 0, 0 }
+  };
+  static gint n_drag_types = sizeof(drag_types)/sizeof(drag_types[0]);
+
+  gtk_drag_dest_set (GTK_WIDGET (filesel),
+                    GTK_DEST_DEFAULT_ALL,
+                    drop_types, n_drop_types,
+                    GDK_ACTION_COPY);
+
+  g_signal_connect (filesel, "drag_data_received",
+                   G_CALLBACK (filenames_dropped), NULL);
+
+  eventbox = gtk_widget_get_parent (filesel->selection_text);
+  gtk_drag_source_set (eventbox,
+                      GDK_BUTTON1_MASK,
+                      drag_types, n_drag_types,
+                      GDK_ACTION_COPY);
+
+  g_signal_connect (eventbox, "drag_data_get",
+                   G_CALLBACK (filenames_drag_get), filesel);
 }
 
 GtkWidget*
@@ -614,25 +1087,27 @@ gtk_file_selection_new (const gchar *title)
 {
   GtkFileSelection *filesel;
 
-  filesel = gtk_type_new (GTK_TYPE_FILE_SELECTION);
+  filesel = g_object_new (GTK_TYPE_FILE_SELECTION, NULL);
   gtk_window_set_title (GTK_WINDOW (filesel), title);
+  gtk_dialog_set_has_separator (GTK_DIALOG (filesel), FALSE);
 
+  file_selection_setup_dnd (filesel);
+  
   return GTK_WIDGET (filesel);
 }
 
 void
 gtk_file_selection_show_fileop_buttons (GtkFileSelection *filesel)
 {
-  g_return_if_fail (filesel != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (filesel));
     
   /* delete, create directory, and rename */
   if (!filesel->fileop_c_dir) 
     {
-      filesel->fileop_c_dir = gtk_button_new_with_label (_("Create Dir"));
-      gtk_signal_connect (GTK_OBJECT (filesel->fileop_c_dir), "clicked",
-                         (GtkSignalFunc) gtk_file_selection_create_dir, 
-                         (gpointer) filesel);
+      filesel->fileop_c_dir = gtk_button_new_with_mnemonic (_("_New Folder"));
+      g_signal_connect (filesel->fileop_c_dir, "clicked",
+                       G_CALLBACK (gtk_file_selection_create_dir),
+                       filesel);
       gtk_box_pack_start (GTK_BOX (filesel->button_area), 
                          filesel->fileop_c_dir, TRUE, TRUE, 0);
       gtk_widget_show (filesel->fileop_c_dir);
@@ -640,10 +1115,10 @@ gtk_file_selection_show_fileop_buttons (GtkFileSelection *filesel)
        
   if (!filesel->fileop_del_file) 
     {
-      filesel->fileop_del_file = gtk_button_new_with_label (_("Delete File"));
-      gtk_signal_connect (GTK_OBJECT (filesel->fileop_del_file), "clicked",
-                         (GtkSignalFunc) gtk_file_selection_delete_file, 
-                         (gpointer) filesel);
+      filesel->fileop_del_file = gtk_button_new_with_mnemonic (_("De_lete File"));
+      g_signal_connect (filesel->fileop_del_file, "clicked",
+                       G_CALLBACK (gtk_file_selection_delete_file),
+                       filesel);
       gtk_box_pack_start (GTK_BOX (filesel->button_area), 
                          filesel->fileop_del_file, TRUE, TRUE, 0);
       gtk_widget_show (filesel->fileop_del_file);
@@ -651,22 +1126,23 @@ gtk_file_selection_show_fileop_buttons (GtkFileSelection *filesel)
 
   if (!filesel->fileop_ren_file)
     {
-      filesel->fileop_ren_file = gtk_button_new_with_label (_("Rename File"));
-      gtk_signal_connect (GTK_OBJECT (filesel->fileop_ren_file), "clicked",
-                         (GtkSignalFunc) gtk_file_selection_rename_file, 
-                         (gpointer) filesel);
+      filesel->fileop_ren_file = gtk_button_new_with_mnemonic (_("_Rename File"));
+      g_signal_connect (filesel->fileop_ren_file, "clicked",
+                       G_CALLBACK (gtk_file_selection_rename_file),
+                       filesel);
       gtk_box_pack_start (GTK_BOX (filesel->button_area), 
                          filesel->fileop_ren_file, TRUE, TRUE, 0);
       gtk_widget_show (filesel->fileop_ren_file);
     }
-
-  gtk_widget_queue_resize (GTK_WIDGET (filesel));
+  
+  gtk_file_selection_update_fileops (filesel);
+  
+  g_object_notify (G_OBJECT (filesel), "show_fileops");
 }
 
 void       
 gtk_file_selection_hide_fileop_buttons (GtkFileSelection *filesel)
 {
-  g_return_if_fail (filesel != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (filesel));
     
   if (filesel->fileop_ren_file)
@@ -686,51 +1162,87 @@ gtk_file_selection_hide_fileop_buttons (GtkFileSelection *filesel)
       gtk_widget_destroy (filesel->fileop_c_dir);
       filesel->fileop_c_dir = NULL;
     }
+  g_object_notify (G_OBJECT (filesel), "show_fileops");
 }
 
 
 
+/**
+ * gtk_file_selection_set_filename:
+ * @filesel: a #GtkFileSelection.
+ * @filename:  a string to set as the default file name.
+ * 
+ * Sets a default path for the file requestor. If @filename includes a
+ * directory path, then the requestor will open with that path as its
+ * current working directory.
+ *
+ * This has the consequence that in order to open the requestor with a 
+ * working directory and an empty filename, @filename must have a trailing
+ * directory separator.
+ *
+ * The encoding of @filename is the on-disk encoding, which
+ * may not be UTF-8. See g_filename_from_utf8().
+ **/
 void
 gtk_file_selection_set_filename (GtkFileSelection *filesel,
                                 const gchar      *filename)
 {
   gchar *buf;
   const char *name, *last_slash;
+  char *filename_utf8;
 
-  g_return_if_fail (filesel != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (filesel));
   g_return_if_fail (filename != NULL);
 
-  last_slash = strrchr (filename, G_DIR_SEPARATOR);
+  filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
+  g_return_if_fail (filename_utf8 != NULL);
+
+  last_slash = strrchr (filename_utf8, G_DIR_SEPARATOR);
 
   if (!last_slash)
     {
       buf = g_strdup ("");
-      name = filename;
+      name = filename_utf8;
     }
   else
     {
-      buf = g_strdup (filename);
-      buf[last_slash - filename + 1] = 0;
+      buf = g_strdup (filename_utf8);
+      buf[last_slash - filename_utf8 + 1] = 0;
       name = last_slash + 1;
     }
 
-  gtk_file_selection_populate (filesel, buf, FALSE);
+  gtk_file_selection_populate (filesel, buf, FALSE, TRUE);
 
   if (filesel->selection_entry)
     gtk_entry_set_text (GTK_ENTRY (filesel->selection_entry), name);
   g_free (buf);
+  g_object_notify (G_OBJECT (filesel), "filename");
+
+  g_free (filename_utf8);
 }
 
-gchar*
+/**
+ * gtk_file_selection_get_filename:
+ * @filesel: a #GtkFileSelection
+ * 
+ * This function returns the selected filename in the on-disk encoding
+ * (see g_filename_from_utf8()), which may or may not be the same as that
+ * used by GTK+ (UTF-8). To convert to UTF-8, call g_filename_to_utf8().
+ * The returned string points to a statically allocated buffer and
+ * should be copied if you plan to keep it around.
+ *
+ * If no file is selected then the selected directory path is returned.
+ * 
+ * Return value: currently-selected filename in the on-disk encoding.
+ **/
+G_CONST_RETURN gchar*
 gtk_file_selection_get_filename (GtkFileSelection *filesel)
 {
-  static gchar nothing[2] = "";
+  static const gchar nothing[2] = "";
   static gchar something[MAXPATHLEN*2];
   char *sys_filename;
-  char *text;
+  const char *text;
 
-  g_return_val_if_fail (filesel != NULL, nothing);
   g_return_val_if_fail (GTK_IS_FILE_SELECTION (filesel), nothing);
 
 #ifdef G_WITH_CYGWIN
@@ -739,7 +1251,9 @@ gtk_file_selection_get_filename (GtkFileSelection *filesel)
   text = gtk_entry_get_text (GTK_ENTRY (filesel->selection_entry));
   if (text)
     {
-      sys_filename = g_filename_from_utf8 (cmpl_completion_fullname (text, filesel->cmpl_state));
+      sys_filename = g_filename_from_utf8 (cmpl_completion_fullname (text, filesel->cmpl_state), -1, NULL, NULL, NULL);
+      if (!sys_filename)
+       return nothing;
       strncpy (something, sys_filename, sizeof (something));
       g_free (sys_filename);
       return something;
@@ -752,13 +1266,12 @@ void
 gtk_file_selection_complete (GtkFileSelection *filesel,
                             const gchar      *pattern)
 {
-  g_return_if_fail (filesel != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (filesel));
   g_return_if_fail (pattern != NULL);
 
   if (filesel->selection_entry)
     gtk_entry_set_text (GTK_ENTRY (filesel->selection_entry), pattern);
-  gtk_file_selection_populate (filesel, (gchar*) pattern, TRUE);
+  gtk_file_selection_populate (filesel, (gchar*) pattern, TRUE, TRUE);
 }
 
 static void
@@ -797,62 +1310,68 @@ gtk_file_selection_destroy (GtkObject *object)
       cmpl_free_state (filesel->cmpl_state);
       filesel->cmpl_state = NULL;
     }
-  
+  if (filesel->selected_names)
+    {
+      free_selected_names (filesel->selected_names);
+      filesel->selected_names = NULL;
+    } 
+
+  if (filesel->last_selected)
+    {
+      g_free (filesel->last_selected);
+      filesel->last_selected = NULL;
+    }
+
   GTK_OBJECT_CLASS (parent_class)->destroy (object);
 }
 
+static void
+gtk_file_selection_map (GtkWidget *widget)
+{
+  GtkFileSelection *filesel = GTK_FILE_SELECTION (widget);
+
+  /* Refresh the contents */
+  gtk_file_selection_populate (filesel, "", FALSE, FALSE);
+  
+  GTK_WIDGET_CLASS (parent_class)->map (widget);
+}
+
+static void
+gtk_file_selection_finalize (GObject *object)
+{
+  GtkFileSelection *filesel = GTK_FILE_SELECTION (object);
+
+  g_free (filesel->fileop_file);
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
 /* Begin file operations callbacks */
 
 static void
 gtk_file_selection_fileop_error (GtkFileSelection *fs,
                                 gchar            *error_message)
 {
-  GtkWidget *label;
-  GtkWidget *vbox;
-  GtkWidget *button;
   GtkWidget *dialog;
-  
+    
   g_return_if_fail (error_message != NULL);
-  
-  /* main dialog */
-  dialog = gtk_dialog_new ();
-  /*
-  gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
-                     (GtkSignalFunc) gtk_file_selection_fileop_destroy, 
-                     (gpointer) fs);
-  */
-  gtk_window_set_title (GTK_WINDOW (dialog), _("Error"));
-  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
-  
-  /* If file dialog is grabbed, make this dialog modal too */
-  /* When error dialog is closed, file dialog will be grabbed again */
-  if (GTK_WINDOW (fs)->modal)
-      gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
 
-  vbox = gtk_vbox_new (FALSE, 0);
-  gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox,
-                    FALSE, FALSE, 0);
-  gtk_widget_show (vbox);
-
-  label = gtk_label_new (error_message);
-  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
-  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 5);
-  gtk_widget_show (label);
+  /* main dialog */
+  dialog = gtk_message_dialog_new (GTK_WINDOW (fs),
+                                  GTK_DIALOG_DESTROY_WITH_PARENT,
+                                  GTK_MESSAGE_ERROR,
+                                  GTK_BUTTONS_CLOSE,
+                                  "%s", error_message);
 
   /* yes, we free it */
   g_free (error_message);
-  
-  /* close button */
-  button = gtk_button_new_with_label (_("Close"));
-  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
-                            (GtkSignalFunc) gtk_widget_destroy, 
-                            (gpointer) dialog);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
-                    button, TRUE, TRUE, 0);
-  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
-  gtk_widget_grab_default (button);
-  gtk_widget_show (button);
+
+  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+  g_signal_connect_swapped (dialog, "response",
+                           G_CALLBACK (gtk_widget_destroy),
+                           dialog);
 
   gtk_widget_show (dialog);
 }
@@ -863,26 +1382,39 @@ gtk_file_selection_fileop_destroy (GtkWidget *widget,
 {
   GtkFileSelection *fs = data;
 
-  g_return_if_fail (fs != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
   
   fs->fileop_dialog = NULL;
 }
 
+static gboolean
+entry_is_empty (GtkEntry *entry)
+{
+  const gchar *text = gtk_entry_get_text (entry);
+  
+  return *text == '\0';
+}
+
+static void
+gtk_file_selection_fileop_entry_changed (GtkEntry   *entry,
+                                        GtkWidget  *button)
+{
+  gtk_widget_set_sensitive (button, !entry_is_empty (entry));
+}
 
 static void
 gtk_file_selection_create_dir_confirmed (GtkWidget *widget,
                                         gpointer   data)
 {
   GtkFileSelection *fs = data;
-  gchar *dirname;
+  const gchar *dirname;
   gchar *path;
   gchar *full_path;
   gchar *sys_full_path;
   gchar *buf;
+  GError *error = NULL;
   CompletionState *cmpl_state;
   
-  g_return_if_fail (fs != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
 
   dirname = gtk_entry_get_text (GTK_ENTRY (fs->fileop_entry));
@@ -890,18 +1422,32 @@ gtk_file_selection_create_dir_confirmed (GtkWidget *widget,
   path = cmpl_reference_position (cmpl_state);
   
   full_path = g_strconcat (path, G_DIR_SEPARATOR_S, dirname, NULL);
-  sys_full_path = g_filename_from_utf8 (full_path);
+  sys_full_path = g_filename_from_utf8 (full_path, -1, NULL, NULL, &error);
+  if (error)
+    {
+      if (g_error_matches (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE))
+       buf = g_strdup_printf (_("The folder name \"%s\" contains symbols that are not allowed in filenames"), dirname);
+      else
+       buf = g_strdup_printf (_("Error creating folder \"%s\": %s\n%s"), dirname, error->message,
+                              _("You probably used symbols not allowed in filenames."));
+      gtk_file_selection_fileop_error (fs, buf);
+      g_error_free (error);
+      goto out;
+    }
+
   if (mkdir (sys_full_path, 0755) < 0) 
     {
-      buf = g_strconcat ("Error creating directory \"", dirname, "\":  ", 
-                        g_strerror (errno), NULL);
+      buf = g_strdup_printf (_("Error creating folder \"%s\": %s\n"), dirname,
+                            g_strerror (errno));
       gtk_file_selection_fileop_error (fs, buf);
     }
+
+ out:
   g_free (full_path);
   g_free (sys_full_path);
   
   gtk_widget_destroy (fs->fileop_dialog);
-  gtk_file_selection_populate (fs, "", FALSE);
+  gtk_file_selection_populate (fs, "", FALSE, FALSE);
 }
   
 static void
@@ -914,7 +1460,6 @@ gtk_file_selection_create_dir (GtkWidget *widget,
   GtkWidget *vbox;
   GtkWidget *button;
 
-  g_return_if_fail (fs != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
 
   if (fs->fileop_dialog)
@@ -923,11 +1468,12 @@ gtk_file_selection_create_dir (GtkWidget *widget,
   /* main dialog */
   dialog = gtk_dialog_new ();
   fs->fileop_dialog = dialog;
-  gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
-                     (GtkSignalFunc) gtk_file_selection_fileop_destroy, 
-                     (gpointer) fs);
-  gtk_window_set_title (GTK_WINDOW (dialog), _("Create Directory"));
+  g_signal_connect (dialog, "destroy",
+                   G_CALLBACK (gtk_file_selection_fileop_destroy),
+                   fs);
+  gtk_window_set_title (GTK_WINDOW (dialog), _("New Folder"));
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fs));
 
   /* If file dialog is grabbed, grab option dialog */
   /* When option dialog is closed, file dialog will be grabbed again */
@@ -940,71 +1486,98 @@ gtk_file_selection_create_dir (GtkWidget *widget,
                     FALSE, FALSE, 0);
   gtk_widget_show( vbox);
   
-  label = gtk_label_new (_("Directory name:"));
+  label = gtk_label_new_with_mnemonic (_("_Folder name:"));
   gtk_misc_set_alignment(GTK_MISC (label), 0.0, 0.0);
   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 5);
   gtk_widget_show (label);
 
   /*  The directory entry widget  */
   fs->fileop_entry = gtk_entry_new ();
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), fs->fileop_entry);
   gtk_box_pack_start (GTK_BOX (vbox), fs->fileop_entry, 
                      TRUE, TRUE, 5);
   GTK_WIDGET_SET_FLAGS (fs->fileop_entry, GTK_CAN_DEFAULT);
+  gtk_entry_set_activates_default (GTK_ENTRY (fs->fileop_entry), TRUE); 
   gtk_widget_show (fs->fileop_entry);
   
   /* buttons */
-  button = gtk_button_new_with_label (_("Create"));
-  gtk_signal_connect (GTK_OBJECT (button), "clicked",
-                     (GtkSignalFunc) gtk_file_selection_create_dir_confirmed, 
-                     (gpointer) fs);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
-                    button, TRUE, TRUE, 0);
-  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
-  gtk_widget_show (button);
-  
-  button = gtk_button_new_with_label (_("Cancel"));
-  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
-                            (GtkSignalFunc) gtk_widget_destroy, 
-                            (gpointer) dialog);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
-                    button, TRUE, TRUE, 0);
-  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
-  gtk_widget_grab_default (button);
-  gtk_widget_show (button);
+  button = gtk_dialog_add_button (GTK_DIALOG (dialog), 
+                                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+  g_signal_connect_swapped (button, "clicked",
+                           G_CALLBACK (gtk_widget_destroy),
+                           dialog);
+
+  gtk_widget_grab_focus (fs->fileop_entry);
+
+  button = gtk_dialog_add_button (GTK_DIALOG (dialog), 
+                                 _("C_reate"), GTK_RESPONSE_OK);
+  gtk_widget_set_sensitive (button, FALSE);
+  g_signal_connect (button, "clicked",
+                   G_CALLBACK (gtk_file_selection_create_dir_confirmed),
+                   fs);
+  g_signal_connect (fs->fileop_entry, "changed",
+                    G_CALLBACK (gtk_file_selection_fileop_entry_changed),
+                   button);
 
+  gtk_widget_grab_default (button);
+  
   gtk_widget_show (dialog);
 }
 
 static void
-gtk_file_selection_delete_file_confirmed (GtkWidget *widget,
-                                         gpointer   data)
+gtk_file_selection_delete_file_response (GtkDialog *dialog, 
+                                         gint       response_id,
+                                         gpointer   data)
 {
   GtkFileSelection *fs = data;
   CompletionState *cmpl_state;
   gchar *path;
   gchar *full_path;
   gchar *sys_full_path;
+  GError *error = NULL;
   gchar *buf;
   
-  g_return_if_fail (fs != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
 
+  if (response_id != GTK_RESPONSE_OK)
+    {
+      gtk_widget_destroy (GTK_WIDGET (dialog));
+      return;
+    }
+
   cmpl_state = (CompletionState*) fs->cmpl_state;
   path = cmpl_reference_position (cmpl_state);
   
   full_path = g_strconcat (path, G_DIR_SEPARATOR_S, fs->fileop_file, NULL);
-  sys_full_path = g_filename_from_utf8 (full_path);
+  sys_full_path = g_filename_from_utf8 (full_path, -1, NULL, NULL, &error);
+  if (error)
+    {
+      if (g_error_matches (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE))
+       buf = g_strdup_printf (_("The filename \"%s\" contains symbols that are not allowed in filenames"),
+                              fs->fileop_file);
+      else
+       buf = g_strdup_printf (_("Error deleting file \"%s\": %s\n%s"),
+                              fs->fileop_file, error->message,
+                              _("It probably contains symbols not allowed in filenames."));
+      
+      gtk_file_selection_fileop_error (fs, buf);
+      g_error_free (error);
+      goto out;
+    }
+
   if (unlink (sys_full_path) < 0) 
     {
-      buf = g_strconcat ("Error deleting file \"", fs->fileop_file, "\":  ", 
-                        g_strerror (errno), NULL);
+      buf = g_strdup_printf (_("Error deleting file \"%s\": %s"),
+                            fs->fileop_file, g_strerror (errno));
       gtk_file_selection_fileop_error (fs, buf);
     }
+  
+ out:
   g_free (full_path);
   g_free (sys_full_path);
   
   gtk_widget_destroy (fs->fileop_dialog);
-  gtk_file_selection_populate (fs, "", FALSE);
+  gtk_file_selection_populate (fs, "", FALSE, TRUE);
 }
 
 static void
@@ -1012,18 +1585,13 @@ gtk_file_selection_delete_file (GtkWidget *widget,
                                gpointer   data)
 {
   GtkFileSelection *fs = data;
-  GtkWidget *label;
-  GtkWidget *vbox;
-  GtkWidget *button;
   GtkWidget *dialog;
-  gchar *filename;
-  gchar *buf;
+  const gchar *filename;
   
-  g_return_if_fail (fs != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
 
   if (fs->fileop_dialog)
-         return;
+    return;
 
 #ifdef G_WITH_CYGWIN
   translate_win32_path (fs);
@@ -1033,56 +1601,36 @@ gtk_file_selection_delete_file (GtkWidget *widget,
   if (strlen (filename) < 1)
     return;
 
-  fs->fileop_file = filename;
+  g_free (fs->fileop_file);
+  fs->fileop_file = g_strdup (filename);
   
   /* main dialog */
-  fs->fileop_dialog = dialog = gtk_dialog_new ();
-  gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
-                     (GtkSignalFunc) gtk_file_selection_fileop_destroy, 
-                     (gpointer) fs);
+  fs->fileop_dialog = dialog = 
+    gtk_message_dialog_new (GTK_WINDOW (fs),
+                            GTK_WINDOW (fs)->modal ? GTK_DIALOG_MODAL : 0,
+                            GTK_MESSAGE_QUESTION,
+                            GTK_BUTTONS_NONE,
+                            _("Really delete file \"%s\" ?"), filename);
+
+  g_signal_connect (dialog, "destroy",
+                   G_CALLBACK (gtk_file_selection_fileop_destroy),
+                   fs);
   gtk_window_set_title (GTK_WINDOW (dialog), _("Delete File"));
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
-
-  /* If file dialog is grabbed, grab option dialog */
-  /* When option dialog is closed, file dialog will be grabbed again */
-  if (GTK_WINDOW (fs)->modal)
-      gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-  
-  vbox = gtk_vbox_new (FALSE, 0);
-  gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox,
-                    FALSE, FALSE, 0);
-  gtk_widget_show (vbox);
-
-  buf = g_strconcat ("Really delete file \"", filename, "\" ?", NULL);
-  label = gtk_label_new (buf);
-  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
-  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 5);
-  gtk_widget_show (label);
-  g_free (buf);
   
   /* buttons */
-  button = gtk_button_new_with_label (_("Delete"));
-  gtk_signal_connect (GTK_OBJECT (button), "clicked",
-                     (GtkSignalFunc) gtk_file_selection_delete_file_confirmed, 
-                     (gpointer) fs);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
-                     button, TRUE, TRUE, 0);
-  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
-  gtk_widget_show (button);
-  
-  button = gtk_button_new_with_label (_("Cancel"));
-  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
-                            (GtkSignalFunc) gtk_widget_destroy, 
-                            (gpointer) dialog);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
-                     button, TRUE, TRUE, 0);
-  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
-  gtk_widget_grab_default (button);
-  gtk_widget_show (button);
+  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                          GTK_STOCK_DELETE, GTK_RESPONSE_OK,
+                          NULL);
 
-  gtk_widget_show (dialog);
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
 
+  g_signal_connect (dialog, "response",
+                    G_CALLBACK (gtk_file_selection_delete_file_response),
+                    fs);
+  
+  gtk_widget_show (dialog);
 }
 
 static void
@@ -1091,15 +1639,15 @@ gtk_file_selection_rename_file_confirmed (GtkWidget *widget,
 {
   GtkFileSelection *fs = data;
   gchar *buf;
-  gchar *file;
+  const gchar *file;
   gchar *path;
   gchar *new_filename;
   gchar *old_filename;
   gchar *sys_new_filename;
   gchar *sys_old_filename;
   CompletionState *cmpl_state;
+  GError *error = NULL;
   
-  g_return_if_fail (fs != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
 
   file = gtk_entry_get_text (GTK_ENTRY (fs->fileop_entry));
@@ -1109,22 +1657,55 @@ gtk_file_selection_rename_file_confirmed (GtkWidget *widget,
   new_filename = g_strconcat (path, G_DIR_SEPARATOR_S, file, NULL);
   old_filename = g_strconcat (path, G_DIR_SEPARATOR_S, fs->fileop_file, NULL);
 
-  sys_new_filename = g_filename_from_utf8 (new_filename);
-  sys_old_filename = g_filename_from_utf8 (old_filename);
+  sys_new_filename = g_filename_from_utf8 (new_filename, -1, NULL, NULL, &error);
+  if (error)
+    {
+      if (g_error_matches (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE))
+       buf = g_strdup_printf (_("The file name \"%s\" contains symbols that are not allowed in filenames"), new_filename);
+      else
+       buf = g_strdup_printf (_("Error renaming file to \"%s\": %s\n%s"),
+                              new_filename, error->message,
+                              _("You probably used symbols not allowed in filenames."));
+      gtk_file_selection_fileop_error (fs, buf);
+      g_error_free (error);
+      goto out1;
+    }
 
+  sys_old_filename = g_filename_from_utf8 (old_filename, -1, NULL, NULL, &error);
+  if (error)
+    {
+      if (g_error_matches (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE))
+       buf = g_strdup_printf (_("The file name \"%s\" contains symbols that are not allowed in filenames"), old_filename);
+      else
+       buf = g_strdup_printf (_("Error renaming file \"%s\": %s\n%s"),
+                              old_filename, error->message,
+                              _("It probably contains symbols not allowed in filenames."));
+      gtk_file_selection_fileop_error (fs, buf);
+      g_error_free (error);
+      goto out2;
+    }
+  
   if (rename (sys_old_filename, sys_new_filename) < 0) 
     {
-      buf = g_strconcat ("Error renaming file \"", file, "\":  ", 
-                        g_strerror (errno), NULL);
+      buf = g_strdup_printf (_("Error renaming file \"%s\" to \"%s\": %s"),
+                            sys_old_filename, sys_new_filename,
+                            g_strerror (errno));
       gtk_file_selection_fileop_error (fs, buf);
+      goto out2;
     }
+  
+  gtk_file_selection_populate (fs, "", FALSE, FALSE);
+  gtk_entry_set_text (GTK_ENTRY (fs->selection_entry), file);
+  
+ out2:
+  g_free (sys_old_filename);
+
+ out1:
   g_free (new_filename);
   g_free (old_filename);
   g_free (sys_new_filename);
-  g_free (sys_old_filename);
   
   gtk_widget_destroy (fs->fileop_dialog);
-  gtk_file_selection_populate (fs, "", FALSE);
 }
   
 static void
@@ -1138,23 +1719,24 @@ gtk_file_selection_rename_file (GtkWidget *widget,
   GtkWidget *button;
   gchar *buf;
   
-  g_return_if_fail (fs != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
 
   if (fs->fileop_dialog)
          return;
 
-  fs->fileop_file = gtk_entry_get_text (GTK_ENTRY (fs->selection_entry));
+  g_free (fs->fileop_file);
+  fs->fileop_file = g_strdup (gtk_entry_get_text (GTK_ENTRY (fs->selection_entry)));
   if (strlen (fs->fileop_file) < 1)
     return;
   
   /* main dialog */
   fs->fileop_dialog = dialog = gtk_dialog_new ();
-  gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
-                     (GtkSignalFunc) gtk_file_selection_fileop_destroy, 
-                     (gpointer) fs);
+  g_signal_connect (dialog, "destroy",
+                   G_CALLBACK (gtk_file_selection_fileop_destroy),
+                   fs);
   gtk_window_set_title (GTK_WINDOW (dialog), _("Rename File"));
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fs));
 
   /* If file dialog is grabbed, grab option dialog */
   /* When option dialog  closed, file dialog will be grabbed again */
@@ -1167,8 +1749,8 @@ gtk_file_selection_rename_file (GtkWidget *widget,
                      FALSE, FALSE, 0);
   gtk_widget_show(vbox);
   
-  buf = g_strconcat ("Rename file \"", fs->fileop_file, "\" to:", NULL);
-  label = gtk_label_new(buf);
+  buf = g_strdup_printf (_("Rename file \"%s\" to:"), fs->fileop_file);
+  label = gtk_label_new (buf);
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 5);
   gtk_widget_show (label);
@@ -1179,35 +1761,75 @@ gtk_file_selection_rename_file (GtkWidget *widget,
   gtk_box_pack_start (GTK_BOX (vbox), fs->fileop_entry, 
                      TRUE, TRUE, 5);
   GTK_WIDGET_SET_FLAGS (fs->fileop_entry, GTK_CAN_DEFAULT);
+  gtk_entry_set_activates_default (GTK_ENTRY (fs->fileop_entry), TRUE); 
   gtk_widget_show (fs->fileop_entry);
   
-  gtk_entry_set_text (GTK_ENTRY (fs->fileop_entry), fs->fileop_file);
-  gtk_editable_select_region (GTK_EDITABLE (fs->fileop_entry),
-                             0, strlen (fs->fileop_file));
+  gtk_entry_set_text (GTK_ENTRY (fs->fileop_entry), fs->fileop_file);
+  gtk_editable_select_region (GTK_EDITABLE (fs->fileop_entry),
+                             0, strlen (fs->fileop_file));
+
+  /* buttons */
+  button = gtk_dialog_add_button (GTK_DIALOG (dialog), 
+                                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+  g_signal_connect_swapped (button, "clicked",
+                           G_CALLBACK (gtk_widget_destroy),
+                           dialog);
+
+  gtk_widget_grab_focus (fs->fileop_entry);
+
+  button = gtk_dialog_add_button (GTK_DIALOG (dialog), 
+                                 _("_Rename"), GTK_RESPONSE_OK);
+  g_signal_connect (button, "clicked",
+                   G_CALLBACK (gtk_file_selection_rename_file_confirmed),
+                   fs);
+  g_signal_connect (fs->fileop_entry, "changed",
+                   G_CALLBACK (gtk_file_selection_fileop_entry_changed),
+                   button);
+
+  gtk_widget_grab_default (button);
+  
+  gtk_widget_show (dialog);
+}
+
+static gint
+gtk_file_selection_insert_text (GtkWidget   *widget,
+                               const gchar *new_text,
+                               gint         new_text_length,
+                               gint        *position,
+                               gpointer     user_data)
+{
+  gchar *filename;
+
+  filename = g_filename_from_utf8 (new_text, new_text_length, NULL, NULL, NULL);
+
+  if (!filename)
+    {
+      gdk_display_beep (gtk_widget_get_display (widget));
+      g_signal_stop_emission_by_name (widget, "insert_text");
+      return FALSE;
+    }
+  
+  g_free (filename);
+  
+  return TRUE;
+}
 
-  /* buttons */
-  button = gtk_button_new_with_label (_("Rename"));
-  gtk_signal_connect (GTK_OBJECT (button), "clicked",
-                     (GtkSignalFunc) gtk_file_selection_rename_file_confirmed, 
-                     (gpointer) fs);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
-                     button, TRUE, TRUE, 0);
-  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
-  gtk_widget_show (button);
-  
-  button = gtk_button_new_with_label (_("Cancel"));
-  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
-                            (GtkSignalFunc) gtk_widget_destroy, 
-                            (gpointer) dialog);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
-                     button, TRUE, TRUE, 0);
-  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
-  gtk_widget_grab_default (button);
-  gtk_widget_show (button);
+static void
+gtk_file_selection_update_fileops (GtkFileSelection *fs)
+{
+  gboolean sensitive;
 
-  gtk_widget_show (dialog);
-}
+  if (!fs->selection_entry)
+    return;
+
+  sensitive = !entry_is_empty (GTK_ENTRY (fs->selection_entry));
 
+  if (fs->fileop_del_file)
+    gtk_widget_set_sensitive (fs->fileop_del_file, sensitive);
+  
+  if (fs->fileop_ren_file)
+    gtk_widget_set_sensitive (fs->fileop_ren_file, sensitive);
+}
 
 static gint
 gtk_file_selection_key_press (GtkWidget   *widget,
@@ -1220,29 +1842,25 @@ gtk_file_selection_key_press (GtkWidget   *widget,
   g_return_val_if_fail (widget != NULL, FALSE);
   g_return_val_if_fail (event != NULL, FALSE);
 
-  if (event->keyval == GDK_Tab)
+  if ((event->keyval == GDK_Tab || event->keyval == GDK_KP_Tab) &&
+      (event->state & gtk_accelerator_get_default_mod_mask ()) == 0)
     {
       fs = GTK_FILE_SELECTION (user_data);
 #ifdef G_WITH_CYGWIN
       translate_win32_path (fs);
 #endif
-      text = gtk_entry_get_text (GTK_ENTRY (fs->selection_entry));
+      text = g_strdup (gtk_entry_get_text (GTK_ENTRY (fs->selection_entry)));
 
-      text = g_strdup (text);
-
-      gtk_file_selection_populate (fs, text, TRUE);
+      gtk_file_selection_populate (fs, text, TRUE, TRUE);
 
       g_free (text);
 
-      gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
-
       return TRUE;
     }
 
   return FALSE;
 }
 
-
 static void
 gtk_file_selection_history_callback (GtkWidget *widget,
                                     gpointer   data)
@@ -1251,7 +1869,6 @@ gtk_file_selection_history_callback (GtkWidget *widget,
   HistoryCallbackArg *callback_arg;
   GList *list;
 
-  g_return_if_fail (fs != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
 
   list = fs->history_list;
@@ -1261,7 +1878,7 @@ gtk_file_selection_history_callback (GtkWidget *widget,
     
     if (callback_arg->menu_item == widget)
       {
-       gtk_file_selection_populate (fs, callback_arg->directory, FALSE);
+       gtk_file_selection_populate (fs, callback_arg->directory, FALSE, FALSE);
        break;
       }
     
@@ -1280,7 +1897,6 @@ gtk_file_selection_update_history_menu (GtkFileSelection *fs,
   gint dir_len;
   gint i;
   
-  g_return_if_fail (fs != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
   g_return_if_fail (current_directory != NULL);
   
@@ -1338,10 +1954,10 @@ gtk_file_selection_update_history_menu (GtkFileSelection *fs,
          
          fs->history_list = g_list_append (fs->history_list, callback_arg);
          
-         gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
-                             (GtkSignalFunc) gtk_file_selection_history_callback,
-                             (gpointer) fs);
-         gtk_menu_append (GTK_MENU (fs->history_menu), menu_item);
+         g_signal_connect (menu_item, "activate",
+                           G_CALLBACK (gtk_file_selection_history_callback),
+                           fs);
+         gtk_menu_shell_append (GTK_MENU_SHELL (fs->history_menu), menu_item);
          gtk_widget_show (menu_item);
        }
     }
@@ -1351,156 +1967,142 @@ gtk_file_selection_update_history_menu (GtkFileSelection *fs,
   g_free (current_dir);
 }
 
-static void
-gtk_file_selection_file_button (GtkWidget      *widget,
-                               gint            row, 
-                               gint            column, 
-                               GdkEventButton *bevent,
-                               gpointer        user_data)
+static gchar *
+get_real_filename (gchar    *filename,
+                   gboolean  free_old)
 {
-  GtkFileSelection *fs = NULL;
-  gchar *filename, *temp = NULL;
-  
-  g_return_if_fail (GTK_IS_CLIST (widget));
-
-  fs = user_data;
-  g_return_if_fail (fs != NULL);
-  g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
-  
-  gtk_clist_get_text (GTK_CLIST (fs->file_list), row, 0, &temp);
-  filename = g_strdup (temp);
-
 #ifdef G_WITH_CYGWIN
   /* Check to see if the selection was a drive selector */
-  if (isalpha (filename[0]) && (filename[1] == ':')) {
-    /* It is... map it to a CYGWIN32 drive */
-    gchar *temp_filename = g_strdup_printf ("//%c/", tolower (filename[0]));
-    g_free(filename);
-    filename = temp_filename;
-  }
-#endif /* G_WITH_CYGWIN */
-
-  if (filename)
+  if (isalpha (filename[0]) && (filename[1] == ':'))
     {
-      if (bevent)
-       switch (bevent->type)
-         {
-         case GDK_2BUTTON_PRESS:
-           gtk_button_clicked (GTK_BUTTON (fs->ok_button));
-           break;
-           
-         default:
-           gtk_entry_set_text (GTK_ENTRY (fs->selection_entry), filename);
-           break;
-         }
-      else
-       gtk_entry_set_text (GTK_ENTRY (fs->selection_entry), filename);
+      gchar temp_filename[MAX_PATH];
+      int len;
 
-      g_free (filename);
+      cygwin_conv_to_posix_path (filename, temp_filename);
+
+      /* we need trailing '/'. */
+      len = strlen (temp_filename);
+      if (len > 0 && temp_filename[len-1] != '/')
+        {
+          temp_filename[len]   = '/';
+          temp_filename[len+1] = '\0';
+        }
+      
+      if (free_old)
+       g_free (filename);
+
+      return g_strdup (temp_filename);
     }
+#endif /* G_WITH_CYGWIN */
+  return filename;
 }
 
 static void
-gtk_file_selection_dir_button (GtkWidget      *widget,
-                              gint            row, 
-                              gint            column, 
-                              GdkEventButton *bevent,
-                              gpointer        user_data)
-{
-  GtkFileSelection *fs = NULL;
-  gchar *filename, *temp = NULL;
-
-  g_return_if_fail (GTK_IS_CLIST (widget));
-
-  fs = GTK_FILE_SELECTION (user_data);
-  g_return_if_fail (fs != NULL);
-  g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
+gtk_file_selection_file_activate (GtkTreeView       *tree_view,
+                                 GtkTreePath       *path,
+                                 GtkTreeViewColumn *column,
+                                 gpointer           user_data)
+{
+  GtkFileSelection *fs = GTK_FILE_SELECTION (user_data);
+  GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
+  GtkTreeIter iter;  
+  gchar *filename;
+  
+  gtk_tree_model_get_iter (model, &iter, path);
+  gtk_tree_model_get (model, &iter, FILE_COLUMN, &filename, -1);
+  filename = get_real_filename (filename, TRUE);
+  gtk_entry_set_text (GTK_ENTRY (fs->selection_entry), filename);
+  gtk_button_clicked (GTK_BUTTON (fs->ok_button));
 
-  gtk_clist_get_text (GTK_CLIST (fs->dir_list), row, 0, &temp);
-  filename = g_strdup (temp);
+  g_free (filename);
+}
 
-  if (filename)
-    {
-      if (bevent)
-       switch (bevent->type)
-         {
-         case GDK_2BUTTON_PRESS:
-           gtk_file_selection_populate (fs, filename, FALSE);
-           break;
-         
-         default:
-           gtk_entry_set_text (GTK_ENTRY (fs->selection_entry), filename);
-           break;
-         }
-      else
-       gtk_entry_set_text (GTK_ENTRY (fs->selection_entry), filename);
+static void
+gtk_file_selection_dir_activate (GtkTreeView       *tree_view,
+                                GtkTreePath       *path,
+                                GtkTreeViewColumn *column,
+                                gpointer           user_data)
+{
+  GtkFileSelection *fs = GTK_FILE_SELECTION (user_data);
+  GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
+  GtkTreeIter iter;
+  gchar *filename;
 
-      g_free (filename);
-    }
+  gtk_tree_model_get_iter (model, &iter, path);
+  gtk_tree_model_get (model, &iter, DIR_COLUMN, &filename, -1);
+  filename = get_real_filename (filename, TRUE);
+  gtk_file_selection_populate (fs, filename, FALSE, FALSE);
+  g_free (filename);
 }
 
-#if defined(G_OS_WIN32) || defined(G_WITH_CYGWIN)
+#ifdef G_PLATFORM_WIN32
 
 static void
-win32_gtk_add_drives_to_dir_list (GtkWidget *the_dir_list)
+win32_gtk_add_drives_to_dir_list (GtkListStore *model)
 {
-  gchar *text[2], *textPtr;
+  gchar *textPtr;
   gchar buffer[128];
-  char volumeNameBuf[128];
   char formatBuffer[128];
+  GtkTreeIter iter;
 
-  text[1] = NULL;
-
-  /* Get the Drives string */
+  /* Get the drives string */
   GetLogicalDriveStrings (sizeof (buffer), buffer);
 
   /* Add the drives as necessary */
   textPtr = buffer;
-  while (*textPtr != '\0') {
-    /* Get the volume information for this drive */
-    if ((tolower (textPtr[0]) != 'a') && (tolower (textPtr[0]) != 'b'))
-      {
-       /* Ignore floppies (?) */
-       DWORD maxComponentLength, flags;
-
-       GetVolumeInformation (textPtr,
-                             volumeNameBuf, sizeof(volumeNameBuf),
-                             NULL, &maxComponentLength,
-                             &flags, NULL, 0);
-       /* Build the actual displayable string */
-
-       sprintf (formatBuffer, "%c:\\", toupper(textPtr[0]));
-#if 0 /* HB: removed to allow drive change AND directory update with one click */
-       if (strlen (volumeNameBuf) > 0)
-         sprintf (formatBuffer, "%s (%s)", formatBuffer, volumeNameBuf);
-#endif
-       /* Add to the list */
-       text[0] = formatBuffer;
-       gtk_clist_append (GTK_CLIST (the_dir_list), text);
-      }
-    textPtr += (strlen (textPtr) + 1);
-  }
+  while (*textPtr != '\0')
+    {
+      /* Ignore floppies (?) */
+      if (GetDriveType (textPtr) != DRIVE_REMOVABLE)
+       {
+         /* Build the actual displayable string */
+         g_snprintf (formatBuffer, sizeof (formatBuffer), "%c:\\", toupper (textPtr[0]));
+
+         /* Add to the list */
+         gtk_list_store_append (model, &iter);
+         gtk_list_store_set (model, &iter, DIR_COLUMN, formatBuffer, -1);
+       }
+      textPtr += (strlen (textPtr) + 1);
+    }
 }
 #endif
 
+static gchar *
+escape_underscores (const gchar *str)
+{
+  GString *result = g_string_new (NULL);
+  while (*str)
+    {
+      if (*str == '_')
+       g_string_append_c (result, '_');
+
+      g_string_append_c (result, *str);
+      str++;
+    }
+
+  return g_string_free (result, FALSE);
+}
+
 static void
 gtk_file_selection_populate (GtkFileSelection *fs,
                             gchar            *rel_path,
-                            gint              try_complete)
+                            gboolean          try_complete,
+                            gboolean          reset_entry)
 {
   CompletionState *cmpl_state;
   PossibleCompletion* poss;
+  GtkTreeIter iter;
+  GtkListStore *dir_model;
+  GtkListStore *file_model;
   gchar* filename;
   gchar* rem_path = rel_path;
   gchar* sel_text;
-  gchar* text[2];
   gint did_recurse = FALSE;
   gint possible_count = 0;
   gint selection_index = -1;
   
-  g_return_if_fail (fs != NULL);
   g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
-  
+
   cmpl_state = (CompletionState*) fs->cmpl_state;
   poss = cmpl_completion_matches (rel_path, &rem_path, cmpl_state);
 
@@ -1513,18 +2115,17 @@ gtk_file_selection_populate (GtkFileSelection *fs,
 
   g_assert (cmpl_state->reference_dir);
 
-  gtk_clist_freeze (GTK_CLIST (fs->dir_list));
-  gtk_clist_clear (GTK_CLIST (fs->dir_list));
-  gtk_clist_freeze (GTK_CLIST (fs->file_list));
-  gtk_clist_clear (GTK_CLIST (fs->file_list));
+  dir_model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (fs->dir_list)));
+  file_model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (fs->file_list)));
 
-  /* Set the dir_list to include ./ and ../ */
-  text[1] = NULL;
-  text[0] = "." G_DIR_SEPARATOR_S;
-  gtk_clist_append (GTK_CLIST (fs->dir_list), text);
+  gtk_list_store_clear (dir_model);
+  gtk_list_store_clear (file_model);
 
-  text[0] = ".." G_DIR_SEPARATOR_S;
-  gtk_clist_append (GTK_CLIST (fs->dir_list), text);
+  /* Set the dir list to include ./ and ../ */
+  gtk_list_store_append (dir_model, &iter);
+  gtk_list_store_set (dir_model, &iter, DIR_COLUMN, "." G_DIR_SEPARATOR_S, -1);
+  gtk_list_store_append (dir_model, &iter);
+  gtk_list_store_set (dir_model, &iter, DIR_COLUMN, ".." G_DIR_SEPARATOR_S, -1);
 
   while (poss)
     {
@@ -1534,31 +2135,30 @@ gtk_file_selection_populate (GtkFileSelection *fs,
 
           filename = cmpl_this_completion (poss);
 
-         text[0] = filename;
-         
           if (cmpl_is_directory (poss))
             {
               if (strcmp (filename, "." G_DIR_SEPARATOR_S) != 0 &&
                   strcmp (filename, ".." G_DIR_SEPARATOR_S) != 0)
-               gtk_clist_append (GTK_CLIST (fs->dir_list), text);
+               {
+                 gtk_list_store_append (dir_model, &iter);
+                 gtk_list_store_set (dir_model, &iter, DIR_COLUMN, filename, -1);
+               }
            }
           else
            {
-             gtk_clist_append (GTK_CLIST (fs->file_list), text);
+             gtk_list_store_append (file_model, &iter);
+             gtk_list_store_set (file_model, &iter, DIR_COLUMN, filename, -1);
             }
        }
 
       poss = cmpl_next_completion (cmpl_state);
     }
 
-#if defined(G_OS_WIN32) || defined(G_WITH_CYGWIN)
+#ifdef G_PLATFORM_WIN32
   /* For Windows, add drives as potential selections */
-  win32_gtk_add_drives_to_dir_list (fs->dir_list);
+  win32_gtk_add_drives_to_dir_list (dir_model);
 #endif
 
-  gtk_clist_thaw (GTK_CLIST (fs->dir_list));
-  gtk_clist_thaw (GTK_CLIST (fs->file_list));
-
   /* File lists are set. */
 
   g_assert (cmpl_state->reference_dir);
@@ -1580,7 +2180,7 @@ gtk_file_selection_populate (GtkFileSelection *fs,
 
               did_recurse = TRUE;
 
-              gtk_file_selection_populate (fs, dir_name, TRUE);
+              gtk_file_selection_populate (fs, dir_name, TRUE, TRUE);
 
               g_free (dir_name);
             }
@@ -1599,7 +2199,7 @@ gtk_file_selection_populate (GtkFileSelection *fs,
            gtk_entry_set_text (GTK_ENTRY (fs->selection_entry), rem_path);
         }
     }
-  else
+  else if (reset_entry)
     {
       if (fs->selection_entry)
        gtk_entry_set_text (GTK_ENTRY (fs->selection_entry), "");
@@ -1608,15 +2208,16 @@ gtk_file_selection_populate (GtkFileSelection *fs,
   if (!did_recurse)
     {
       if (fs->selection_entry)
-       gtk_entry_set_position (GTK_ENTRY (fs->selection_entry), selection_index);
+       gtk_editable_set_position (GTK_EDITABLE (fs->selection_entry),
+                                  selection_index);
 
       if (fs->selection_entry)
        {
-         sel_text = g_strconcat (_("Selection: "),
-                                 cmpl_reference_position (cmpl_state),
-                                 NULL);
+         char *escaped = escape_underscores (cmpl_reference_position (cmpl_state));
+         sel_text = g_strconcat (_("_Selection: "), escaped, NULL);
+         g_free (escaped);
 
-         gtk_label_set_text (GTK_LABEL (fs->selection_text), sel_text);
+         gtk_label_set_text_with_mnemonic (GTK_LABEL (fs->selection_text), sel_text);
          g_free (sel_text);
        }
 
@@ -1633,7 +2234,7 @@ gtk_file_selection_abort (GtkFileSelection *fs)
 {
   gchar err_buf[256];
 
-  sprintf (err_buf, _("Directory unreadable: %s"), cmpl_strerror (cmpl_errno));
+  g_snprintf (err_buf, sizeof (err_buf), _("Folder unreadable: %s"), cmpl_strerror (cmpl_errno));
 
   /*  BEEP gdk_beep();  */
 
@@ -1641,6 +2242,278 @@ gtk_file_selection_abort (GtkFileSelection *fs)
     gtk_label_set_text (GTK_LABEL (fs->selection_text), err_buf);
 }
 
+/**
+ * gtk_file_selection_set_select_multiple:
+ * @filesel: a #GtkFileSelection
+ * @select_multiple: whether or not the user is allowed to select multiple
+ * files in the file list.
+ *
+ * Sets whether the user is allowed to select multiple files in the file list.
+ * Use gtk_file_selection_get_selections () to get the list of selected files.
+ **/
+void
+gtk_file_selection_set_select_multiple (GtkFileSelection *filesel,
+                                       gboolean          select_multiple)
+{
+  GtkTreeSelection *sel;
+  GtkSelectionMode mode;
+
+  g_return_if_fail (GTK_IS_FILE_SELECTION (filesel));
+
+  sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (filesel->file_list));
+
+  mode = select_multiple ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE;
+
+  if (mode != gtk_tree_selection_get_mode (sel))
+    {
+      gtk_tree_selection_set_mode (sel, mode);
+
+      g_object_notify (G_OBJECT (filesel), "select-multiple");
+    }
+}
+
+/**
+ * gtk_file_selection_get_select_multiple:
+ * @filesel: a #GtkFileSelection
+ *
+ * Determines whether or not the user is allowed to select multiple files in
+ * the file list. See gtk_file_selection_set_select_multiple().
+ *
+ * Return value: %TRUE if the user is allowed to select multiple files in the
+ * file list
+ **/
+gboolean
+gtk_file_selection_get_select_multiple (GtkFileSelection *filesel)
+{
+  GtkTreeSelection *sel;
+
+  g_return_val_if_fail (GTK_IS_FILE_SELECTION (filesel), FALSE);
+
+  sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (filesel->file_list));
+  return (gtk_tree_selection_get_mode (sel) == GTK_SELECTION_MULTIPLE);
+}
+
+static void
+multiple_changed_foreach (GtkTreeModel *model,
+                         GtkTreePath  *path,
+                         GtkTreeIter  *iter,
+                         gpointer      data)
+{
+  GPtrArray *names = data;
+  gchar *filename;
+
+  gtk_tree_model_get (model, iter, FILE_COLUMN, &filename, -1);
+
+  g_ptr_array_add (names, filename);
+}
+
+static void
+free_selected_names (GPtrArray *names)
+{
+  gint i;
+
+  for (i = 0; i < names->len; i++)
+    g_free (g_ptr_array_index (names, i));
+
+  g_ptr_array_free (names, TRUE);
+}
+
+static void
+gtk_file_selection_file_changed (GtkTreeSelection *selection,
+                                gpointer          user_data)
+{
+  GtkFileSelection *fs = GTK_FILE_SELECTION (user_data);
+  GPtrArray *new_names;
+  gchar *filename;
+  const gchar *entry;
+  gint index = -1;
+
+  new_names = g_ptr_array_sized_new (8);
+
+  gtk_tree_selection_selected_foreach (selection,
+                                      multiple_changed_foreach,
+                                      new_names);
+
+  /* nothing selected */
+  if (new_names->len == 0)
+    {
+      g_ptr_array_free (new_names, TRUE);
+
+      if (fs->selected_names != NULL)
+       {
+         free_selected_names (fs->selected_names);
+         fs->selected_names = NULL;
+       }
+
+      goto maybe_clear_entry;
+    }
+
+  if (new_names->len != 1)
+    {
+      GPtrArray *old_names = fs->selected_names;
+
+      if (old_names != NULL)
+       {
+         /* A common case is selecting a range of files from top to bottom,
+          * so quickly check for that to avoid looping over the entire list
+          */
+         if (compare_utf8_filenames (g_ptr_array_index (old_names, old_names->len - 1),
+                                     g_ptr_array_index (new_names, new_names->len - 1)) != 0)
+           index = new_names->len - 1;
+         else
+           {
+             gint i = 0, j = 0, cmp;
+
+             /* do a quick diff, stopping at the first file not in the
+              * old list
+              */
+             while (i < old_names->len && j < new_names->len)
+               {
+                 cmp = compare_utf8_filenames (g_ptr_array_index (old_names, i),
+                                               g_ptr_array_index (new_names, j));
+                 if (cmp < 0)
+                   {
+                     i++;
+                   }
+                 else if (cmp == 0)
+                   {
+                     i++;
+                     j++;
+                   }
+                 else if (cmp > 0)
+                   {
+                     index = j;
+                     break;
+                   }
+               }
+
+             /* we ran off the end of the old list */
+             if (index == -1 && i < new_names->len)
+               index = j;
+           }
+       }
+      else
+       {
+         /* A phantom anchor still exists at the point where the last item
+          * was selected, which is used for subsequent range selections.
+          * So search up from there.
+          */
+         if (fs->last_selected &&
+             compare_utf8_filenames (fs->last_selected,
+                                     g_ptr_array_index (new_names, 0)) == 0)
+           index = new_names->len - 1;
+         else
+           index = 0;
+       }
+    }
+  else
+    index = 0;
+
+  if (fs->selected_names != NULL)
+    free_selected_names (fs->selected_names);
+
+  fs->selected_names = new_names;
+
+  if (index != -1)
+    {
+      if (fs->last_selected != NULL)
+       g_free (fs->last_selected);
+
+      fs->last_selected = g_strdup (g_ptr_array_index (new_names, index));
+      filename = get_real_filename (fs->last_selected, FALSE);
+
+      gtk_entry_set_text (GTK_ENTRY (fs->selection_entry), filename);
+
+      if (filename != fs->last_selected)
+       g_free (filename);
+      
+      return;
+    }
+  
+maybe_clear_entry:
+
+  entry = gtk_entry_get_text (GTK_ENTRY (fs->selection_entry));
+  if ((entry != NULL) && (fs->last_selected != NULL) &&
+      (compare_utf8_filenames (entry, fs->last_selected) == 0))
+    gtk_entry_set_text (GTK_ENTRY (fs->selection_entry), "");
+}
+
+/**
+ * gtk_file_selection_get_selections:
+ * @filesel: a #GtkFileSelection
+ *
+ * Retrieves the list of file selections the user has made in the dialog box.
+ * This function is intended for use when the user can select multiple files
+ * in the file list. The first file in the list is equivalent to what
+ * gtk_file_selection_get_filename() would return.
+ *
+ * The filenames are in the encoding of g_filename_from_utf8(), which may or 
+ * may not be the same as that used by GTK+ (UTF-8). To convert to UTF-8, call
+ * g_filename_to_utf8() on each string.
+ *
+ * Return value: a newly-allocated %NULL-terminated array of strings. Use
+ * g_strfreev() to free it.
+ **/
+gchar **
+gtk_file_selection_get_selections (GtkFileSelection *filesel)
+{
+  GPtrArray *names;
+  gchar **selections;
+  gchar *filename, *dirname;
+  gchar *current, *buf;
+  gint i, count;
+  gboolean unselected_entry;
+
+  g_return_val_if_fail (GTK_IS_FILE_SELECTION (filesel), NULL);
+
+  filename = g_strdup (gtk_file_selection_get_filename (filesel));
+
+  if (strlen (filename) == 0)
+    {
+      g_free (filename);
+      return NULL;
+    }
+
+  names = filesel->selected_names;
+
+  if (names != NULL)
+    selections = g_new (gchar *, names->len + 2);
+  else
+    selections = g_new (gchar *, 2);
+
+  count = 0;
+  unselected_entry = TRUE;
+
+  if (names != NULL)
+    {
+      dirname = g_path_get_dirname (filename);
+
+      for (i = 0; i < names->len; i++)
+       {
+         buf = g_filename_from_utf8 (g_ptr_array_index (names, i), -1,
+                                     NULL, NULL, NULL);
+         current = g_build_filename (dirname, buf, NULL);
+         g_free (buf);
+
+         selections[count++] = current;
+
+         if (unselected_entry && compare_sys_filenames (current, filename) == 0)
+           unselected_entry = FALSE;
+       }
+
+      g_free (dirname);
+    }
+
+  if (unselected_entry)
+    selections[count++] = filename;
+  else
+    g_free (filename);
+
+  selections[count] = NULL;
+
+  return selections;
+}
+
 /**********************************************************************/
 /*                       External Interface                          */
 /**********************************************************************/
@@ -1671,11 +2544,11 @@ cmpl_last_valid_char (CompletionState *cmpl_state)
   return cmpl_state->last_valid_char;
 }
 
-static gchar*
-cmpl_completion_fullname (gchar           *text,
+static const gchar*
+cmpl_completion_fullname (const gchar     *text,
                          CompletionState *cmpl_state)
 {
-  static char nothing[2] = "";
+  static const char nothing[2] = "";
 
   if (!cmpl_state_okay (cmpl_state))
     {
@@ -1757,7 +2630,7 @@ cmpl_init_state (void)
 
   /* g_get_current_dir() returns a string in the "system" charset */
   sys_getcwd_buf = g_get_current_dir ();
-  utf8_cwd = g_filename_to_utf8 (sys_getcwd_buf);
+  utf8_cwd = g_filename_to_utf8 (sys_getcwd_buf, -1, NULL, NULL, NULL);
   g_free (sys_getcwd_buf);
 
 tryagain:
@@ -1839,6 +2712,7 @@ cmpl_free_state (CompletionState* cmpl_state)
 static void
 free_dir (CompletionDir* dir)
 {
+  g_free (dir->cmpl_text);
   g_free (dir->fullname);
   g_free (dir);
 }
@@ -1848,7 +2722,10 @@ free_dir_sent (CompletionDirSent* sent)
 {
   gint i;
   for (i = 0; i < sent->entry_count; i++)
-    g_free (sent->entries[i].entry_name);
+    {
+      g_free (sent->entries[i].entry_name);
+      g_free (sent->entries[i].sort_key);
+    }
   g_free (sent->entries);
   g_free (sent);
 }
@@ -1892,7 +2769,9 @@ cmpl_completion_matches (gchar           *text_to_complete,
                         gchar          **remaining_text,
                         CompletionState *cmpl_state)
 {
+#ifdef HAVE_PWD_H
   gchar* first_slash;
+#endif
   PossibleCompletion *poss;
 
   prune_memory_usage (cmpl_state);
@@ -1938,7 +2817,7 @@ cmpl_completion_matches (gchar           *text_to_complete,
 
   cmpl_state->completion_dir->cmpl_index = -1;
   cmpl_state->completion_dir->cmpl_parent = NULL;
-  cmpl_state->completion_dir->cmpl_text = *remaining_text;
+  cmpl_state->completion_dir->cmpl_text = g_strdup (*remaining_text);
 
   cmpl_state->active_completion_dir = cmpl_state->completion_dir;
 
@@ -1991,7 +2870,7 @@ open_ref_dir (gchar           *text_to_complete,
   if (text_to_complete[0] == '/' && text_to_complete[1] == '/')
     {
       char root_dir[5];
-      sprintf (root_dir, "//%c", text_to_complete[2]);
+      g_snprintf (root_dir, sizeof (root_dir), "//%c", text_to_complete[2]);
 
       new_dir = open_dir (root_dir, cmpl_state);
 
@@ -2034,22 +2913,21 @@ open_ref_dir (gchar           *text_to_complete,
       p = strrchr (tmp, G_DIR_SEPARATOR);
       if (p)
        {
-         if (p == tmp)
+         if (p + 1 == g_path_skip_root (tmp))
            p++;
       
          *p = '\0';
-
          new_dir = open_dir (tmp, cmpl_state);
 
          if (new_dir)
            *remaining_text = text_to_complete + 
-             ((p == tmp + 1) ? (p - tmp) : (p + 1 - tmp));
+             ((p == g_path_skip_root (tmp)) ? (p - tmp) : (p + 1 - tmp));
        }
       else
        {
          /* If no possible candidates, use the cwd */
          gchar *sys_curdir = g_get_current_dir ();
-         gchar *utf8_curdir = g_filename_to_utf8 (sys_curdir);
+         gchar *utf8_curdir = g_filename_to_utf8 (sys_curdir, -1, NULL, NULL, NULL);
 
          g_free (sys_curdir);
 
@@ -2083,7 +2961,7 @@ open_ref_dir (gchar           *text_to_complete,
 
 /* open a directory by user name */
 static CompletionDir*
-open_user_dir (gchar           *text_to_complete,
+open_user_dir (const gchar     *text_to_complete,
               CompletionState *cmpl_state)
 {
   CompletionDir *result;
@@ -2102,10 +2980,8 @@ open_user_dir (gchar           *text_to_complete,
   if (!cmp_len)
     {
       /* ~/ */
-      gchar *homedir = g_get_home_dir ();
-      gchar *utf8_homedir = g_filename_to_utf8 (homedir);
-
-      g_free (homedir);
+      const gchar *homedir = g_get_home_dir ();
+      gchar *utf8_homedir = g_filename_to_utf8 (homedir, -1, NULL, NULL, NULL);
 
       if (utf8_homedir)
        result = open_dir (utf8_homedir, cmpl_state);
@@ -2130,7 +3006,7 @@ open_user_dir (gchar           *text_to_complete,
          cmpl_errno = errno;
          return NULL;
        }
-      utf8_dir = g_filename_to_utf8 (pwd->pw_dir);
+      utf8_dir = g_filename_to_utf8 (pwd->pw_dir, -1, NULL, NULL, NULL);
       result = open_dir (utf8_dir, cmpl_state);
       g_free (utf8_dir);
     }
@@ -2170,84 +3046,114 @@ open_new_dir (gchar       *dir_name,
              gboolean     stat_subdirs)
 {
   CompletionDirSent *sent;
-  DIR *directory;
-  struct dirent *dirent_ptr;
+  GDir *directory;
+  const char *dirent;
+  GError *error = NULL;
   gint entry_count = 0;
+  gint n_entries = 0;
   gint i;
   struct stat ent_sbuf;
   GString *path;
   gchar *sys_dir_name;
 
   sent = g_new (CompletionDirSent, 1);
+#ifndef G_PLATFORM_WIN32
   sent->mtime = sbuf->st_mtime;
   sent->inode = sbuf->st_ino;
   sent->device = sbuf->st_dev;
-
+#endif
   path = g_string_sized_new (2*MAXPATHLEN + 10);
 
-  sys_dir_name = g_filename_from_utf8 (dir_name);
-  directory = opendir (sys_dir_name);
-
+  sys_dir_name = g_filename_from_utf8 (dir_name, -1, NULL, NULL, NULL);
+  if (!sys_dir_name)
+    {
+      cmpl_errno = CMPL_ERRNO_DID_NOT_CONVERT;
+      return NULL;
+    }
+  
+  directory = g_dir_open (sys_dir_name, 0, &error);
   if (!directory)
     {
-      cmpl_errno = errno;
+      cmpl_errno = error->code; /* ??? */
       g_free (sys_dir_name);
       return NULL;
     }
 
-  while ((dirent_ptr = readdir (directory)) != NULL)
+  while ((dirent = g_dir_read_name (directory)) != NULL)
     entry_count++;
+  entry_count += 2;            /* For ".",".." */
 
   sent->entries = g_new (CompletionDirEntry, entry_count);
   sent->entry_count = entry_count;
 
-  rewinddir (directory);
+  g_dir_rewind (directory);
 
   for (i = 0; i < entry_count; i += 1)
     {
-      dirent_ptr = readdir (directory);
+      GError *error = NULL;
 
-      if (!dirent_ptr)
+      if (i == 0)
+       dirent = ".";
+      else if (i == 1)
+       dirent = "..";
+      else
        {
-         cmpl_errno = errno;
-         closedir (directory);
-         g_free (sys_dir_name);
-         return NULL;
+         dirent = g_dir_read_name (directory);
+         if (!dirent)          /* Directory changed */
+           break;
        }
 
-      sent->entries[i].entry_name = g_filename_to_utf8 (dirent_ptr->d_name);
-
+      sent->entries[n_entries].entry_name = g_filename_to_utf8 (dirent, -1, NULL, NULL, &error);
+      if (sent->entries[n_entries].entry_name == NULL
+         || !g_utf8_validate (sent->entries[n_entries].entry_name, -1, NULL))
+       {
+         gchar *escaped_str = g_strescape (dirent, NULL);
+         g_message (_("The filename \"%s\" couldn't be converted to UTF-8 "
+                      "(try setting the environment variable G_BROKEN_FILENAMES): %s"),
+                    escaped_str,
+                    error->message ? error->message : _("Invalid UTF-8"));
+         g_free (escaped_str);
+         g_clear_error (&error);
+         continue;
+       }
+      g_clear_error (&error);
+      
+      sent->entries[n_entries].sort_key = g_utf8_collate_key (sent->entries[n_entries].entry_name, -1);
+      
       g_string_assign (path, sys_dir_name);
       if (path->str[path->len-1] != G_DIR_SEPARATOR)
        {
          g_string_append_c (path, G_DIR_SEPARATOR);
        }
-      g_string_append (path, dirent_ptr->d_name);
+      g_string_append (path, dirent);
 
       if (stat_subdirs)
        {
          /* Here we know path->str is a "system charset" string */
          if (stat (path->str, &ent_sbuf) >= 0 && S_ISDIR (ent_sbuf.st_mode))
-           sent->entries[i].is_dir = TRUE;
+           sent->entries[n_entries].is_dir = TRUE;
          else
            /* stat may fail, and we don't mind, since it could be a
             * dangling symlink. */
-           sent->entries[i].is_dir = FALSE;
+           sent->entries[n_entries].is_dir = FALSE;
        }
       else
-       sent->entries[i].is_dir = 1;
-    }
+       sent->entries[n_entries].is_dir = 1;
 
+      n_entries++;
+    }
+  sent->entry_count = n_entries;
+  
   g_free (sys_dir_name);
   g_string_free (path, TRUE);
   qsort (sent->entries, sent->entry_count, sizeof (CompletionDirEntry), compare_cmpl_dir);
 
-  closedir (directory);
+  g_dir_close (directory);
 
   return sent;
 }
 
-#if !defined(G_OS_WIN32) && !defined(G_WITH_CYGWIN)
+#ifndef G_PLATFORM_WIN32
 
 static gboolean
 check_dir (gchar       *dir_name,
@@ -2283,7 +3189,13 @@ check_dir (gchar       *dir_name,
        }
     }
 
-  sys_dir_name = g_filename_from_utf8 (dir_name);
+  sys_dir_name = g_filename_from_utf8 (dir_name, -1, NULL, NULL, NULL);
+  if (!sys_dir_name)
+    {
+      cmpl_errno = CMPL_ERRNO_DID_NOT_CONVERT;
+      return FALSE;
+    }
+  
   if (stat (sys_dir_name, result) < 0)
     {
       g_free (sys_dir_name);
@@ -2314,12 +3226,14 @@ static CompletionDir*
 open_dir (gchar           *dir_name,
          CompletionState *cmpl_state)
 {
+#ifndef G_PLATFORM_WIN32
   struct stat sbuf;
   gboolean stat_subdirs;
-  CompletionDirSent *sent;
   GList* cdsl;
+#endif
+  CompletionDirSent *sent;
 
-#if !defined(G_OS_WIN32) && !defined(G_WITH_CYGWIN)
+#ifndef G_PLATFORM_WIN32
   if (!check_dir (dir_name, &sbuf, &stat_subdirs))
     return NULL;
 
@@ -2336,11 +3250,11 @@ open_dir (gchar           *dir_name,
 
       cdsl = cdsl->next;
     }
-#else
-  stat_subdirs = TRUE;
-#endif
 
   sent = open_new_dir (dir_name, &sbuf, stat_subdirs);
+#else
+  sent = open_new_dir (dir_name, NULL, TRUE);
+#endif
 
   if (sent)
     {
@@ -2368,6 +3282,7 @@ attach_dir (CompletionDirSent *sent,
   new_dir->sent = sent;
   new_dir->fullname = g_strdup (dir_name);
   new_dir->fullname_len = strlen (dir_name);
+  new_dir->cmpl_text = NULL;
 
   return new_dir;
 }
@@ -2416,7 +3331,13 @@ correct_dir_fullname (CompletionDir* cmpl_dir)
          return TRUE;
        }
 
-      sys_filename = g_filename_from_utf8 (cmpl_dir->fullname);
+      sys_filename = g_filename_from_utf8 (cmpl_dir->fullname, -1, NULL, NULL, NULL);
+      if (!sys_filename)
+       {
+         cmpl_errno = CMPL_ERRNO_DID_NOT_CONVERT;
+         return FALSE;
+       }
+      
       if (stat (sys_filename, &sbuf) < 0)
        {
          g_free (sys_filename);
@@ -2444,7 +3365,13 @@ correct_dir_fullname (CompletionDir* cmpl_dir)
          return TRUE;
        }
 
-      sys_filename = g_filename_from_utf8 (cmpl_dir->fullname);
+      sys_filename = g_filename_from_utf8 (cmpl_dir->fullname, -1, NULL, NULL, NULL);
+      if (!sys_filename)
+       {
+         cmpl_errno = CMPL_ERRNO_DID_NOT_CONVERT;
+         return FALSE;
+       }
+      
       if (stat (sys_filename, &sbuf) < 0)
        {
          g_free (sys_filename);
@@ -2471,7 +3398,9 @@ correct_parent (CompletionDir *cmpl_dir,
   struct stat parbuf;
   gchar *last_slash;
   gchar *first_slash;
+#ifndef G_PLATFORM_WIN32
   gchar *new_name;
+#endif
   gchar *sys_filename;
   gchar c = 0;
 
@@ -2492,7 +3421,15 @@ correct_parent (CompletionDir *cmpl_dir,
       last_slash[1] = 0;
     }
 
-  sys_filename = g_filename_from_utf8 (cmpl_dir->fullname);
+  sys_filename = g_filename_from_utf8 (cmpl_dir->fullname, -1, NULL, NULL, NULL);
+  if (!sys_filename)
+    {
+      cmpl_errno = CMPL_ERRNO_DID_NOT_CONVERT;
+      if (!c)
+       last_slash[0] = G_DIR_SEPARATOR;
+      return FALSE;
+    }
+  
   if (stat (sys_filename, &parbuf) < 0)
     {
       g_free (sys_filename);
@@ -2503,7 +3440,7 @@ correct_parent (CompletionDir *cmpl_dir,
     }
   g_free (sys_filename);
 
-#ifndef G_OS_WIN32             /* No inode numbers on Win32 */
+#ifndef G_PLATFORM_WIN32       /* No inode numbers on Win32 */
   if (parbuf.st_ino == sbuf->st_ino && parbuf.st_dev == sbuf->st_dev)
     /* it wasn't a link */
     return TRUE;
@@ -2528,7 +3465,7 @@ correct_parent (CompletionDir *cmpl_dir,
   return TRUE;
 }
 
-#ifndef G_OS_WIN32
+#ifndef G_PLATFORM_WIN32
 
 static gchar*
 find_parent_dir_fullname (gchar* dirname)
@@ -2539,18 +3476,26 @@ find_parent_dir_fullname (gchar* dirname)
   gchar *sys_dirname;
 
   sys_orig_dir = g_get_current_dir ();
-  sys_dirname = g_filename_from_utf8 (dirname);
+  sys_dirname = g_filename_from_utf8 (dirname, -1, NULL, NULL, NULL);
+  if (!sys_dirname)
+    {
+      g_free (sys_orig_dir);
+      cmpl_errno = CMPL_ERRNO_DID_NOT_CONVERT;
+      return NULL;
+    }
+  
   if (chdir (sys_dirname) != 0 || chdir ("..") != 0)
     {
+      cmpl_errno = errno;
+      chdir (sys_orig_dir);
       g_free (sys_dirname);
       g_free (sys_orig_dir);
-      cmpl_errno = errno;
       return NULL;
     }
   g_free (sys_dirname);
 
   sys_cwd = g_get_current_dir ();
-  result = g_filename_to_utf8 (sys_cwd);
+  result = g_filename_to_utf8 (sys_cwd, -1, NULL, NULL, NULL);
   g_free (sys_cwd);
 
   if (chdir (sys_orig_dir) != 0)
@@ -2632,7 +3577,12 @@ attempt_homedir_completion (gchar           *text_to_complete,
 
 #endif
 
-#if defined(G_OS_WIN32) || defined(G_WITH_CYGWIN)
+#ifdef G_PLATFORM_WIN32
+/* FIXME: determine whether we should casefold all Unicode letters
+ * here, too (and in in first_diff_index() walk through the strings with
+ * g_utf8_next_char()), or if this folding isn't actually needed at
+ * all.
+ */
 #define FOLD(c) (tolower(c))
 #else
 #define FOLD(c) (c)
@@ -2716,8 +3666,7 @@ find_completion_dir (gchar          *text_to_complete,
       for (i = 0; i < dir->sent->entry_count; i += 1)
        {
          if (dir->sent->entries[i].is_dir &&
-            fnmatch (pat_buf, dir->sent->entries[i].entry_name,
-                     FNMATCH_FLAGS)!= FNM_NOMATCH)
+             _gtk_fnmatch (pat_buf, dir->sent->entries[i].entry_name))
            {
              if (found)
                {
@@ -2744,7 +3693,7 @@ find_completion_dir (gchar          *text_to_complete,
        {
          g_free (pat_buf);
          return NULL;
-       }
+}
       
       next->cmpl_parent = dir;
       
@@ -2778,10 +3727,10 @@ update_cmpl (PossibleCompletion *poss,
 
   if (cmpl_state->updated_text_alloc < cmpl_len + 1)
     {
+      cmpl_state->updated_text_alloc = 2*cmpl_len;
       cmpl_state->updated_text =
        (gchar*)g_realloc (cmpl_state->updated_text,
                           cmpl_state->updated_text_alloc);
-      cmpl_state->updated_text_alloc = 2*cmpl_len;
     }
 
   if (cmpl_state->updated_text_len < 0)
@@ -2867,8 +3816,7 @@ attempt_file_completion (CompletionState *cmpl_state)
     {
       if (dir->sent->entries[dir->cmpl_index].is_dir)
        {
-         if (fnmatch (pat_buf, dir->sent->entries[dir->cmpl_index].entry_name,
-                      FNMATCH_FLAGS) != FNM_NOMATCH)
+         if (_gtk_fnmatch (pat_buf, dir->sent->entries[dir->cmpl_index].entry_name))
            {
              CompletionDir* new_dir;
 
@@ -2884,7 +3832,7 @@ attempt_file_completion (CompletionState *cmpl_state)
              new_dir->cmpl_parent = dir;
 
              new_dir->cmpl_index = -1;
-             new_dir->cmpl_text = first_slash + 1;
+             new_dir->cmpl_text = g_strdup (first_slash + 1);
 
              cmpl_state->active_completion_dir = new_dir;
 
@@ -2916,8 +3864,7 @@ attempt_file_completion (CompletionState *cmpl_state)
       append_completion_text (dir->sent->entries[dir->cmpl_index].entry_name, cmpl_state);
 
       cmpl_state->the_completion.is_a_completion =
-       fnmatch (pat_buf, dir->sent->entries[dir->cmpl_index].entry_name,
-                FNMATCH_FLAGS) != FNM_NOMATCH;
+       _gtk_fnmatch (pat_buf, dir->sent->entries[dir->cmpl_index].entry_name);
 
       cmpl_state->the_completion.is_directory = dir->sent->entries[dir->cmpl_index].is_dir;
       if (dir->sent->entries[dir->cmpl_index].is_dir)
@@ -2944,10 +3891,10 @@ get_pwdb (CompletionState* cmpl_state)
 
   while ((pwd_ptr = getpwent ()) != NULL)
     {
-      utf8 = g_filename_to_utf8 (pwd_ptr->pw_name);
+      utf8 = g_filename_to_utf8 (pwd_ptr->pw_name, -1, NULL, NULL, NULL);
       len += strlen (utf8);
       g_free (utf8);
-      utf8 = g_filename_to_utf8 (pwd_ptr->pw_dir);
+      utf8 = g_filename_to_utf8 (pwd_ptr->pw_dir, -1, NULL, NULL, NULL);
       len += strlen (utf8);
       g_free (utf8);
       len += 2;
@@ -2971,7 +3918,7 @@ get_pwdb (CompletionState* cmpl_state)
          goto error;
        }
 
-      utf8 = g_filename_to_utf8 (pwd_ptr->pw_name);
+      utf8 = g_filename_to_utf8 (pwd_ptr->pw_name, -1, NULL, NULL, NULL);
       strcpy (buf_ptr, utf8);
       g_free (utf8);
 
@@ -2980,7 +3927,7 @@ get_pwdb (CompletionState* cmpl_state)
       buf_ptr += strlen (buf_ptr);
       buf_ptr += 1;
 
-      utf8 = g_filename_to_utf8 (pwd_ptr->pw_dir);
+      utf8 = g_filename_to_utf8 (pwd_ptr->pw_dir, -1, NULL, NULL, NULL);
       strcpy (buf_ptr, utf8);
       g_free (utf8);
 
@@ -3026,13 +3973,9 @@ static gint
 compare_cmpl_dir (const void *a,
                  const void *b)
 {
-#if !defined(G_OS_WIN32) && !defined(G_WITH_CYGWIN)
-  return strcmp ((((CompletionDirEntry*)a))->entry_name,
-                (((CompletionDirEntry*)b))->entry_name);
-#else
-  return g_strcasecmp ((((CompletionDirEntry*)a))->entry_name,
-                      (((CompletionDirEntry*)b))->entry_name);
-#endif
+  
+  return strcmp (((CompletionDirEntry*)a)->sort_key,
+                (((CompletionDirEntry*)b))->sort_key);
 }
 
 static gint
@@ -3041,11 +3984,13 @@ cmpl_state_okay (CompletionState* cmpl_state)
   return  cmpl_state && cmpl_state->reference_dir;
 }
 
-static gchar*
+static const gchar*
 cmpl_strerror (gint err)
 {
   if (err == CMPL_ERRNO_TOO_LONG)
-    return "Name too long";
+    return _("Name too long");
+  else if (err == CMPL_ERRNO_DID_NOT_CONVERT)
+    return _("Couldn't convert filename");
   else
     return g_strerror (err);
 }